Skip to content

Commit cfe50f7

Browse files
HuangYifacebook-github-bot
authored andcommitted
add c api for HyperClockCache (#11110)
Summary: Pull Request resolved: #11110 Reviewed By: cbi42 Differential Revision: D42660941 Pulled By: ajkr fbshipit-source-id: e977d9b76dfd5d8c62335f961c275f3b810503d7
1 parent 142b18d commit cfe50f7

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

db/c.cc

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// Use of this source code is governed by a BSD-style license that can be
88
// found in the LICENSE file. See the AUTHORS file for names of contributors.
99

10-
1110
#include "rocksdb/c.h"
1211

1312
#include <cstdlib>
@@ -78,6 +77,7 @@ using ROCKSDB_NAMESPACE::EnvOptions;
7877
using ROCKSDB_NAMESPACE::FileLock;
7978
using ROCKSDB_NAMESPACE::FilterPolicy;
8079
using ROCKSDB_NAMESPACE::FlushOptions;
80+
using ROCKSDB_NAMESPACE::HyperClockCacheOptions;
8181
using ROCKSDB_NAMESPACE::InfoLogLevel;
8282
using ROCKSDB_NAMESPACE::IngestExternalFileOptions;
8383
using ROCKSDB_NAMESPACE::Iterator;
@@ -208,6 +208,9 @@ struct rocksdb_logger_t {
208208
struct rocksdb_lru_cache_options_t {
209209
LRUCacheOptions rep;
210210
};
211+
struct rocksdb_hyper_clock_cache_options_t {
212+
HyperClockCacheOptions rep;
213+
};
211214
struct rocksdb_memory_allocator_t {
212215
std::shared_ptr<MemoryAllocator> rep;
213216
};
@@ -4682,6 +4685,53 @@ rocksdb_cache_t* rocksdb_cache_create_lru_opts(
46824685
return c;
46834686
}
46844687

4688+
rocksdb_hyper_clock_cache_options_t* rocksdb_hyper_clock_cache_options_create(
4689+
size_t capacity, size_t estimated_entry_charge) {
4690+
return new rocksdb_hyper_clock_cache_options_t{
4691+
HyperClockCacheOptions(capacity, estimated_entry_charge)};
4692+
}
4693+
4694+
void rocksdb_hyper_clock_cache_options_destroy(
4695+
rocksdb_hyper_clock_cache_options_t* opt) {
4696+
delete opt;
4697+
}
4698+
4699+
void rocksdb_hyper_clock_cache_options_set_capacity(
4700+
rocksdb_hyper_clock_cache_options_t* opts, size_t capacity) {
4701+
opts->rep.capacity = capacity;
4702+
}
4703+
4704+
void rocksdb_hyper_clock_cache_options_set_estimated_entry_charge(
4705+
rocksdb_hyper_clock_cache_options_t* opts, size_t estimated_entry_charge) {
4706+
opts->rep.estimated_entry_charge = estimated_entry_charge;
4707+
}
4708+
4709+
void rocksdb_hyper_clock_cache_options_set_num_shard_bits(
4710+
rocksdb_hyper_clock_cache_options_t* opts, int num_shard_bits) {
4711+
opts->rep.num_shard_bits = num_shard_bits;
4712+
}
4713+
4714+
void rocksdb_hyper_clock_cache_options_set_memory_allocator(
4715+
rocksdb_hyper_clock_cache_options_t* opts,
4716+
rocksdb_memory_allocator_t* memory_allocator) {
4717+
opts->rep.memory_allocator = memory_allocator->rep;
4718+
}
4719+
4720+
rocksdb_cache_t* rocksdb_cache_create_hyper_clock(
4721+
size_t capacity, size_t estimated_entry_charge) {
4722+
HyperClockCacheOptions opts(capacity, estimated_entry_charge);
4723+
rocksdb_cache_t* c = new rocksdb_cache_t;
4724+
c->rep = opts.MakeSharedCache();
4725+
return c;
4726+
}
4727+
4728+
rocksdb_cache_t* rocksdb_cache_create_hyper_clock_opts(
4729+
rocksdb_hyper_clock_cache_options_t* opts) {
4730+
rocksdb_cache_t* c = new rocksdb_cache_t;
4731+
c->rep = opts->rep.MakeSharedCache();
4732+
return c;
4733+
}
4734+
46854735
void rocksdb_cache_destroy(rocksdb_cache_t* cache) { delete cache; }
46864736

46874737
void rocksdb_cache_disown_data(rocksdb_cache_t* cache) {

include/rocksdb/c.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ typedef struct rocksdb_backup_engine_options_t rocksdb_backup_engine_options_t;
7676
typedef struct rocksdb_restore_options_t rocksdb_restore_options_t;
7777
typedef struct rocksdb_memory_allocator_t rocksdb_memory_allocator_t;
7878
typedef struct rocksdb_lru_cache_options_t rocksdb_lru_cache_options_t;
79+
typedef struct rocksdb_hyper_clock_cache_options_t
80+
rocksdb_hyper_clock_cache_options_t;
7981
typedef struct rocksdb_cache_t rocksdb_cache_t;
8082
typedef struct rocksdb_compactionfilter_t rocksdb_compactionfilter_t;
8183
typedef struct rocksdb_compactionfiltercontext_t
@@ -2017,6 +2019,29 @@ rocksdb_cache_get_usage(rocksdb_cache_t* cache);
20172019
extern ROCKSDB_LIBRARY_API size_t
20182020
rocksdb_cache_get_pinned_usage(rocksdb_cache_t* cache);
20192021

2022+
/* HyperClockCache */
2023+
extern ROCKSDB_LIBRARY_API rocksdb_hyper_clock_cache_options_t*
2024+
rocksdb_hyper_clock_cache_options_create(size_t capacity,
2025+
size_t estimated_entry_charge);
2026+
extern ROCKSDB_LIBRARY_API void rocksdb_hyper_clock_cache_options_destroy(
2027+
rocksdb_hyper_clock_cache_options_t*);
2028+
extern ROCKSDB_LIBRARY_API void rocksdb_hyper_clock_cache_options_set_capacity(
2029+
rocksdb_hyper_clock_cache_options_t*, size_t);
2030+
extern ROCKSDB_LIBRARY_API void
2031+
rocksdb_hyper_clock_cache_options_set_estimated_entry_charge(
2032+
rocksdb_hyper_clock_cache_options_t*, size_t);
2033+
extern ROCKSDB_LIBRARY_API void
2034+
rocksdb_hyper_clock_cache_options_set_num_shard_bits(
2035+
rocksdb_hyper_clock_cache_options_t*, int);
2036+
extern ROCKSDB_LIBRARY_API void
2037+
rocksdb_hyper_clock_cache_options_set_memory_allocator(
2038+
rocksdb_hyper_clock_cache_options_t*, rocksdb_memory_allocator_t*);
2039+
2040+
extern ROCKSDB_LIBRARY_API rocksdb_cache_t* rocksdb_cache_create_hyper_clock(
2041+
size_t capacity, size_t estimated_entry_charge);
2042+
extern ROCKSDB_LIBRARY_API rocksdb_cache_t*
2043+
rocksdb_cache_create_hyper_clock_opts(rocksdb_hyper_clock_cache_options_t*);
2044+
20202045
/* DBPath */
20212046

20222047
extern ROCKSDB_LIBRARY_API rocksdb_dbpath_t* rocksdb_dbpath_create(

0 commit comments

Comments
 (0)