From 2dabd8189e1bc70b5e9ad340b925bb1915e062d3 Mon Sep 17 00:00:00 2001 From: Connor Tsui Date: Tue, 3 Sep 2024 20:36:15 -0400 Subject: [PATCH] no default values and clean up some docs --- src/buffer/buffer_pool_manager.cpp | 26 +++++++++++++++++------- src/include/buffer/buffer_pool_manager.h | 21 ++++++------------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/buffer/buffer_pool_manager.cpp b/src/buffer/buffer_pool_manager.cpp index f0c1fc899..ae1f717f4 100644 --- a/src/buffer/buffer_pool_manager.cpp +++ b/src/buffer/buffer_pool_manager.cpp @@ -30,7 +30,10 @@ namespace bustub { */ BufferPoolManager::BufferPoolManager(size_t pool_size, DiskManager *disk_manager, size_t replacer_k, LogManager *log_manager) - : pool_size_(pool_size), disk_scheduler_(std::make_unique(disk_manager)), log_manager_(log_manager) { + : next_page_id_(0), + pool_size_(pool_size), + disk_scheduler_(std::make_unique(disk_manager)), + log_manager_(log_manager) { // TODO(students): remove this line after you have implemented the buffer pool manager throw NotImplementedException( "BufferPoolManager is not implemented yet. If you have finished implementing BPM, please remove the throw " @@ -180,11 +183,25 @@ auto BufferPoolManager::FlushPage(page_id_t page_id) -> bool { return false; } */ void BufferPoolManager::FlushAllPages() {} +/** + * @brief Deallocates a page on disk. The caller should acquire the `BufferPoolManager` latch before calling this + * function. + * + * Note: You should look at the documentation for `DeletePage` before using this method. + * Also note: This is a no-op without a more complex data structure to track deallocated pages. + * + * @param page_id The page ID of the page to deallocate from disk. + */ +void BufferPoolManager::DeallocatePage(page_id_t page_id) {} + /**********************************************************************************************************************/ /**********************************************************************************************************************/ /**********************************************************************************************************************/ -// TODO(2024 tas) Remove this function from the rest of the BusTub. +// Below there be dragons... + +// TODO(2024 tas) Remove these function from the rest of the BusTub. + auto BufferPoolManager::FetchPageRead(page_id_t page_id, AccessType access_type) -> ReadPageGuard { auto guard_opt = ReadPage(page_id, access_type); BUSTUB_ASSERT(guard_opt.has_value(), "TODO(2024 tas) Using deprecated `FetchPageRead`"); @@ -193,7 +210,6 @@ auto BufferPoolManager::FetchPageRead(page_id_t page_id, AccessType access_type) return std::move(guard_opt).value(); } -// TODO(2024 tas) Remove this function from the rest of the BusTub. auto BufferPoolManager::FetchPageWrite(page_id_t page_id, AccessType access_type) -> WritePageGuard { auto guard_opt = WritePage(page_id, access_type); BUSTUB_ASSERT(guard_opt.has_value(), "TODO(2024 tas) Using deprecated `FetchPageWrite`"); @@ -203,8 +219,6 @@ auto BufferPoolManager::FetchPageWrite(page_id_t page_id, AccessType access_type } /** - * TODO(cjtsui): This entire function should probably be removed. - * * @brief Fetch the requested page from the buffer pool. Return nullptr if page_id needs to be fetched from the disk * but all frames are currently in use and not evictable (in another word, pinned). * @@ -224,8 +238,6 @@ auto BufferPoolManager::FetchPage(page_id_t page_id, [[maybe_unused]] AccessType } /** - * TODO(cjtsui): This entire function should probably be removed. - * * @brief Unpin the target page from the buffer pool. If page_id is not in the buffer pool or its pin count is already * 0, return false. * diff --git a/src/include/buffer/buffer_pool_manager.h b/src/include/buffer/buffer_pool_manager.h index ec1d5b7d8..82287f1dc 100644 --- a/src/include/buffer/buffer_pool_manager.h +++ b/src/include/buffer/buffer_pool_manager.h @@ -50,12 +50,12 @@ class BufferPoolManager { auto UnpinPage(page_id_t page_id, bool is_dirty, AccessType access_type = AccessType::Unknown) -> bool; private: + /** @brief The next page ID to be allocated. */ + std::atomic next_page_id_; + /** @brief The number of frames in the buffer pool. */ const size_t pool_size_; - /** @brief The next page ID to be allocated. */ - std::atomic next_page_id_ = 0; - /** * @brief The latch protecting most of the `BufferPoolManager`'s shared data structures. * @@ -96,18 +96,9 @@ class BufferPoolManager { */ LogManager *log_manager_ __attribute__((__unused__)); - /** - * @brief Deallocates a page on disk. The caller should acquire the `BufferPoolManager` latch before calling this - * function. - * - * Note: You should look at the documentation for `DeletePage` before using this method. - * - * @param page_id The page ID of the page to deallocate from disk. - */ - void DeallocatePage(__attribute__((unused)) page_id_t page_id) { - // Note that this is a no-op without a more complex data structure to track deallocated pages. - } + // TODO(cjtsui) this should probably be a method on the disk scheduler. + void DeallocatePage(page_id_t page_id); - /** TODO(student): You may add additional private members and helper functions */ + /** TODO(student): You may add additional private members and helper functions. */ }; } // namespace bustub