Skip to content

Commit 325775a

Browse files
authored
Spring 24: Modifications for P2 (#698)
Update benchmark and make bf possible
1 parent 905ba77 commit 325775a

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

src/include/storage/page/extendible_htable_directory_page.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,6 @@ class ExtendibleHTableDirectoryPage {
198198

199199
static_assert(sizeof(page_id_t) == 4);
200200

201-
static_assert(sizeof(ExtendibleHTableDirectoryPage) == HTABLE_DIRECTORY_PAGE_METADATA_SIZE +
202-
HTABLE_DIRECTORY_ARRAY_SIZE +
203-
sizeof(page_id_t) * HTABLE_DIRECTORY_ARRAY_SIZE);
204-
205201
static_assert(sizeof(ExtendibleHTableDirectoryPage) <= BUSTUB_PAGE_SIZE);
206202

207203
} // namespace bustub

src/include/storage/page/extendible_htable_header_page.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ class ExtendibleHTableHeaderPage {
8383

8484
static_assert(sizeof(page_id_t) == 4);
8585

86-
static_assert(sizeof(ExtendibleHTableHeaderPage) ==
87-
sizeof(page_id_t) * HTABLE_HEADER_ARRAY_SIZE + HTABLE_HEADER_PAGE_METADATA_SIZE);
88-
8986
static_assert(sizeof(ExtendibleHTableHeaderPage) <= BUSTUB_PAGE_SIZE);
9087

9188
} // namespace bustub

tools/htable_bench/htable_bench.cpp

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ auto ClockMs() -> uint64_t {
3232
return static_cast<uint64_t>(tm.tv_sec * 1000) + static_cast<uint64_t>(tm.tv_usec / 1000);
3333
}
3434

35-
static const size_t BUSTUB_READ_THREAD = 4;
36-
static const size_t BUSTUB_WRITE_THREAD = 2;
35+
static const size_t BUSTUB_READ_THREAD = 5;
36+
static const size_t BUSTUB_WRITE_THREAD = 3;
3737
static const size_t LRU_K_SIZE = 4;
38-
static const size_t BUSTUB_BPM_SIZE = 256;
39-
static const size_t TOTAL_KEYS = 100000;
38+
static const size_t BUSTUB_BPM_SIZE = 2048;
39+
static const size_t TOTAL_KEYS = 200000;
4040
static const size_t KEY_MODIFY_RANGE = 2048;
41+
static const size_t HTABLE_HEADER_DEPTH = 7;
42+
static const size_t HTABLE_DIRECTORY_DEPTH = 9;
4143

4244
struct HTableTotalMetrics {
4345
uint64_t write_cnt_{0};
@@ -110,6 +112,9 @@ auto KeyWillVanish(size_t key) -> bool { return key % 7 == 0; }
110112
// These keys will be overwritten to a new value
111113
auto KeyWillChange(size_t key) -> bool { return key % 5 == 0; }
112114

115+
// These keys will not be present
116+
auto KeyWillNeverBeInserted(size_t key) -> bool { return key % 3 == 0; }
117+
113118
// NOLINTNEXTLINE
114119
auto main(int argc, char **argv) -> int {
115120
using bustub::AccessType;
@@ -143,15 +148,18 @@ auto main(int argc, char **argv) -> int {
143148
bustub::GenericComparator<8> comparator(key_schema.get());
144149

145150
bustub::DiskExtendibleHashTable<bustub::GenericKey<8>, bustub::RID, bustub::GenericComparator<8>> index(
146-
"foo_pk", bpm.get(), comparator, bustub::HashFunction<bustub::GenericKey<8>>());
151+
"foo_pk", bpm.get(), comparator, bustub::HashFunction<bustub::GenericKey<8>>(), HTABLE_HEADER_DEPTH,
152+
HTABLE_DIRECTORY_DEPTH);
147153

148154
for (size_t key = 0; key < TOTAL_KEYS; key++) {
149-
bustub::GenericKey<8> index_key;
150-
bustub::RID rid;
151-
uint32_t value = key;
152-
rid.Set(value, value);
153-
index_key.SetFromInteger(key);
154-
index.Insert(index_key, rid, nullptr);
155+
if (!KeyWillNeverBeInserted(key)) {
156+
bustub::GenericKey<8> index_key;
157+
bustub::RID rid;
158+
uint32_t value = key;
159+
rid.Set(value, value);
160+
index_key.SetFromInteger(key);
161+
index.Insert(index_key, rid, nullptr);
162+
}
155163
}
156164

157165
fmt::print(stderr, "[info] benchmark start\n");
@@ -183,12 +191,12 @@ auto main(int argc, char **argv) -> int {
183191
index_key.SetFromInteger(key);
184192
index.GetValue(index_key, &rids);
185193

186-
if (!KeyWillVanish(key) && rids.empty()) {
194+
if (!KeyWillVanish(key) && !KeyWillNeverBeInserted(key) && rids.empty()) {
187195
std::string msg = fmt::format("key not found: {}", key);
188196
throw std::runtime_error(msg);
189197
}
190198

191-
if (!KeyWillVanish(key) && !KeyWillChange(key)) {
199+
if (!KeyWillVanish(key) && !KeyWillNeverBeInserted(key) && !KeyWillChange(key)) {
192200
if (rids.size() != 1) {
193201
std::string msg = fmt::format("key not found: {}", key);
194202
throw std::runtime_error(msg);
@@ -257,7 +265,7 @@ auto main(int argc, char **argv) -> int {
257265
for (auto &thread : threads) {
258266
thread.join();
259267
}
260-
268+
index.VerifyIntegrity();
261269
total_metrics.Report();
262270

263271
return 0;

0 commit comments

Comments
 (0)