From 7c9f23e6dba4ce16a151a882e3a29d6a9623f802 Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Wed, 25 Apr 2018 15:45:18 -0700 Subject: [PATCH] Rate limiter should be allowed to share between different rocksdb instances in C API Summary: Currently, the `rocksdb_options_set_ratelimiter` in `c.cc` will change the input to nil, which make it is not possible to use the shared rate limiter create by `rocksdb_ratelimiter_create` in different rocksdb option. In this pr, I changed it to shared ptr. Closes https://github.com/facebook/rocksdb/pull/3758 Differential Revision: D7749740 Pulled By: ajkr fbshipit-source-id: c6121f8ca75402afdb4b295ce63c2338d253a1b5 --- db/c.cc | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/db/c.cc b/db/c.cc index 1c32ee69cb..bc7239dc15 100644 --- a/db/c.cc +++ b/db/c.cc @@ -143,7 +143,7 @@ struct rocksdb_column_family_handle_t { ColumnFamilyHandle* rep; }; struct rocksdb_envoptions_t { EnvOptions rep; }; struct rocksdb_ingestexternalfileoptions_t { IngestExternalFileOptions rep; }; struct rocksdb_sstfilewriter_t { SstFileWriter* rep; }; -struct rocksdb_ratelimiter_t { RateLimiter* rep; }; +struct rocksdb_ratelimiter_t { shared_ptr rep; }; struct rocksdb_perfcontext_t { PerfContext* rep; }; struct rocksdb_pinnableslice_t { PinnableSlice rep; @@ -2524,8 +2524,9 @@ char *rocksdb_options_statistics_get_string(rocksdb_options_t *opt) { } void rocksdb_options_set_ratelimiter(rocksdb_options_t *opt, rocksdb_ratelimiter_t *limiter) { - opt->rep.rate_limiter.reset(limiter->rep); - limiter->rep = nullptr; + if (limiter) { + opt->rep.rate_limiter = limiter->rep; + } } rocksdb_ratelimiter_t* rocksdb_ratelimiter_create( @@ -2533,15 +2534,13 @@ rocksdb_ratelimiter_t* rocksdb_ratelimiter_create( int64_t refill_period_us, int32_t fairness) { rocksdb_ratelimiter_t* rate_limiter = new rocksdb_ratelimiter_t; - rate_limiter->rep = NewGenericRateLimiter(rate_bytes_per_sec, - refill_period_us, fairness); + rate_limiter->rep.reset( + NewGenericRateLimiter(rate_bytes_per_sec, + refill_period_us, fairness)); return rate_limiter; } void rocksdb_ratelimiter_destroy(rocksdb_ratelimiter_t *limiter) { - if (limiter->rep) { - delete limiter->rep; - } delete limiter; }