Skip to content

Commit c4c93c6

Browse files
committed
Revert:优化hash
1 parent 3cb4508 commit c4c93c6

5 files changed

Lines changed: 3 additions & 21 deletions

File tree

src/common/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static constexpr int HEADER_PAGE_ID = 0; // the header page id
3737
static constexpr int PAGE_SIZE = 4096; // size of a data page in byte 4KB
3838
static constexpr int BUFFER_POOL_SIZE = 1024 * 256 / 8; // size of buffer pool 256MB
3939
// static constexpr int BUFFER_POOL_SIZE = 1024 * 256 / 4; // size of buffer pool 4GB
40-
static constexpr int BUFFER_POOL_INSTANCE_SIZE = 8; // size of buffer pool instance
40+
static constexpr int BUFFER_POOL_INSTANCE_SIZE = 1; // size of buffer pool instance
4141
static constexpr int LOG_BUFFER_SIZE = (1024 * PAGE_SIZE); // size of a log buffer in byte
4242
static constexpr int BUCKET_SIZE = 50; // size of extendible hash bucket
4343

src/storage/buffer_pool_manager.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ See the Mulan PSL v2 for more details. */
1313
extern DiskManager disk_manager;
1414

1515
size_t BufferPoolManager::get_instance_no(const PageId& page_id) const {
16-
// return hasher_(page_id) % BUFFER_POOL_INSTANCE_SIZE;
17-
//! 八个缓冲区的
18-
return hasher_(page_id) & 0x7;
16+
return std::hash<PageId>{}(page_id) % BUFFER_POOL_INSTANCE_SIZE;
1917
}
2018

2119
/**

src/storage/buffer_pool_manager.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ class BufferPoolManager {
3232
private:
3333
size_t pool_size_; // 缓冲池大小(帧数)
3434
BufferPoolInstance* buffer_pool_instances_[BUFFER_POOL_INSTANCE_SIZE]; // 缓冲池实例数组
35-
36-
struct PageIdHash {
37-
size_t operator()(const PageId &pid) const {
38-
return static_cast<size_t>(pid.fd) * 131 + static_cast<size_t>(pid.page_no);
39-
}
40-
};
41-
PageIdHash hasher_; // 哈希函数,用于计算PageId的哈希值
4235

4336
public:
4437
BufferPoolManager(size_t pool_size) : pool_size_(pool_size) {

src/transaction/transaction_manager.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,7 @@ void TransactionManager::abort(Context* context) {
177177
}
178178

179179
auto TransactionManager::GetVersionInfoShard(const PageId& page_id) -> PageVersionInfoShard& {
180-
// return version_info_shards_[hasher_(page_id) % VERSION_INFO_SHARDS];
181-
//256个分片,使用哈希函数计算页ID的哈希值并取模
182-
return version_info_shards_[hasher_(page_id) & 0xFF];
180+
return version_info_shards_[std::hash<PageId>{}(page_id) % VERSION_INFO_SHARDS];
183181
}
184182

185183
/**

src/transaction/transaction_manager.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ class TransactionManager {
4242
// 保护事务表的读写锁
4343
std::shared_mutex txn_map_mutex_;
4444

45-
struct PageIdHash {
46-
size_t operator()(const PageId &pid) const {
47-
return static_cast<size_t>(pid.fd) * 131 + static_cast<size_t>(pid.page_no);
48-
}
49-
};
50-
PageIdHash hasher_; // 哈希函数,用于计算PageId的哈希值
51-
5245
// std::mutex commit_mutex_; // 用于提交事务时的互斥锁
5346

5447
/**

0 commit comments

Comments
 (0)