@@ -72,7 +72,7 @@ BufferPoolManager::BufferPoolManager(size_t num_frames, DiskManager *disk_manage
7272 next_page_id_ (0 ),
7373 bpm_latch_(std::make_shared<std::mutex>()),
7474 replacer_(std::make_shared<LRUKReplacer>(num_frames, k_dist)),
75- disk_scheduler_(std::make_unique <DiskScheduler>(disk_manager)),
75+ disk_scheduler_(std::make_shared <DiskScheduler>(disk_manager)),
7676 log_manager_(log_manager) {
7777 // Not strictly necessary...
7878 std::scoped_lock latch (*bpm_latch_);
@@ -112,12 +112,6 @@ auto BufferPoolManager::Size() const -> size_t { return num_frames_; }
112112 * You will maintain a thread-safe, monotonically increasing counter in the form of a `std::atomic<page_id_t>`.
113113 * See the documentation on [atomics](https://en.cppreference.com/w/cpp/atomic/atomic) for more information.
114114 *
115- * Also, make sure to read the documentation for `DeletePage`! You can assume that you will never run out of disk
116- * space (via `DiskScheduler::IncreaseDiskSpace`), so this function _cannot_ fail.
117- *
118- * Once you have allocated the new page via the counter, make sure to call `DiskScheduler::IncreaseDiskSpace` so you
119- * have enough space on disk!
120- *
121115 * TODO(P1): Add implementation.
122116 *
123117 * @return The page ID of the newly allocated page.
@@ -136,14 +130,7 @@ auto BufferPoolManager::NewPage() -> page_id_t { UNIMPLEMENTED("TODO(P1): Add im
136130 * function. You will probably want to implement this function _after_ you have implemented `CheckedReadPage` and
137131 * `CheckedWritePage`.
138132 *
139- * Ideally, we would want to ensure that all space on disk is used efficiently. That would mean the space that deleted
140- * pages on disk used to occupy should somehow be made available to new pages allocated by `NewPage`.
141- *
142- * If you would like to attempt this, you are free to do so. However, for this implementation, you are allowed to
143- * assume you will not run out of disk space and simply keep allocating disk space upwards in `NewPage`.
144- *
145- * For (nonexistent) style points, you can still call `DeallocatePage` in case you want to implement something slightly
146- * more space-efficient in the future.
133+ * You should call `DeallocatePage` in the disk scheduler to make the space available for new pages.
147134 *
148135 * TODO(P1): Add implementation.
149136 *
@@ -274,11 +261,14 @@ auto BufferPoolManager::ReadPage(page_id_t page_id, AccessType access_type) -> R
274261}
275262
276263/* *
277- * @brief Flushes a page's data out to disk.
264+ * @brief Flushes a page's data out to disk unsafely .
278265 *
279266 * This function will write out a page's data to disk if it has been modified. If the given page is not in memory, this
280267 * function will return `false`.
281268 *
269+ * You should not take a lock on the page in this function.
270+ * This means that you should carefully consider when to toggle the `is_dirty_` bit.
271+ *
282272 * ### Implementation
283273 *
284274 * You should probably leave implementing this function until after you have completed `CheckedReadPage` and
@@ -289,10 +279,47 @@ auto BufferPoolManager::ReadPage(page_id_t page_id, AccessType access_type) -> R
289279 * @param page_id The page ID of the page to be flushed.
290280 * @return `false` if the page could not be found in the page table, otherwise `true`.
291281 */
282+ auto BufferPoolManager::FlushPageUnsafe (page_id_t page_id) -> bool { UNIMPLEMENTED (" TODO(P1): Add implementation." ); }
283+
284+ /* *
285+ * @brief Flushes a page's data out to disk safely.
286+ *
287+ * This function will write out a page's data to disk if it has been modified. If the given page is not in memory, this
288+ * function will return `false`.
289+ *
290+ * You should take a lock on the page in this function to ensure that a consistent state is flushed to disk.
291+ *
292+ * ### Implementation
293+ *
294+ * You should probably leave implementing this function until after you have completed `CheckedReadPage`,
295+ * `CheckedWritePage`, and `Flush` in the page guards, as it will likely be much easier to understand what to do.
296+ *
297+ * TODO(P1): Add implementation
298+ *
299+ * @param page_id The page ID of the page to be flushed.
300+ * @return `false` if the page could not be found in the page table, otherwise `true`.
301+ */
292302auto BufferPoolManager::FlushPage (page_id_t page_id) -> bool { UNIMPLEMENTED (" TODO(P1): Add implementation." ); }
293303
294304/* *
295- * @brief Flushes all page data that is in memory to disk.
305+ * @brief Flushes all page data that is in memory to disk unsafely.
306+ *
307+ * You should not take locks on the pages in this function.
308+ * This means that you should carefully consider when to toggle the `is_dirty_` bit.
309+ *
310+ * ### Implementation
311+ *
312+ * You should probably leave implementing this function until after you have completed `CheckedReadPage`,
313+ * `CheckedWritePage`, and `FlushPage`, as it will likely be much easier to understand what to do.
314+ *
315+ * TODO(P1): Add implementation
316+ */
317+ void BufferPoolManager::FlushAllPagesUnsafe () { UNIMPLEMENTED (" TODO(P1): Add implementation." ); }
318+
319+ /* *
320+ * @brief Flushes all page data that is in memory to disk safely.
321+ *
322+ * You should take locks on the pages in this function to ensure that a consistent state is flushed to disk.
296323 *
297324 * ### Implementation
298325 *
0 commit comments