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

[DNM] Testing Extendible HT Wrapper #651

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
49 changes: 30 additions & 19 deletions src/container/disk/hash/disk_extendible_hash_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,17 @@
//===----------------------------------------------------------------------===//

#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <mutex> // NOLINT

#include "common/config.h"
#include "common/exception.h"
#include "common/logger.h"
#include "common/macros.h"
#include "common/rid.h"
#include "common/util/hash_util.h"
#include "container/disk/hash/disk_extendible_hash_table.h"
#include "storage/index/hash_comparator.h"
#include "storage/page/extendible_htable_bucket_page.h"
#include "storage/page/extendible_htable_directory_page.h"
#include "storage/page/extendible_htable_header_page.h"
#include "storage/page/page_guard.h"
#include "storage/index/stl_comparator_wrapper.h"
#include "storage/index/stl_equal_wrapper.h"
#include "storage/index/stl_hasher_wrapper.h"

namespace bustub {

Expand All @@ -36,20 +31,26 @@ DiskExtendibleHashTable<K, V, KC>::DiskExtendibleHashTable(const std::string &na
uint32_t header_max_depth, uint32_t directory_max_depth,
uint32_t bucket_max_size)
: bpm_(bpm),
cmp_(cmp),
hash_fn_(std::move(hash_fn)),
header_max_depth_(header_max_depth),
directory_max_depth_(directory_max_depth),
bucket_max_size_(bucket_max_size) {
throw NotImplementedException("DiskExtendibleHashTable is not implemented");
}
bucket_max_size_(bucket_max_size),
hash_fn_(hash_fn),
cmp_(StlComparatorWrapper<K, KC>(cmp)),
eq_(StlEqualWrapper<K, KC>(cmp)),
data_(0, StlHasherWrapper<K>(hash_fn_), eq_) {}

/*****************************************************************************
* SEARCH
*****************************************************************************/
template <typename K, typename V, typename KC>
auto DiskExtendibleHashTable<K, V, KC>::GetValue(const K &key, std::vector<V> *result, Transaction *transaction) const
auto DiskExtendibleHashTable<K, V, KC>::GetValue(const K &key, std::vector<V> *result, Transaction *transaction)
-> bool {
std::scoped_lock<std::mutex> lock(mu_);
if (auto it = data_.find(key); it != data_.end()) {
result->push_back(it->second);
return true;
}
*result = {};
return false;
}

Expand All @@ -59,33 +60,43 @@ auto DiskExtendibleHashTable<K, V, KC>::GetValue(const K &key, std::vector<V> *r

template <typename K, typename V, typename KC>
auto DiskExtendibleHashTable<K, V, KC>::Insert(const K &key, const V &value, Transaction *transaction) -> bool {
return false;
std::scoped_lock<std::mutex> lock(mu_);
if (data_.find(key) != data_.end()) {
return false;
}
data_.emplace(key, value);
return true;
}

template <typename K, typename V, typename KC>
auto DiskExtendibleHashTable<K, V, KC>::InsertToNewDirectory(ExtendibleHTableHeaderPage *header, uint32_t directory_idx,
uint32_t hash, const K &key, const V &value) -> bool {
return false;
UNREACHABLE("Not implemented");
}

template <typename K, typename V, typename KC>
auto DiskExtendibleHashTable<K, V, KC>::InsertToNewBucket(ExtendibleHTableDirectoryPage *directory, uint32_t bucket_idx,
const K &key, const V &value) -> bool {
return false;
UNREACHABLE("Not implemented");
}

template <typename K, typename V, typename KC>
void DiskExtendibleHashTable<K, V, KC>::UpdateDirectoryMapping(ExtendibleHTableDirectoryPage *directory,
uint32_t new_bucket_idx, page_id_t new_bucket_page_id,
uint32_t new_local_depth, uint32_t local_depth_mask) {
throw NotImplementedException("DiskExtendibleHashTable is not implemented");
UNREACHABLE("Not implemented");
}

/*****************************************************************************
* REMOVE
*****************************************************************************/
template <typename K, typename V, typename KC>
auto DiskExtendibleHashTable<K, V, KC>::Remove(const K &key, Transaction *transaction) -> bool {
std::scoped_lock<std::mutex> lock(mu_);
if (auto it = data_.find(key); it != data_.end()) {
data_.erase(it);
return true;
}
return false;
}

Expand Down
15 changes: 12 additions & 3 deletions src/include/container/disk/hash/disk_extendible_hash_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@
#pragma once

#include <deque>
#include <mutex> // NOLINT
#include <queue>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

#include "buffer/buffer_pool_manager.h"
#include "common/config.h"
#include "concurrency/transaction.h"
#include "container/hash/hash_function.h"
#include "storage/index/stl_comparator_wrapper.h"
#include "storage/index/stl_equal_wrapper.h"
#include "storage/index/stl_hasher_wrapper.h"
#include "storage/page/extendible_htable_bucket_page.h"
#include "storage/page/extendible_htable_directory_page.h"
#include "storage/page/extendible_htable_header_page.h"
Expand Down Expand Up @@ -83,7 +88,7 @@ class DiskExtendibleHashTable {
* @param transaction the current transaction
* @return the value(s) associated with the given key
*/
auto GetValue(const K &key, std::vector<V> *result, Transaction *transaction = nullptr) const -> bool;
auto GetValue(const K &key, std::vector<V> *result, Transaction *transaction = nullptr) -> bool;

/**
* Helper function to verify the integrity of the extendible hash table's directory.
Expand Down Expand Up @@ -126,12 +131,16 @@ class DiskExtendibleHashTable {
// member variables
std::string index_name_;
BufferPoolManager *bpm_;
KC cmp_;
HashFunction<K> hash_fn_;
uint32_t header_max_depth_;
uint32_t directory_max_depth_;
uint32_t bucket_max_size_;
page_id_t header_page_id_;

HashFunction<K> hash_fn_;
StlComparatorWrapper<K, KC> cmp_;
StlEqualWrapper<K, KC> eq_;
std::mutex mu_;
std::unordered_map<K, V, StlHasherWrapper<K>, StlEqualWrapper<K, KC>> data_;
};

} // namespace bustub
Loading