Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose mode option to Rate Limiter via C API #12259

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,
Copy link
Contributor Author

@zaidoon1 zaidoon1 Jan 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no functional change here, but looking at other enums that are being used by the c api, they explicitly define the enum values so updated here to match that pattern

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.