Skip to content

Commit

Permalink
no default values and clean up some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
connortsui20 committed Sep 4, 2024
1 parent ca1f509 commit 2dabd81
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
26 changes: 19 additions & 7 deletions src/buffer/buffer_pool_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<DiskScheduler>(disk_manager)), log_manager_(log_manager) {
: next_page_id_(0),
pool_size_(pool_size),
disk_scheduler_(std::make_unique<DiskScheduler>(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 "
Expand Down Expand Up @@ -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`");
Expand All @@ -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`");
Expand All @@ -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).
*
Expand All @@ -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.
*
Expand Down
21 changes: 6 additions & 15 deletions src/include/buffer/buffer_pool_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<page_id_t> 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<page_id_t> next_page_id_ = 0;

/**
* @brief The latch protecting most of the `BufferPoolManager`'s shared data structures.
*
Expand Down Expand Up @@ -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

0 comments on commit 2dabd81

Please sign in to comment.