Skip to content

Commit

Permalink
expose mode option to Rate Limiter via C API (#12259)
Browse files Browse the repository at this point in the history
Summary:
addresses #12220 to allow rate limiting compaction but not flushes

Pull Request resolved: #12259

Reviewed By: jaykorean

Differential Revision: D52965342

Pulled By: ajkr

fbshipit-source-id: 38566d9ac75c932c63e10cc53796fab0e46e3b2e
  • Loading branch information
zaidoon authored and facebook-github-bot committed Jan 22, 2024
1 parent 4b684e9 commit e572ae9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
10 changes: 10 additions & 0 deletions db/c.cc
Expand Up @@ -4005,6 +4005,16 @@ rocksdb_ratelimiter_t* rocksdb_ratelimiter_create_auto_tuned(
return rate_limiter;
}

rocksdb_ratelimiter_t* rocksdb_ratelimiter_create_with_mode(
int64_t rate_bytes_per_sec, int64_t refill_period_us, int32_t fairness,
int mode, bool auto_tuned) {
rocksdb_ratelimiter_t* rate_limiter = new rocksdb_ratelimiter_t;
rate_limiter->rep.reset(
NewGenericRateLimiter(rate_bytes_per_sec, refill_period_us, fairness,
static_cast<RateLimiter::Mode>(mode), auto_tuned));
return rate_limiter;
}

void rocksdb_ratelimiter_destroy(rocksdb_ratelimiter_t* limiter) {
delete limiter;
}
Expand Down
5 changes: 5 additions & 0 deletions db/c_test.c
Expand Up @@ -718,6 +718,11 @@ int main(int argc, char** argv) {
rocksdb_options_set_ratelimiter(options, rate_limiter);
rocksdb_ratelimiter_destroy(rate_limiter);

rate_limiter = rocksdb_ratelimiter_create_with_mode(1000 * 1024 * 1024,
100 * 1000, 10, 0, true);
rocksdb_options_set_ratelimiter(options, rate_limiter);
rocksdb_ratelimiter_destroy(rate_limiter);

roptions = rocksdb_readoptions_create();
rocksdb_readoptions_set_verify_checksums(roptions, 1);
rocksdb_readoptions_set_fill_cache(roptions, 1);
Expand Down
4 changes: 4 additions & 0 deletions include/rocksdb/c.h
Expand Up @@ -1684,6 +1684,10 @@ 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 rocksdb_ratelimiter_t*
rocksdb_ratelimiter_create_with_mode(int64_t rate_bytes_per_sec,
int64_t refill_period_us, int32_t fairness,
int mode, bool auto_tuned);
extern ROCKSDB_LIBRARY_API void rocksdb_ratelimiter_destroy(
rocksdb_ratelimiter_t*);

Expand Down
6 changes: 3 additions & 3 deletions include/rocksdb/rate_limiter.h
Expand Up @@ -26,9 +26,9 @@ class RateLimiter {
};

enum class Mode {
kReadsOnly,
kWritesOnly,
kAllIo,
kReadsOnly = 0,
kWritesOnly = 1,
kAllIo = 2,
};

// For API compatibility, default to rate-limiting writes only.
Expand Down
@@ -0,0 +1 @@
Exposed mode option to Rate Limiter via c api.

0 comments on commit e572ae9

Please sign in to comment.