add c api for HyperClockCache (#11110)

Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/11110

Reviewed By: cbi42

Differential Revision: D42660941

Pulled By: ajkr

fbshipit-source-id: e977d9b76dfd5d8c62335f961c275f3b810503d7
oxigraph-8.1.1
HuangYi 2 years ago committed by Facebook GitHub Bot
parent 142b18d00b
commit cfe50f7e77
  1. 52
      db/c.cc
  2. 25
      include/rocksdb/c.h

@ -7,7 +7,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors. // found in the LICENSE file. See the AUTHORS file for names of contributors.
#include "rocksdb/c.h" #include "rocksdb/c.h"
#include <cstdlib> #include <cstdlib>
@ -78,6 +77,7 @@ using ROCKSDB_NAMESPACE::EnvOptions;
using ROCKSDB_NAMESPACE::FileLock; using ROCKSDB_NAMESPACE::FileLock;
using ROCKSDB_NAMESPACE::FilterPolicy; using ROCKSDB_NAMESPACE::FilterPolicy;
using ROCKSDB_NAMESPACE::FlushOptions; using ROCKSDB_NAMESPACE::FlushOptions;
using ROCKSDB_NAMESPACE::HyperClockCacheOptions;
using ROCKSDB_NAMESPACE::InfoLogLevel; using ROCKSDB_NAMESPACE::InfoLogLevel;
using ROCKSDB_NAMESPACE::IngestExternalFileOptions; using ROCKSDB_NAMESPACE::IngestExternalFileOptions;
using ROCKSDB_NAMESPACE::Iterator; using ROCKSDB_NAMESPACE::Iterator;
@ -208,6 +208,9 @@ struct rocksdb_logger_t {
struct rocksdb_lru_cache_options_t { struct rocksdb_lru_cache_options_t {
LRUCacheOptions rep; LRUCacheOptions rep;
}; };
struct rocksdb_hyper_clock_cache_options_t {
HyperClockCacheOptions rep;
};
struct rocksdb_memory_allocator_t { struct rocksdb_memory_allocator_t {
std::shared_ptr<MemoryAllocator> rep; std::shared_ptr<MemoryAllocator> rep;
}; };
@ -4682,6 +4685,53 @@ rocksdb_cache_t* rocksdb_cache_create_lru_opts(
return c; return c;
} }
rocksdb_hyper_clock_cache_options_t* rocksdb_hyper_clock_cache_options_create(
size_t capacity, size_t estimated_entry_charge) {
return new rocksdb_hyper_clock_cache_options_t{
HyperClockCacheOptions(capacity, estimated_entry_charge)};
}
void rocksdb_hyper_clock_cache_options_destroy(
rocksdb_hyper_clock_cache_options_t* opt) {
delete opt;
}
void rocksdb_hyper_clock_cache_options_set_capacity(
rocksdb_hyper_clock_cache_options_t* opts, size_t capacity) {
opts->rep.capacity = capacity;
}
void rocksdb_hyper_clock_cache_options_set_estimated_entry_charge(
rocksdb_hyper_clock_cache_options_t* opts, size_t estimated_entry_charge) {
opts->rep.estimated_entry_charge = estimated_entry_charge;
}
void rocksdb_hyper_clock_cache_options_set_num_shard_bits(
rocksdb_hyper_clock_cache_options_t* opts, int num_shard_bits) {
opts->rep.num_shard_bits = num_shard_bits;
}
void rocksdb_hyper_clock_cache_options_set_memory_allocator(
rocksdb_hyper_clock_cache_options_t* opts,
rocksdb_memory_allocator_t* memory_allocator) {
opts->rep.memory_allocator = memory_allocator->rep;
}
rocksdb_cache_t* rocksdb_cache_create_hyper_clock(
size_t capacity, size_t estimated_entry_charge) {
HyperClockCacheOptions opts(capacity, estimated_entry_charge);
rocksdb_cache_t* c = new rocksdb_cache_t;
c->rep = opts.MakeSharedCache();
return c;
}
rocksdb_cache_t* rocksdb_cache_create_hyper_clock_opts(
rocksdb_hyper_clock_cache_options_t* opts) {
rocksdb_cache_t* c = new rocksdb_cache_t;
c->rep = opts->rep.MakeSharedCache();
return c;
}
void rocksdb_cache_destroy(rocksdb_cache_t* cache) { delete cache; } void rocksdb_cache_destroy(rocksdb_cache_t* cache) { delete cache; }
void rocksdb_cache_disown_data(rocksdb_cache_t* cache) { void rocksdb_cache_disown_data(rocksdb_cache_t* cache) {

@ -76,6 +76,8 @@ typedef struct rocksdb_backup_engine_options_t rocksdb_backup_engine_options_t;
typedef struct rocksdb_restore_options_t rocksdb_restore_options_t; typedef struct rocksdb_restore_options_t rocksdb_restore_options_t;
typedef struct rocksdb_memory_allocator_t rocksdb_memory_allocator_t; typedef struct rocksdb_memory_allocator_t rocksdb_memory_allocator_t;
typedef struct rocksdb_lru_cache_options_t rocksdb_lru_cache_options_t; typedef struct rocksdb_lru_cache_options_t rocksdb_lru_cache_options_t;
typedef struct rocksdb_hyper_clock_cache_options_t
rocksdb_hyper_clock_cache_options_t;
typedef struct rocksdb_cache_t rocksdb_cache_t; typedef struct rocksdb_cache_t rocksdb_cache_t;
typedef struct rocksdb_compactionfilter_t rocksdb_compactionfilter_t; typedef struct rocksdb_compactionfilter_t rocksdb_compactionfilter_t;
typedef struct rocksdb_compactionfiltercontext_t typedef struct rocksdb_compactionfiltercontext_t
@ -2017,6 +2019,29 @@ rocksdb_cache_get_usage(rocksdb_cache_t* cache);
extern ROCKSDB_LIBRARY_API size_t extern ROCKSDB_LIBRARY_API size_t
rocksdb_cache_get_pinned_usage(rocksdb_cache_t* cache); rocksdb_cache_get_pinned_usage(rocksdb_cache_t* cache);
/* HyperClockCache */
extern ROCKSDB_LIBRARY_API rocksdb_hyper_clock_cache_options_t*
rocksdb_hyper_clock_cache_options_create(size_t capacity,
size_t estimated_entry_charge);
extern ROCKSDB_LIBRARY_API void rocksdb_hyper_clock_cache_options_destroy(
rocksdb_hyper_clock_cache_options_t*);
extern ROCKSDB_LIBRARY_API void rocksdb_hyper_clock_cache_options_set_capacity(
rocksdb_hyper_clock_cache_options_t*, size_t);
extern ROCKSDB_LIBRARY_API void
rocksdb_hyper_clock_cache_options_set_estimated_entry_charge(
rocksdb_hyper_clock_cache_options_t*, size_t);
extern ROCKSDB_LIBRARY_API void
rocksdb_hyper_clock_cache_options_set_num_shard_bits(
rocksdb_hyper_clock_cache_options_t*, int);
extern ROCKSDB_LIBRARY_API void
rocksdb_hyper_clock_cache_options_set_memory_allocator(
rocksdb_hyper_clock_cache_options_t*, rocksdb_memory_allocator_t*);
extern ROCKSDB_LIBRARY_API rocksdb_cache_t* rocksdb_cache_create_hyper_clock(
size_t capacity, size_t estimated_entry_charge);
extern ROCKSDB_LIBRARY_API rocksdb_cache_t*
rocksdb_cache_create_hyper_clock_opts(rocksdb_hyper_clock_cache_options_t*);
/* DBPath */ /* DBPath */
extern ROCKSDB_LIBRARY_API rocksdb_dbpath_t* rocksdb_dbpath_create( extern ROCKSDB_LIBRARY_API rocksdb_dbpath_t* rocksdb_dbpath_create(

Loading…
Cancel
Save