From d78d983376903a39fefeb47d2f3c46283bcc7dae Mon Sep 17 00:00:00 2001 From: prashanthduvvada Date: Thu, 22 Aug 2024 19:43:44 -0400 Subject: [PATCH 1/2] Adding log file name getter in disk manager + other changes --- src/include/storage/disk/disk_manager.h | 3 +++ test/table/tuple_test.cpp | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/include/storage/disk/disk_manager.h b/src/include/storage/disk/disk_manager.h index 34cb8acc0..3e3fa6b46 100644 --- a/src/include/storage/disk/disk_manager.h +++ b/src/include/storage/disk/disk_manager.h @@ -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 diff --git a/test/table/tuple_test.cpp b/test/table/tuple_test.cpp index 12449d215..b80c739fc 100644 --- a/test/table/tuple_test.cpp +++ b/test/table/tuple_test.cpp @@ -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 @@ -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); @@ -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; From e03497f9a48e4ba78f7dff6ff1795bdc86ba2fc7 Mon Sep 17 00:00:00 2001 From: prashanthduvvada Date: Fri, 23 Aug 2024 13:31:37 -0400 Subject: [PATCH 2/2] Adding more required changes --- test/buffer/buffer_pool_manager_test.cpp | 13 ++++++----- .../disk/hash/hash_table_page_test.cpp | 4 ++-- test/container/disk/hash/hash_table_test.cpp | 2 +- test/recovery/recovery_test.cpp.disabled | 22 +++++++++++-------- test/storage/disk_manager_test.cpp | 17 +++++++------- 5 files changed, 32 insertions(+), 26 deletions(-) diff --git a/test/buffer/buffer_pool_manager_test.cpp b/test/buffer/buffer_pool_manager_test.cpp index 3a55ddb29..76f2f3132 100644 --- a/test/buffer/buffer_pool_manager_test.cpp +++ b/test/buffer/buffer_pool_manager_test.cpp @@ -13,6 +13,7 @@ #include "buffer/buffer_pool_manager.h" #include +#include #include #include #include @@ -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; @@ -37,7 +39,7 @@ TEST(BufferPoolManagerTest, DISABLED_BinaryDataTest) { static_assert(upper_bound - lower_bound == 255); std::uniform_int_distribution 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; @@ -90,7 +92,7 @@ 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; @@ -98,11 +100,10 @@ TEST(BufferPoolManagerTest, DISABLED_BinaryDataTest) { // 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; @@ -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; diff --git a/test/container/disk/hash/hash_table_page_test.cpp b/test/container/disk/hash/hash_table_page_test.cpp index 429026ba6..6bd5e2686 100644 --- a/test/container/disk/hash/hash_table_page_test.cpp +++ b/test/container/disk/hash/hash_table_page_test.cpp @@ -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; // } @@ -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; // } diff --git a/test/container/disk/hash/hash_table_test.cpp b/test/container/disk/hash/hash_table_test.cpp index a488d4bf3..9ac3b4cb9 100644 --- a/test/container/disk/hash/hash_table_test.cpp +++ b/test/container/disk/hash/hash_table_test.cpp @@ -113,7 +113,7 @@ // ht.VerifyIntegrity(); // disk_manager->ShutDown(); -// remove("test.bustub"); +// remove(fname); // delete disk_manager; // delete bpm; // } diff --git a/test/recovery/recovery_test.cpp.disabled b/test/recovery/recovery_test.cpp.disabled index 8659a5fde..93376f1c3 100644 --- a/test/recovery/recovery_test.cpp.disabled +++ b/test/recovery/recovery_test.cpp.disabled @@ -10,6 +10,7 @@ // //===----------------------------------------------------------------------===// +#include #include #include @@ -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..."); @@ -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"); @@ -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..."); @@ -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; @@ -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..."); diff --git a/test/storage/disk_manager_test.cpp b/test/storage/disk_manager_test.cpp index 4ae4c825f..1605b27e0 100644 --- a/test/storage/disk_manager_test.cpp +++ b/test/storage/disk_manager_test.cpp @@ -18,18 +18,21 @@ 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); }; }; @@ -37,8 +40,7 @@ class DiskManagerTest : public ::testing::Test { 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 @@ -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