Add auto_tuned option to RateLimiter C API (#12058)

Summary:
#### Problem
While the RocksDB C API does have the RateLimiter API, it does not
expose the auto_tuned option.

#### Summary of Change
This PR exposes auto_tuned RateLimiter option in RocksDB C API.

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

Test Plan: Augment the C API existing test to cover the new API.

Reviewed By: cbi42

Differential Revision: D51201933

Pulled By: ajkr

fbshipit-source-id: 5bc595a9cf9f88f50fee797b729ba96f09ed8266
This commit is contained in:
Yueh-Hsuan Chiang 2023-11-10 09:53:09 -08:00 committed by Facebook GitHub Bot
parent dfaf4dc111
commit 73d223c4e2
4 changed files with 20 additions and 0 deletions

10
db/c.cc
View File

@ -3967,6 +3967,16 @@ rocksdb_ratelimiter_t* rocksdb_ratelimiter_create(int64_t rate_bytes_per_sec,
return rate_limiter; return rate_limiter;
} }
rocksdb_ratelimiter_t* rocksdb_ratelimiter_create_auto_tuned(
int64_t rate_bytes_per_sec, int64_t refill_period_us, int32_t fairness) {
rocksdb_ratelimiter_t* rate_limiter = new rocksdb_ratelimiter_t;
rate_limiter->rep.reset(NewGenericRateLimiter(rate_bytes_per_sec,
refill_period_us, fairness,
RateLimiter::Mode::kWritesOnly,
true)); // auto_tuned
return rate_limiter;
}
void rocksdb_ratelimiter_destroy(rocksdb_ratelimiter_t* limiter) { void rocksdb_ratelimiter_destroy(rocksdb_ratelimiter_t* limiter) {
delete limiter; delete limiter;
} }

View File

@ -713,6 +713,11 @@ int main(int argc, char** argv) {
rocksdb_options_set_ratelimiter(options, rate_limiter); rocksdb_options_set_ratelimiter(options, rate_limiter);
rocksdb_ratelimiter_destroy(rate_limiter); rocksdb_ratelimiter_destroy(rate_limiter);
rate_limiter =
rocksdb_ratelimiter_create_auto_tuned(1000 * 1024 * 1024, 100 * 1000, 10);
rocksdb_options_set_ratelimiter(options, rate_limiter);
rocksdb_ratelimiter_destroy(rate_limiter);
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, 1); rocksdb_readoptions_set_fill_cache(roptions, 1);

View File

@ -1672,6 +1672,10 @@ extern ROCKSDB_LIBRARY_API int rocksdb_options_get_wal_compression(
/* RateLimiter */ /* RateLimiter */
extern ROCKSDB_LIBRARY_API rocksdb_ratelimiter_t* rocksdb_ratelimiter_create( extern ROCKSDB_LIBRARY_API rocksdb_ratelimiter_t* rocksdb_ratelimiter_create(
int64_t rate_bytes_per_sec, int64_t refill_period_us, int32_t fairness); int64_t rate_bytes_per_sec, int64_t refill_period_us, int32_t fairness);
extern ROCKSDB_LIBRARY_API rocksdb_ratelimiter_t*
rocksdb_ratelimiter_create_auto_tuned(int64_t rate_bytes_per_sec,
int64_t refill_period_us,
int32_t fairness);
extern ROCKSDB_LIBRARY_API void rocksdb_ratelimiter_destroy( extern ROCKSDB_LIBRARY_API void rocksdb_ratelimiter_destroy(
rocksdb_ratelimiter_t*); rocksdb_ratelimiter_t*);

View File

@ -0,0 +1 @@
Added rocksdb_ratelimiter_create_auto_tuned API to create an auto-tuned GenericRateLimiter.