提交 62d54809 编写于 作者: K krad

Add persistent cache to Windows build system

Summary: Add hash table (under persistent cache) to CMake list

Test Plan: Run hash_test in windows and make check in Linux

Reviewers: sdong

Subscribers: andrewkr, dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D59151
上级 84295865
......@@ -322,6 +322,7 @@ set(APPS
tools/dump/rocksdb_dump.cc
tools/dump/rocksdb_undump.cc
util/cache_bench.cc
utilities/persistent_cache/hash_table_bench.cc
)
set(C_TESTS db/c_test.c)
......@@ -424,6 +425,7 @@ set(TESTS
utilities/memory/memory_test.cc
utilities/merge_operators/string_append/stringappend_test.cc
utilities/options/options_util_test.cc
utilities/persistent_cache/hash_table_test.cc
utilities/redis/redis_lists_test.cc
utilities/spatialdb/spatial_db_test.cc
utilities/table_properties_collectors/compact_on_deletion_collector_test.cc
......
......@@ -8,12 +8,14 @@
#ifndef ROCKSDB_LITE
#include <assert.h>
#include <sys/mman.h>
#include <list>
#include <vector>
#ifdef OS_LINUX
#include <sys/mman.h>
#endif
#include "include/rocksdb/env.h"
#include "port/port_posix.h"
#include "util/mutexlock.h"
namespace rocksdb {
......@@ -64,7 +66,9 @@ class HashTable {
public:
explicit HashTable(const size_t capacity = 1024 * 1024,
const float load_factor = 2.0, const uint32_t nlocks = 256)
: nbuckets_(load_factor ? capacity / load_factor : 0), nlocks_(nlocks) {
: nbuckets_(
static_cast<uint32_t>(load_factor ? capacity / load_factor : 0)),
nlocks_(nlocks) {
// pre-conditions
assert(capacity);
assert(load_factor);
......@@ -72,11 +76,15 @@ class HashTable {
assert(nlocks_);
buckets_.reset(new Bucket[nbuckets_]);
#ifdef OS_LINUX
mlock(buckets_.get(), nbuckets_ * sizeof(Bucket));
#endif
// initialize locks
locks_.reset(new port::RWMutex[nlocks_]);
#ifdef OS_LINUX
mlock(locks_.get(), nlocks_ * sizeof(port::RWMutex));
#endif
// post-conditions
assert(buckets_);
......
......@@ -6,9 +6,12 @@
#ifndef ROCKSDB_LITE
#ifndef GFLAGS
#include <cstdio>
int main() { fprintf(stderr, "Please install gflags to run tools\n"); }
#else
#include <gflags/gflags.h>
#include <sys/time.h>
#include <unistd.h>
#endif
#include <atomic>
#include <functional>
......@@ -102,9 +105,10 @@ class HashTableBenchmark {
}
void RunRead() {
Random64 rgen(time(nullptr));
while (!quit_) {
std::string s;
size_t k = random() % max_prepop_key;
size_t k = rgen.Next() % max_prepop_key;
bool status = impl_->Lookup(k, &s);
assert(status);
assert(s == std::string(1000, k % 255));
......
......@@ -75,7 +75,7 @@ class EvictableHashTable : private HashTable<T*, Hash, Equal> {
// Evict one of the least recently used object
//
T* Evict(const std::function<void(T*)>& fn = nullptr) {
const size_t start_idx = random() % hash_table::nlocks_;
const size_t start_idx = rand_.Next() % hash_table::nlocks_;
T* t = nullptr;
// iterate from start_idx .. 0 .. start_idx
......@@ -156,6 +156,7 @@ class EvictableHashTable : private HashTable<T*, Hash, Equal> {
return hash_table::locks_[lock_idx];
}
Random64 rand_{static_cast<uint64_t>(time(nullptr))};
std::unique_ptr<LRUListType[]> lru_lists_;
};
......
......@@ -3,12 +3,14 @@
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
//
#include <stdlib.h>
#include <iostream>
#include <set>
#include <string>
#include "db/db_test_util.h"
#include "util/arena.h"
#include "util/random.h"
#include "util/testharness.h"
#include "utilities/persistent_cache/hash_table.h"
#include "utilities/persistent_cache/hash_table_evictable.h"
......@@ -101,10 +103,11 @@ TEST_F(HashTableTest, TestErase) {
map_.Insert(Node(k, std::string(1000, k % 255)));
}
auto rand = Random64(time(nullptr));
// erase a few keys randomly
std::set<uint64_t> erased;
for (int i = 0; i < 1024; ++i) {
uint64_t k = random() % max_keys;
uint64_t k = rand.Next() % max_keys;
if (erased.find(k) != erased.end()) {
continue;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册