Skip to content

Commit

Permalink
clean up public-facing backend code (#744)
Browse files Browse the repository at this point in the history
* clean up public-facing backend code

* format
  • Loading branch information
connortsui20 committed Sep 17, 2024
1 parent 69f851a commit b95f3f2
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 19 deletions.
11 changes: 7 additions & 4 deletions src/include/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ extern std::atomic<bool> enable_logging;
/** If ENABLE_LOGGING is true, the log should be flushed to disk every LOG_TIMEOUT. */
extern std::chrono::duration<int64_t> 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
Expand Down
4 changes: 2 additions & 2 deletions src/include/storage/disk/disk_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 1 addition & 5 deletions src/include/storage/disk/disk_manager_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
//===----------------------------------------------------------------------===//

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -99,7 +96,6 @@ class DiskManagerUnlimitedMemory : public DiskManager {
while (data_.size() < pages + 1) {
data_.push_back(std::make_shared<ProtectedPage>());
}
assert(data_.size() == pages + 1);

pages_ = pages;
}
Expand Down
2 changes: 1 addition & 1 deletion src/include/storage/page/page_guard.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
//===----------------------------------------------------------------------===//

Expand Down
7 changes: 2 additions & 5 deletions src/storage/disk/disk_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <string>
#include <thread> // NOLINT

#include "common/config.h"
#include "common/exception.h"
#include "common/logger.h"
#include "storage/disk/disk_manager.h"
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/storage/disk/disk_manager_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
//===----------------------------------------------------------------------===//

Expand Down
2 changes: 1 addition & 1 deletion test/storage/page_guard_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
//===----------------------------------------------------------------------===//

Expand Down

0 comments on commit b95f3f2

Please sign in to comment.