mirror of https://github.com/facebook/rocksdb.git
C API: support get usage and pinned_usage for cache
Summary: Closes https://github.com/facebook/rocksdb/pull/1671 Differential Revision: D4327453 Pulled By: yiwu-arbug fbshipit-source-id: bcdbc65
This commit is contained in:
parent
0ab6fc167f
commit
8f5d24ae68
13
db/c.cc
13
db/c.cc
|
@ -2242,6 +2242,11 @@ void rocksdb_readoptions_set_readahead_size(
|
||||||
opt->rep.readahead_size = v;
|
opt->rep.readahead_size = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void rocksdb_readoptions_set_pin_data(rocksdb_readoptions_t* opt,
|
||||||
|
unsigned char v) {
|
||||||
|
opt->rep.pin_data = v;
|
||||||
|
}
|
||||||
|
|
||||||
rocksdb_writeoptions_t* rocksdb_writeoptions_create() {
|
rocksdb_writeoptions_t* rocksdb_writeoptions_create() {
|
||||||
return new rocksdb_writeoptions_t;
|
return new rocksdb_writeoptions_t;
|
||||||
}
|
}
|
||||||
|
@ -2309,6 +2314,14 @@ void rocksdb_cache_set_capacity(rocksdb_cache_t* cache, size_t capacity) {
|
||||||
cache->rep->SetCapacity(capacity);
|
cache->rep->SetCapacity(capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t rocksdb_cache_get_usage(rocksdb_cache_t* cache) {
|
||||||
|
return cache->rep->GetUsage();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t rocksdb_cache_get_pinned_usage(rocksdb_cache_t* cache) {
|
||||||
|
return cache->rep->GetPinnedUsage();
|
||||||
|
}
|
||||||
|
|
||||||
rocksdb_env_t* rocksdb_create_default_env() {
|
rocksdb_env_t* rocksdb_create_default_env() {
|
||||||
rocksdb_env_t* result = new rocksdb_env_t;
|
rocksdb_env_t* result = new rocksdb_env_t;
|
||||||
result->rep = Env::Default();
|
result->rep = Env::Default();
|
||||||
|
|
24
db/c_test.c
24
db/c_test.c
|
@ -340,7 +340,7 @@ int main(int argc, char** argv) {
|
||||||
|
|
||||||
roptions = rocksdb_readoptions_create();
|
roptions = rocksdb_readoptions_create();
|
||||||
rocksdb_readoptions_set_verify_checksums(roptions, 1);
|
rocksdb_readoptions_set_verify_checksums(roptions, 1);
|
||||||
rocksdb_readoptions_set_fill_cache(roptions, 0);
|
rocksdb_readoptions_set_fill_cache(roptions, 1);
|
||||||
|
|
||||||
woptions = rocksdb_writeoptions_create();
|
woptions = rocksdb_writeoptions_create();
|
||||||
rocksdb_writeoptions_set_sync(woptions, 1);
|
rocksdb_writeoptions_set_sync(woptions, 1);
|
||||||
|
@ -437,6 +437,24 @@ int main(int argc, char** argv) {
|
||||||
rocksdb_compact_range_opt(db, coptions, "a", 1, "z", 1);
|
rocksdb_compact_range_opt(db, coptions, "a", 1, "z", 1);
|
||||||
CheckGet(db, roptions, "foo", "hello");
|
CheckGet(db, roptions, "foo", "hello");
|
||||||
|
|
||||||
|
// Simple check cache usage
|
||||||
|
StartPhase("cache_usage");
|
||||||
|
{
|
||||||
|
rocksdb_readoptions_set_pin_data(roptions, 1);
|
||||||
|
rocksdb_iterator_t* iter = rocksdb_create_iterator(db, roptions);
|
||||||
|
rocksdb_iter_seek(iter, "foo", 3);
|
||||||
|
|
||||||
|
size_t usage = rocksdb_cache_get_usage(cache);
|
||||||
|
CheckCondition(usage > 0);
|
||||||
|
|
||||||
|
size_t pin_usage = rocksdb_cache_get_pinned_usage(cache);
|
||||||
|
CheckCondition(pin_usage > 0);
|
||||||
|
|
||||||
|
rocksdb_iter_next(iter);
|
||||||
|
rocksdb_iter_destroy(iter);
|
||||||
|
rocksdb_readoptions_set_pin_data(roptions, 0);
|
||||||
|
}
|
||||||
|
|
||||||
StartPhase("writebatch");
|
StartPhase("writebatch");
|
||||||
{
|
{
|
||||||
rocksdb_writebatch_t* wb = rocksdb_writebatch_create();
|
rocksdb_writebatch_t* wb = rocksdb_writebatch_create();
|
||||||
|
@ -795,9 +813,9 @@ int main(int argc, char** argv) {
|
||||||
{
|
{
|
||||||
rocksdb_close(db);
|
rocksdb_close(db);
|
||||||
rocksdb_destroy_db(options, dbname, &err);
|
rocksdb_destroy_db(options, dbname, &err);
|
||||||
CheckNoError(err)
|
CheckNoError(err);
|
||||||
|
|
||||||
rocksdb_options_t* db_options = rocksdb_options_create();
|
rocksdb_options_t* db_options = rocksdb_options_create();
|
||||||
rocksdb_options_set_create_if_missing(db_options, 1);
|
rocksdb_options_set_create_if_missing(db_options, 1);
|
||||||
db = rocksdb_open(db_options, dbname, &err);
|
db = rocksdb_open(db_options, dbname, &err);
|
||||||
CheckNoError(err)
|
CheckNoError(err)
|
||||||
|
|
|
@ -875,6 +875,8 @@ extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_tailing(
|
||||||
rocksdb_readoptions_t*, unsigned char);
|
rocksdb_readoptions_t*, unsigned char);
|
||||||
extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_readahead_size(
|
extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_readahead_size(
|
||||||
rocksdb_readoptions_t*, size_t);
|
rocksdb_readoptions_t*, size_t);
|
||||||
|
extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_pin_data(
|
||||||
|
rocksdb_readoptions_t*, unsigned char);
|
||||||
|
|
||||||
/* Write options */
|
/* Write options */
|
||||||
|
|
||||||
|
@ -917,6 +919,10 @@ extern ROCKSDB_LIBRARY_API rocksdb_cache_t* rocksdb_cache_create_lru(
|
||||||
extern ROCKSDB_LIBRARY_API void rocksdb_cache_destroy(rocksdb_cache_t* cache);
|
extern ROCKSDB_LIBRARY_API void rocksdb_cache_destroy(rocksdb_cache_t* cache);
|
||||||
extern ROCKSDB_LIBRARY_API void rocksdb_cache_set_capacity(
|
extern ROCKSDB_LIBRARY_API void rocksdb_cache_set_capacity(
|
||||||
rocksdb_cache_t* cache, size_t capacity);
|
rocksdb_cache_t* cache, size_t capacity);
|
||||||
|
extern ROCKSDB_LIBRARY_API size_t
|
||||||
|
rocksdb_cache_get_usage(rocksdb_cache_t* cache);
|
||||||
|
extern ROCKSDB_LIBRARY_API size_t
|
||||||
|
rocksdb_cache_get_pinned_usage(rocksdb_cache_t* cache);
|
||||||
|
|
||||||
/* Env */
|
/* Env */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue