From b95f3f2b49530708c76c5d76e608537cd074d587 Mon Sep 17 00:00:00 2001 From: Connor Tsui <87130162+connortsui20@users.noreply.github.com> Date: Tue, 17 Sep 2024 17:39:05 -0400 Subject: [PATCH] clean up public-facing backend code (#744) * clean up public-facing backend code * format --- src/include/common/config.h | 11 +++++++---- src/include/storage/disk/disk_manager.h | 4 ++-- src/include/storage/disk/disk_manager_memory.h | 6 +----- src/include/storage/page/page_guard.h | 2 +- src/storage/disk/disk_manager.cpp | 7 ++----- src/storage/disk/disk_manager_memory.cpp | 2 +- test/storage/page_guard_test.cpp | 2 +- 7 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/include/common/config.h b/src/include/common/config.h index d81261151..433399ac2 100644 --- a/src/include/common/config.h +++ b/src/include/common/config.h @@ -30,14 +30,17 @@ extern std::atomic enable_logging; /** If ENABLE_LOGGING is true, the log should be flushed to disk every LOG_TIMEOUT. */ extern std::chrono::duration log_timeout; -static constexpr int INVALID_PAGE_ID = -1; // invalid page id -static constexpr int INVALID_TXN_ID = -1; // invalid transaction id -static constexpr int INVALID_LSN = -1; // invalid log sequence number +static constexpr int INVALID_FRAME_ID = -1; // invalid frame id +static constexpr int INVALID_PAGE_ID = -1; // invalid page id +static constexpr int INVALID_TXN_ID = -1; // invalid transaction id +static constexpr int INVALID_LSN = -1; // invalid log sequence number + static constexpr int BUSTUB_PAGE_SIZE = 4096; // size of a data page in byte static constexpr int BUFFER_POOL_SIZE = 10; // size of buffer pool +static constexpr int DEFAULT_DB_IO_SIZE = 16; // starting size of file on disk static constexpr int LOG_BUFFER_SIZE = ((BUFFER_POOL_SIZE + 1) * BUSTUB_PAGE_SIZE); // size of a log buffer in byte static constexpr int BUCKET_SIZE = 50; // size of extendible hash bucket -static constexpr int LRUK_REPLACER_K = 10; // default lookback window for lru-k replacer +static constexpr int LRUK_REPLACER_K = 10; // backward k-distance for lru-k using frame_id_t = int32_t; // frame id type using page_id_t = int32_t; // page id type diff --git a/src/include/storage/disk/disk_manager.h b/src/include/storage/disk/disk_manager.h index d23c66cf1..411f7d45b 100644 --- a/src/include/storage/disk/disk_manager.h +++ b/src/include/storage/disk/disk_manager.h @@ -121,9 +121,9 @@ class DiskManager { std::mutex db_io_latch_; /** @brief The number of pages allocated to the DBMS on disk. */ - size_t pages_; + size_t pages_{0}; /** @brief The capacity of the file used for storage on disk. */ - size_t page_capacity_; + size_t page_capacity_{DEFAULT_DB_IO_SIZE}; }; } // namespace bustub diff --git a/src/include/storage/disk/disk_manager_memory.h b/src/include/storage/disk/disk_manager_memory.h index ff67f4f2e..0583b3ef8 100644 --- a/src/include/storage/disk/disk_manager_memory.h +++ b/src/include/storage/disk/disk_manager_memory.h @@ -6,7 +6,7 @@ // // Identification: src/include/storage/disk/disk_manager_memory.h // -// Copyright (c) 2015-2020, Carnegie Mellon University Database Group +// Copyright (c) 2015-2024, Carnegie Mellon University Database Group // //===----------------------------------------------------------------------===// @@ -34,9 +34,6 @@ namespace bustub { -/** @brief The default size of the database file. */ -static const size_t DEFAULT_DB_IO_SIZE = 16; - /** * DiskManagerMemory replicates the utility of DiskManager on memory. It is primarily used for * data structure performance testing. @@ -99,7 +96,6 @@ class DiskManagerUnlimitedMemory : public DiskManager { while (data_.size() < pages + 1) { data_.push_back(std::make_shared()); } - assert(data_.size() == pages + 1); pages_ = pages; } diff --git a/src/include/storage/page/page_guard.h b/src/include/storage/page/page_guard.h index 02a66c33a..d4fa9c209 100644 --- a/src/include/storage/page/page_guard.h +++ b/src/include/storage/page/page_guard.h @@ -6,7 +6,7 @@ // // Identification: src/include/storage/page/page_guard.h // -// Copyright (c) 2024-2024, Carnegie Mellon University Database Group +// Copyright (c) 2015-2024, Carnegie Mellon University Database Group // //===----------------------------------------------------------------------===// diff --git a/src/storage/disk/disk_manager.cpp b/src/storage/disk/disk_manager.cpp index 0fb3e1cfb..db8570fb5 100644 --- a/src/storage/disk/disk_manager.cpp +++ b/src/storage/disk/disk_manager.cpp @@ -18,6 +18,7 @@ #include #include // NOLINT +#include "common/config.h" #include "common/exception.h" #include "common/logger.h" #include "storage/disk/disk_manager.h" @@ -26,15 +27,11 @@ namespace bustub { static char *buffer_used; -/** @brief The default size of the database file. */ -static const size_t DEFAULT_DB_IO_SIZE = 16; - /** * Constructor: open/create a single database file & log file * @input db_file: database file name */ -DiskManager::DiskManager(const std::filesystem::path &db_file) - : file_name_(db_file), pages_(0), page_capacity_(DEFAULT_DB_IO_SIZE) { +DiskManager::DiskManager(const std::filesystem::path &db_file) : file_name_(db_file) { log_name_ = file_name_.filename().stem().string() + ".log"; log_io_.open(log_name_, std::ios::binary | std::ios::in | std::ios::app | std::ios::out); diff --git a/src/storage/disk/disk_manager_memory.cpp b/src/storage/disk/disk_manager_memory.cpp index 963b6c73e..65fad38e7 100644 --- a/src/storage/disk/disk_manager_memory.cpp +++ b/src/storage/disk/disk_manager_memory.cpp @@ -6,7 +6,7 @@ // // Identification: src/storage/disk/disk_manager_memory.cpp // -// Copyright (c) 2015-2020, Carnegie Mellon University Database Group +// Copyright (c) 2015-2024, Carnegie Mellon University Database Group // //===----------------------------------------------------------------------===// diff --git a/test/storage/page_guard_test.cpp b/test/storage/page_guard_test.cpp index c3621e17b..242bf221a 100644 --- a/test/storage/page_guard_test.cpp +++ b/test/storage/page_guard_test.cpp @@ -6,7 +6,7 @@ // // Identification: test/storage/page_guard_test.cpp // -// Copyright (c) 2015-2019, Carnegie Mellon University Database Group +// Copyright (c) 2015-2024, Carnegie Mellon University Database Group // //===----------------------------------------------------------------------===//