Skip to content

Commit 89c7a5f

Browse files
Adding log file name getter in disk manager + other changes (#727)
1 parent 5545dbf commit 89c7a5f

File tree

7 files changed

+41
-30
lines changed

7 files changed

+41
-30
lines changed

src/include/storage/disk/disk_manager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ class DiskManager {
9393
/** Checks if the non-blocking flush future was set. */
9494
inline auto HasFlushLogFuture() -> bool { return flush_log_f_ != nullptr; }
9595

96+
/** @brief returns the log file name */
97+
inline auto GetLogFileName() const -> std::filesystem::path { return log_name_; }
98+
9699
protected:
97100
auto GetFileSize(const std::string &file_name) -> int;
98101
// stream to write log file

test/buffer/buffer_pool_manager_test.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "buffer/buffer_pool_manager.h"
1414

1515
#include <cstdio>
16+
#include <filesystem>
1617
#include <limits>
1718
#include <random>
1819
#include <string>
@@ -21,10 +22,11 @@
2122

2223
namespace bustub {
2324

25+
static std::filesystem::path db_fname("test.bustub");
26+
2427
// NOLINTNEXTLINE
2528
// Check whether pages containing terminal characters can be recovered
2629
TEST(BufferPoolManagerTest, DISABLED_BinaryDataTest) {
27-
const std::filesystem::path db_name("test.bustub");
2830
const size_t buffer_pool_size = 10;
2931
const size_t k = 5;
3032

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

40-
auto *disk_manager = new DiskManager(db_name);
42+
auto *disk_manager = new DiskManager(db_fname);
4143
auto *bpm = new BufferPoolManager(buffer_pool_size, disk_manager, k);
4244

4345
page_id_t page_id_temp;
@@ -90,19 +92,18 @@ TEST(BufferPoolManagerTest, DISABLED_BinaryDataTest) {
9092

9193
// Shutdown the disk manager and remove the temporary file we created.
9294
disk_manager->ShutDown();
93-
remove("test.bustub");
95+
remove(db_fname);
9496

9597
delete bpm;
9698
delete disk_manager;
9799
}
98100

99101
// NOLINTNEXTLINE
100102
TEST(BufferPoolManagerTest, DISABLED_SampleTest) {
101-
const std::filesystem::path db_name("test.bustub");
102103
const size_t buffer_pool_size = 10;
103104
const size_t k = 5;
104105

105-
auto *disk_manager = new DiskManager(db_name);
106+
auto *disk_manager = new DiskManager(db_fname);
106107
auto *bpm = new BufferPoolManager(buffer_pool_size, disk_manager, k);
107108

108109
page_id_t page_id_temp;
@@ -148,7 +149,7 @@ TEST(BufferPoolManagerTest, DISABLED_SampleTest) {
148149

149150
// Shutdown the disk manager and remove the temporary file we created.
150151
disk_manager->ShutDown();
151-
remove("test.bustub");
152+
remove(db_fname);
152153

153154
delete bpm;
154155
delete disk_manager;

test/container/disk/hash/hash_table_page_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
// // unpin the directory page now that we are done
5252
// bpm->UnpinPage(directory_page_id, true);
5353
// disk_manager->ShutDown();
54-
// remove("test.bustub");
54+
// remove(fname);
5555
// delete disk_manager;
5656
// delete bpm;
5757
// }
@@ -110,7 +110,7 @@
110110
// // unpin the directory page now that we are done
111111
// bpm->UnpinPage(bucket_page_id, true);
112112
// disk_manager->ShutDown();
113-
// remove("test.bustub");
113+
// remove(fname);
114114
// delete disk_manager;
115115
// delete bpm;
116116
// }

test/container/disk/hash/hash_table_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
// ht.VerifyIntegrity();
114114

115115
// disk_manager->ShutDown();
116-
// remove("test.bustub");
116+
// remove(fname);
117117
// delete disk_manager;
118118
// delete bpm;
119119
// }

test/recovery/recovery_test.cpp.disabled

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include <filesystem>
1314
#include <string>
1415
#include <vector>
1516

@@ -32,25 +33,28 @@
3233

3334
namespace bustub {
3435

36+
const std::filesystem::path db_fname("test.bustub");
37+
const std::filesystem::path log_fname("test.log");
38+
3539
class RecoveryTest : public ::testing::Test {
3640
protected:
3741
// This function is called before every test.
3842
void SetUp() override {
39-
remove("test.bustub");
40-
remove("test.log");
43+
remove(db_fname);
44+
remove(log_fname);
4145
}
4246

4347
// This function is called after every test.
4448
void TearDown() override {
4549
LOG_INFO("Tearing down the system..");
46-
remove("test.bustub");
47-
remove("test.log");
50+
remove(db_fname);
51+
remove(log_fname);
4852
};
4953
};
5054

5155
// NOLINTNEXTLINE
5256
TEST_F(RecoveryTest, DISABLED_RedoTest) {
53-
auto *bustub_instance = new BusTubInstance("test.bustub");
57+
auto *bustub_instance = new BusTubInstance(db_fname);
5458

5559
ASSERT_FALSE(enable_logging);
5660
LOG_INFO("Skip system recovering...");
@@ -92,7 +96,7 @@ TEST_F(RecoveryTest, DISABLED_RedoTest) {
9296
delete bustub_instance;
9397

9498
LOG_INFO("System restart...");
95-
bustub_instance = new BusTubInstance("test.bustub");
99+
bustub_instance = new BusTubInstance(db_fname);
96100

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

140144
// NOLINTNEXTLINE
141145
TEST_F(RecoveryTest, DISABLED_UndoTest) {
142-
auto *bustub_instance = new BusTubInstance("test.bustub");
146+
auto *bustub_instance = new BusTubInstance(db_fname);
143147

144148
ASSERT_FALSE(enable_logging);
145149
LOG_INFO("Skip system recovering...");
@@ -176,7 +180,7 @@ TEST_F(RecoveryTest, DISABLED_UndoTest) {
176180
delete bustub_instance;
177181

178182
LOG_INFO("System restarted..");
179-
bustub_instance = new BusTubInstance("test.bustub");
183+
bustub_instance = new BusTubInstance(db_fname);
180184

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

219223
// NOLINTNEXTLINE
220224
TEST_F(RecoveryTest, DISABLED_CheckpointTest) {
221-
auto *bustub_instance = new BusTubInstance("test.bustub");
225+
auto *bustub_instance = new BusTubInstance(db_fname);
222226

223227
EXPECT_FALSE(enable_logging);
224228
LOG_INFO("Skip system recovering...");

test/storage/disk_manager_test.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,29 @@
1818

1919
namespace bustub {
2020

21+
static std::filesystem::path db_fname("test.bustub");
22+
static std::filesystem::path log_fname("test.log");
23+
2124
class DiskManagerTest : public ::testing::Test {
2225
protected:
2326
// This function is called before every test.
2427
void SetUp() override {
25-
remove("test.bustub");
26-
remove("test.log");
28+
remove(db_fname);
29+
remove(log_fname);
2730
}
2831

2932
// This function is called after every test.
3033
void TearDown() override {
31-
remove("test.bustub");
32-
remove("test.log");
34+
remove(db_fname);
35+
remove(log_fname);
3336
};
3437
};
3538

3639
// NOLINTNEXTLINE
3740
TEST_F(DiskManagerTest, ReadWritePageTest) {
3841
char buf[BUSTUB_PAGE_SIZE] = {0};
3942
char data[BUSTUB_PAGE_SIZE] = {0};
40-
std::filesystem::path db_file("test.bustub");
41-
auto dm = DiskManager(db_file);
43+
auto dm = DiskManager(db_fname);
4244
std::strncpy(data, "A test string.", sizeof(data));
4345

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

6667
dm.ReadLog(buf, sizeof(buf), 0); // tolerate empty read

test/table/tuple_test.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#include "storage/table/tuple.h"
2424

2525
namespace bustub {
26+
27+
static std::filesystem::path db_fname("test.bustub");
28+
2629
// NOLINTNEXTLINE
2730
TEST(TupleTest, DISABLED_TableHeapTest) {
2831
// test1: parse create sql statement
@@ -37,8 +40,7 @@ TEST(TupleTest, DISABLED_TableHeapTest) {
3740
Tuple tuple = ConstructTuple(&schema);
3841

3942
// create transaction
40-
std::filesystem::path fname("test.bustub");
41-
auto *disk_manager = new DiskManager(fname);
43+
auto *disk_manager = new DiskManager(db_fname);
4244
auto *buffer_pool_manager = new BufferPoolManager(50, disk_manager);
4345
auto *table = new TableHeap(buffer_pool_manager);
4446

@@ -55,8 +57,8 @@ TEST(TupleTest, DISABLED_TableHeapTest) {
5557
}
5658

5759
disk_manager->ShutDown();
58-
remove("test.bustub"); // remove db file
59-
remove("test.log");
60+
remove(db_fname); // remove db file
61+
remove(disk_manager->GetLogFileName());
6062
delete table;
6163
delete buffer_pool_manager;
6264
delete disk_manager;

0 commit comments

Comments
 (0)