Add factory method for creating persistent cache that is accessible from public
Summary: Currently there is no mechanism to create persistent cache from headers. Adding a simple factory method to create a simple persistent cache with default or NVM optimized settings. note: Any idea to test this factory is appreciated. Test Plan: None Reviewers: sdong Subscribers: andrewkr, dhruba, leveldb Differential Revision: https://reviews.facebook.net/D64527
This commit is contained in:
parent
be1f1092c9
commit
e91b4d0cf6
@ -9,7 +9,9 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "rocksdb/env.h"
|
||||||
#include "rocksdb/slice.h"
|
#include "rocksdb/slice.h"
|
||||||
#include "rocksdb/statistics.h"
|
#include "rocksdb/statistics.h"
|
||||||
#include "rocksdb/status.h"
|
#include "rocksdb/status.h"
|
||||||
@ -46,4 +48,10 @@ class PersistentCache {
|
|||||||
virtual bool IsCompressed() = 0;
|
virtual bool IsCompressed() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Factor method to create a new persistent cache
|
||||||
|
Status NewPersistentCache(Env* const env, const std::string& path,
|
||||||
|
const uint64_t size,
|
||||||
|
const std::shared_ptr<Logger>& log,
|
||||||
|
const bool optimized_for_nvm,
|
||||||
|
std::shared_ptr<PersistentCache>* cache);
|
||||||
} // namespace rocksdb
|
} // namespace rocksdb
|
||||||
|
@ -359,6 +359,36 @@ bool BlockCacheTier::Reserve(const size_t size) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Status NewPersistentCache(Env* const env, const std::string& path,
|
||||||
|
const uint64_t size,
|
||||||
|
const std::shared_ptr<Logger>& log,
|
||||||
|
const bool optimized_for_nvm,
|
||||||
|
std::shared_ptr<PersistentCache>* cache) {
|
||||||
|
if (!cache) {
|
||||||
|
return Status::IOError("invalid argument cache");
|
||||||
|
}
|
||||||
|
|
||||||
|
auto opt = PersistentCacheConfig(env, path, size, log);
|
||||||
|
if (optimized_for_nvm) {
|
||||||
|
// the default settings are optimized for SSD
|
||||||
|
// NVM devices are better accessed with 4K direct IO and written with
|
||||||
|
// parallelism
|
||||||
|
opt.enable_direct_writes = true;
|
||||||
|
opt.writer_qdepth = 4;
|
||||||
|
opt.writer_dispatch_size = 4 * 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto pcache = std::make_shared<BlockCacheTier>(opt);
|
||||||
|
Status s = pcache->Open();
|
||||||
|
|
||||||
|
if (!s.ok()) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
*cache = pcache;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace rocksdb
|
} // namespace rocksdb
|
||||||
|
|
||||||
#endif // ifndef ROCKSDB_LITE
|
#endif // ifndef ROCKSDB_LITE
|
||||||
|
@ -49,8 +49,8 @@ class BlockCacheTier : public PersistentCacheTier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual ~BlockCacheTier() {
|
virtual ~BlockCacheTier() {
|
||||||
// By contract, the user should have called stop before destroying the
|
// Close is re-entrant so we can call close even if it is already closed
|
||||||
// object
|
Close();
|
||||||
assert(!insert_th_.joinable());
|
assert(!insert_th_.joinable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,6 +235,19 @@ static void UniqueIdCallback(void* arg) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
TEST_F(PersistentCacheTierTest, FactoryTest) {
|
||||||
|
for (auto nvm_opt : {true, false}) {
|
||||||
|
ASSERT_FALSE(cache_);
|
||||||
|
auto log = std::make_shared<ConsoleLogger>();
|
||||||
|
std::shared_ptr<PersistentCache> cache;
|
||||||
|
ASSERT_OK(NewPersistentCache(Env::Default(), path_,
|
||||||
|
/*size=*/1 * 1024 * 1024 * 1024, log, nvm_opt,
|
||||||
|
&cache));
|
||||||
|
ASSERT_TRUE(cache);
|
||||||
|
cache.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PersistentCacheDBTest::PersistentCacheDBTest() : DBTestBase("/cache_test") {
|
PersistentCacheDBTest::PersistentCacheDBTest() : DBTestBase("/cache_test") {
|
||||||
#ifdef OS_LINUX
|
#ifdef OS_LINUX
|
||||||
rocksdb::SyncPoint::GetInstance()->EnableProcessing();
|
rocksdb::SyncPoint::GetInstance()->EnableProcessing();
|
||||||
@ -403,6 +416,7 @@ TEST_F(PersistentCacheDBTest, TieredCacheTest) {
|
|||||||
RunTest(std::bind(&MakeTieredCache, dbname_));
|
RunTest(std::bind(&MakeTieredCache, dbname_));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace rocksdb
|
} // namespace rocksdb
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
Loading…
Reference in New Issue
Block a user