Skip to content

Commit

Permalink
Adding log file name getter in disk manager + other changes (#727)
Browse files Browse the repository at this point in the history
  • Loading branch information
prashanthduvvada committed Aug 23, 2024
1 parent 5545dbf commit 89c7a5f
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 30 deletions.
3 changes: 3 additions & 0 deletions src/include/storage/disk/disk_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class DiskManager {
/** Checks if the non-blocking flush future was set. */
inline auto HasFlushLogFuture() -> bool { return flush_log_f_ != nullptr; }

/** @brief returns the log file name */
inline auto GetLogFileName() const -> std::filesystem::path { return log_name_; }

protected:
auto GetFileSize(const std::string &file_name) -> int;
// stream to write log file
Expand Down
13 changes: 7 additions & 6 deletions test/buffer/buffer_pool_manager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "buffer/buffer_pool_manager.h"

#include <cstdio>
#include <filesystem>
#include <limits>
#include <random>
#include <string>
Expand All @@ -21,10 +22,11 @@

namespace bustub {

static std::filesystem::path db_fname("test.bustub");

// NOLINTNEXTLINE
// Check whether pages containing terminal characters can be recovered
TEST(BufferPoolManagerTest, DISABLED_BinaryDataTest) {
const std::filesystem::path db_name("test.bustub");
const size_t buffer_pool_size = 10;
const size_t k = 5;

Expand All @@ -37,7 +39,7 @@ TEST(BufferPoolManagerTest, DISABLED_BinaryDataTest) {
static_assert(upper_bound - lower_bound == 255);
std::uniform_int_distribution<int> uniform_dist(lower_bound, upper_bound);

auto *disk_manager = new DiskManager(db_name);
auto *disk_manager = new DiskManager(db_fname);
auto *bpm = new BufferPoolManager(buffer_pool_size, disk_manager, k);

page_id_t page_id_temp;
Expand Down Expand Up @@ -90,19 +92,18 @@ TEST(BufferPoolManagerTest, DISABLED_BinaryDataTest) {

// Shutdown the disk manager and remove the temporary file we created.
disk_manager->ShutDown();
remove("test.bustub");
remove(db_fname);

delete bpm;
delete disk_manager;
}

// NOLINTNEXTLINE
TEST(BufferPoolManagerTest, DISABLED_SampleTest) {
const std::filesystem::path db_name("test.bustub");
const size_t buffer_pool_size = 10;
const size_t k = 5;

auto *disk_manager = new DiskManager(db_name);
auto *disk_manager = new DiskManager(db_fname);
auto *bpm = new BufferPoolManager(buffer_pool_size, disk_manager, k);

page_id_t page_id_temp;
Expand Down Expand Up @@ -148,7 +149,7 @@ TEST(BufferPoolManagerTest, DISABLED_SampleTest) {

// Shutdown the disk manager and remove the temporary file we created.
disk_manager->ShutDown();
remove("test.bustub");
remove(db_fname);

delete bpm;
delete disk_manager;
Expand Down
4 changes: 2 additions & 2 deletions test/container/disk/hash/hash_table_page_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
// // unpin the directory page now that we are done
// bpm->UnpinPage(directory_page_id, true);
// disk_manager->ShutDown();
// remove("test.bustub");
// remove(fname);
// delete disk_manager;
// delete bpm;
// }
Expand Down Expand Up @@ -110,7 +110,7 @@
// // unpin the directory page now that we are done
// bpm->UnpinPage(bucket_page_id, true);
// disk_manager->ShutDown();
// remove("test.bustub");
// remove(fname);
// delete disk_manager;
// delete bpm;
// }
Expand Down
2 changes: 1 addition & 1 deletion test/container/disk/hash/hash_table_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
// ht.VerifyIntegrity();

// disk_manager->ShutDown();
// remove("test.bustub");
// remove(fname);
// delete disk_manager;
// delete bpm;
// }
Expand Down
22 changes: 13 additions & 9 deletions test/recovery/recovery_test.cpp.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//
//===----------------------------------------------------------------------===//

#include <filesystem>
#include <string>
#include <vector>

Expand All @@ -32,25 +33,28 @@

namespace bustub {

const std::filesystem::path db_fname("test.bustub");
const std::filesystem::path log_fname("test.log");

class RecoveryTest : public ::testing::Test {
protected:
// This function is called before every test.
void SetUp() override {
remove("test.bustub");
remove("test.log");
remove(db_fname);
remove(log_fname);
}

// This function is called after every test.
void TearDown() override {
LOG_INFO("Tearing down the system..");
remove("test.bustub");
remove("test.log");
remove(db_fname);
remove(log_fname);
};
};

// NOLINTNEXTLINE
TEST_F(RecoveryTest, DISABLED_RedoTest) {
auto *bustub_instance = new BusTubInstance("test.bustub");
auto *bustub_instance = new BusTubInstance(db_fname);

ASSERT_FALSE(enable_logging);
LOG_INFO("Skip system recovering...");
Expand Down Expand Up @@ -92,7 +96,7 @@ TEST_F(RecoveryTest, DISABLED_RedoTest) {
delete bustub_instance;

LOG_INFO("System restart...");
bustub_instance = new BusTubInstance("test.bustub");
bustub_instance = new BusTubInstance(db_fname);

ASSERT_FALSE(enable_logging);
LOG_INFO("Check if tuple is not in table before recovery");
Expand Down Expand Up @@ -139,7 +143,7 @@ TEST_F(RecoveryTest, DISABLED_RedoTest) {

// NOLINTNEXTLINE
TEST_F(RecoveryTest, DISABLED_UndoTest) {
auto *bustub_instance = new BusTubInstance("test.bustub");
auto *bustub_instance = new BusTubInstance(db_fname);

ASSERT_FALSE(enable_logging);
LOG_INFO("Skip system recovering...");
Expand Down Expand Up @@ -176,7 +180,7 @@ TEST_F(RecoveryTest, DISABLED_UndoTest) {
delete bustub_instance;

LOG_INFO("System restarted..");
bustub_instance = new BusTubInstance("test.bustub");
bustub_instance = new BusTubInstance(db_fname);

LOG_INFO("Check if tuple exists before recovery");
Tuple old_tuple;
Expand Down Expand Up @@ -218,7 +222,7 @@ TEST_F(RecoveryTest, DISABLED_UndoTest) {

// NOLINTNEXTLINE
TEST_F(RecoveryTest, DISABLED_CheckpointTest) {
auto *bustub_instance = new BusTubInstance("test.bustub");
auto *bustub_instance = new BusTubInstance(db_fname);

EXPECT_FALSE(enable_logging);
LOG_INFO("Skip system recovering...");
Expand Down
17 changes: 9 additions & 8 deletions test/storage/disk_manager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,29 @@

namespace bustub {

static std::filesystem::path db_fname("test.bustub");
static std::filesystem::path log_fname("test.log");

class DiskManagerTest : public ::testing::Test {
protected:
// This function is called before every test.
void SetUp() override {
remove("test.bustub");
remove("test.log");
remove(db_fname);
remove(log_fname);
}

// This function is called after every test.
void TearDown() override {
remove("test.bustub");
remove("test.log");
remove(db_fname);
remove(log_fname);
};
};

// NOLINTNEXTLINE
TEST_F(DiskManagerTest, ReadWritePageTest) {
char buf[BUSTUB_PAGE_SIZE] = {0};
char data[BUSTUB_PAGE_SIZE] = {0};
std::filesystem::path db_file("test.bustub");
auto dm = DiskManager(db_file);
auto dm = DiskManager(db_fname);
std::strncpy(data, "A test string.", sizeof(data));

dm.ReadPage(0, buf); // tolerate empty read
Expand All @@ -59,8 +61,7 @@ TEST_F(DiskManagerTest, ReadWritePageTest) {
TEST_F(DiskManagerTest, ReadWriteLogTest) {
char buf[16] = {0};
char data[16] = {0};
std::filesystem::path db_file("test.bustub");
auto dm = DiskManager(db_file);
auto dm = DiskManager(db_fname);
std::strncpy(data, "A test string.", sizeof(data));

dm.ReadLog(buf, sizeof(buf), 0); // tolerate empty read
Expand Down
10 changes: 6 additions & 4 deletions test/table/tuple_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include "storage/table/tuple.h"

namespace bustub {

static std::filesystem::path db_fname("test.bustub");

// NOLINTNEXTLINE
TEST(TupleTest, DISABLED_TableHeapTest) {
// test1: parse create sql statement
Expand All @@ -37,8 +40,7 @@ TEST(TupleTest, DISABLED_TableHeapTest) {
Tuple tuple = ConstructTuple(&schema);

// create transaction
std::filesystem::path fname("test.bustub");
auto *disk_manager = new DiskManager(fname);
auto *disk_manager = new DiskManager(db_fname);
auto *buffer_pool_manager = new BufferPoolManager(50, disk_manager);
auto *table = new TableHeap(buffer_pool_manager);

Expand All @@ -55,8 +57,8 @@ TEST(TupleTest, DISABLED_TableHeapTest) {
}

disk_manager->ShutDown();
remove("test.bustub"); // remove db file
remove("test.log");
remove(db_fname); // remove db file
remove(disk_manager->GetLogFileName());
delete table;
delete buffer_pool_manager;
delete disk_manager;
Expand Down

0 comments on commit 89c7a5f

Please sign in to comment.