Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring 24: Modifications for P2 #698

Merged
merged 1 commit into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/include/storage/page/extendible_htable_directory_page.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,6 @@ class ExtendibleHTableDirectoryPage {

static_assert(sizeof(page_id_t) == 4);

static_assert(sizeof(ExtendibleHTableDirectoryPage) == HTABLE_DIRECTORY_PAGE_METADATA_SIZE +
HTABLE_DIRECTORY_ARRAY_SIZE +
sizeof(page_id_t) * HTABLE_DIRECTORY_ARRAY_SIZE);

static_assert(sizeof(ExtendibleHTableDirectoryPage) <= BUSTUB_PAGE_SIZE);

} // namespace bustub
3 changes: 0 additions & 3 deletions src/include/storage/page/extendible_htable_header_page.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ class ExtendibleHTableHeaderPage {

static_assert(sizeof(page_id_t) == 4);

static_assert(sizeof(ExtendibleHTableHeaderPage) ==
sizeof(page_id_t) * HTABLE_HEADER_ARRAY_SIZE + HTABLE_HEADER_PAGE_METADATA_SIZE);

static_assert(sizeof(ExtendibleHTableHeaderPage) <= BUSTUB_PAGE_SIZE);

} // namespace bustub
36 changes: 22 additions & 14 deletions tools/htable_bench/htable_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ auto ClockMs() -> uint64_t {
return static_cast<uint64_t>(tm.tv_sec * 1000) + static_cast<uint64_t>(tm.tv_usec / 1000);
}

static const size_t BUSTUB_READ_THREAD = 4;
static const size_t BUSTUB_WRITE_THREAD = 2;
static const size_t BUSTUB_READ_THREAD = 5;
static const size_t BUSTUB_WRITE_THREAD = 3;
static const size_t LRU_K_SIZE = 4;
static const size_t BUSTUB_BPM_SIZE = 256;
static const size_t TOTAL_KEYS = 100000;
static const size_t BUSTUB_BPM_SIZE = 2048;
static const size_t TOTAL_KEYS = 200000;
static const size_t KEY_MODIFY_RANGE = 2048;
static const size_t HTABLE_HEADER_DEPTH = 7;
static const size_t HTABLE_DIRECTORY_DEPTH = 9;

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

// These keys will not be present
auto KeyWillNeverBeInserted(size_t key) -> bool { return key % 3 == 0; }

// NOLINTNEXTLINE
auto main(int argc, char **argv) -> int {
using bustub::AccessType;
Expand Down Expand Up @@ -143,15 +148,18 @@ auto main(int argc, char **argv) -> int {
bustub::GenericComparator<8> comparator(key_schema.get());

bustub::DiskExtendibleHashTable<bustub::GenericKey<8>, bustub::RID, bustub::GenericComparator<8>> index(
"foo_pk", bpm.get(), comparator, bustub::HashFunction<bustub::GenericKey<8>>());
"foo_pk", bpm.get(), comparator, bustub::HashFunction<bustub::GenericKey<8>>(), HTABLE_HEADER_DEPTH,
HTABLE_DIRECTORY_DEPTH);

for (size_t key = 0; key < TOTAL_KEYS; key++) {
bustub::GenericKey<8> index_key;
bustub::RID rid;
uint32_t value = key;
rid.Set(value, value);
index_key.SetFromInteger(key);
index.Insert(index_key, rid, nullptr);
if (!KeyWillNeverBeInserted(key)) {
bustub::GenericKey<8> index_key;
bustub::RID rid;
uint32_t value = key;
rid.Set(value, value);
index_key.SetFromInteger(key);
index.Insert(index_key, rid, nullptr);
}
}

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

if (!KeyWillVanish(key) && rids.empty()) {
if (!KeyWillVanish(key) && !KeyWillNeverBeInserted(key) && rids.empty()) {
std::string msg = fmt::format("key not found: {}", key);
throw std::runtime_error(msg);
}

if (!KeyWillVanish(key) && !KeyWillChange(key)) {
if (!KeyWillVanish(key) && !KeyWillNeverBeInserted(key) && !KeyWillChange(key)) {
if (rids.size() != 1) {
std::string msg = fmt::format("key not found: {}", key);
throw std::runtime_error(msg);
Expand Down Expand Up @@ -257,7 +265,7 @@ auto main(int argc, char **argv) -> int {
for (auto &thread : threads) {
thread.join();
}

index.VerifyIntegrity();
total_metrics.Report();

return 0;
Expand Down
Loading