Skip to content

Commit

Permalink
Add support for TiKV IO rate limiter (#383)
Browse files Browse the repository at this point in the history
 

Signed-off-by: Yang Zhang <yang.zhang@pingcap.com>

Co-authored-by: Xinye Tao <xy.tao@outlook.com>
  • Loading branch information
v01dstar and tabokie authored Sep 27, 2024
1 parent 96574bd commit d308a00
Show file tree
Hide file tree
Showing 6 changed files with 497 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ set(SOURCES
env/env.cc
env/env_chroot.cc
env/env_encryption.cc
env/env_inspected.cc
env/file_system.cc
env/file_system_tracer.cc
env/fs_remap.cc
Expand Down
1 change: 1 addition & 0 deletions TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ cpp_library_wrapper(name="rocksdb_lib", srcs=[
"env/env.cc",
"env/env_chroot.cc",
"env/env_encryption.cc",
"env/env_inspected.cc",
"env/env_posix.cc",
"env/file_system.cc",
"env/file_system_tracer.cc",
Expand Down
39 changes: 39 additions & 0 deletions env/env_basic_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "rocksdb/convenience.h"
#include "rocksdb/env.h"
#include "rocksdb/env_encryption.h"
#include "rocksdb/env_inspected.h"
#include "test_util/testharness.h"

namespace ROCKSDB_NAMESPACE {
Expand Down Expand Up @@ -81,6 +82,41 @@ static Env* GetTestFS() {
return fs_env;
}

class DummyFileSystemInspector : public FileSystemInspector {
public:
DummyFileSystemInspector(size_t refill_bytes = 0)
: refill_bytes_(refill_bytes) {}

Status Read(size_t len, size_t* allowed) override {
assert(allowed);
if (refill_bytes_ == 0) {
*allowed = len;
} else {
*allowed = std::min(refill_bytes_, len);
}
return Status::OK();
}

Status Write(size_t len, size_t* allowed) override {
assert(allowed);
if (refill_bytes_ == 0) {
*allowed = len;
} else {
*allowed = std::min(refill_bytes_, len);
}
return Status::OK();
}

private:
size_t refill_bytes_;
};

static Env* GetInspectedEnv() {
static std::unique_ptr<Env> inspected_env(NewFileSystemInspectedEnv(
Env::Default(), std::make_shared<DummyFileSystemInspector>(1)));
return inspected_env.get();
}

} // namespace
class EnvBasicTestWithParam
: public testing::Test,
Expand Down Expand Up @@ -118,6 +154,9 @@ INSTANTIATE_TEST_CASE_P(EncryptedEnv, EnvMoreTestWithParam,
INSTANTIATE_TEST_CASE_P(MemEnv, EnvBasicTestWithParam,
::testing::Values(&GetMemoryEnv));

INSTANTIATE_TEST_CASE_P(InspectedEnv, EnvBasicTestWithParam,
::testing::Values(&GetInspectedEnv));

namespace {

// Returns a vector of 0 or 1 Env*, depending whether an Env is registered for
Expand Down
Loading

0 comments on commit d308a00

Please sign in to comment.