Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/storage/src/redis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,18 @@ void Redis::GetRocksDBInfo(std::string &info, const char *prefix) {
string_stream << "#" << prefix << "RocksDB" << "\r\n";

auto write_stream_key_value=[&](const Slice& property, const char *metric) {
uint64_t value;
db_->GetAggregatedIntProperty(property, &value);
uint64_t value = 0;
// Avoids double-counting of shared cache.
if (share_block_cache_ && handles_.size() > 0 &&
(property == rocksdb::DB::Properties::kBlockCacheCapacity ||
property == rocksdb::DB::Properties::kBlockCacheUsage ||
property == rocksdb::DB::Properties::kBlockCachePinnedUsage)) {
std::string sval;
db_->GetProperty(handles_[0], property, &sval);
value = std::strtoull(sval.c_str(), nullptr, 10);
} else {
db_->GetAggregatedIntProperty(property, &value);
}
string_stream << prefix << metric << ':' << value << "\r\n";
};

Expand Down
1 change: 1 addition & 0 deletions src/storage/src/redis.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class Redis {
std::shared_ptr<LockMgr> lock_mgr_;
rocksdb::DB* db_ = nullptr;

bool share_block_cache_ = false;
std::vector<rocksdb::ColumnFamilyHandle*> handles_;
rocksdb::WriteOptions default_write_options_;
rocksdb::ReadOptions default_read_options_;
Expand Down
10 changes: 10 additions & 0 deletions src/storage/src/redis_hashes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Status RedisHashes::Open(const StorageOptions& storage_options, const std::strin
column_families.emplace_back(rocksdb::kDefaultColumnFamilyName, meta_cf_ops);
// Data CF
column_families.emplace_back("data_cf", data_cf_ops);
share_block_cache_ = storage_options.share_block_cache;
return rocksdb::DB::Open(db_ops, db_path, column_families, &handles_, &db_);
}

Expand All @@ -81,6 +82,15 @@ Status RedisHashes::GetProperty(const std::string& property, uint64_t* out) {
std::string value;
db_->GetProperty(handles_[0], property, &value);
*out = std::strtoull(value.c_str(), nullptr, 10);

// Avoids double counting when share_block_cache is enabled.
if (share_block_cache_ &&
(property == "rocksdb.block-cache-usage" ||
property == "rocksdb.block-cache-capacity" ||
property == "rocksdb.block-cache-pinned-usage")) {
return Status::OK();
}

db_->GetProperty(handles_[1], property, &value);
*out += std::strtoull(value.c_str(), nullptr, 10);
return Status::OK();
Expand Down
10 changes: 10 additions & 0 deletions src/storage/src/redis_lists.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Status RedisLists::Open(const StorageOptions& storage_options, const std::string
column_families.emplace_back(rocksdb::kDefaultColumnFamilyName, meta_cf_ops);
// Data CF
column_families.emplace_back("data_cf", data_cf_ops);
share_block_cache_ = storage_options.share_block_cache;
return rocksdb::DB::Open(db_ops, db_path, column_families, &handles_, &db_);
}

Expand All @@ -88,6 +89,15 @@ Status RedisLists::GetProperty(const std::string& property, uint64_t* out) {
std::string value;
db_->GetProperty(handles_[0], property, &value);
*out = std::strtoull(value.c_str(), nullptr, 10);

// Avoids double counting when share_block_cache is enabled.
if (share_block_cache_ &&
(property == "rocksdb.block-cache-usage" ||
property == "rocksdb.block-cache-capacity" ||
property == "rocksdb.block-cache-pinned-usage")) {
return Status::OK();
}

db_->GetProperty(handles_[1], property, &value);
*out += std::strtoull(value.c_str(), nullptr, 10);
return Status::OK();
Expand Down
10 changes: 10 additions & 0 deletions src/storage/src/redis_sets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ rocksdb::Status RedisSets::Open(const StorageOptions& storage_options, const std
column_families.emplace_back(rocksdb::kDefaultColumnFamilyName, meta_cf_ops);
// Member CF
column_families.emplace_back("member_cf", member_cf_ops);
share_block_cache_ = storage_options.share_block_cache;
return rocksdb::DB::Open(db_ops, db_path, column_families, &handles_, &db_);
}

Expand All @@ -88,6 +89,15 @@ rocksdb::Status RedisSets::GetProperty(const std::string& property, uint64_t* ou
std::string value;
db_->GetProperty(handles_[0], property, &value);
*out = std::strtoull(value.c_str(), nullptr, 10);

// Avoids double counting when share_block_cache is enabled.
if (share_block_cache_ &&
(property == "rocksdb.block-cache-usage" ||
property == "rocksdb.block-cache-capacity" ||
property == "rocksdb.block-cache-pinned-usage")) {
return rocksdb::Status::OK();
}

db_->GetProperty(handles_[1], property, &value);
*out += std::strtoull(value.c_str(), nullptr, 10);
return rocksdb::Status::OK();
Expand Down
10 changes: 10 additions & 0 deletions src/storage/src/redis_streams.cc
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ Status RedisStreams::Open(const StorageOptions& storage_options, const std::stri
column_families.emplace_back(rocksdb::kDefaultColumnFamilyName, meta_cf_ops);
// Data CF
column_families.emplace_back("data_cf", data_cf_ops);
share_block_cache_ = storage_options.share_block_cache;
return rocksdb::DB::Open(db_ops, db_path, column_families, &handles_, &db_);
}

Expand All @@ -385,6 +386,15 @@ Status RedisStreams::GetProperty(const std::string& property, uint64_t* out) {
std::string value;
db_->GetProperty(handles_[0], property, &value);
*out = std::strtoull(value.c_str(), nullptr, 10);

// Avoids double counting when share_block_cache is enabled.
if (share_block_cache_ &&
(property == "rocksdb.block-cache-usage" ||
property == "rocksdb.block-cache-capacity" ||
property == "rocksdb.block-cache-pinned-usage")) {
return Status::OK();
}

db_->GetProperty(handles_[1], property, &value);
*out += std::strtoull(value.c_str(), nullptr, 10);
return Status::OK();
Expand Down
11 changes: 11 additions & 0 deletions src/storage/src/redis_zsets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Status RedisZSets::Open(const StorageOptions& storage_options, const std::string
column_families.emplace_back(rocksdb::kDefaultColumnFamilyName, meta_cf_ops);
column_families.emplace_back("data_cf", data_cf_ops);
column_families.emplace_back("score_cf", score_cf_ops);
share_block_cache_ = storage_options.share_block_cache;
return rocksdb::DB::Open(db_ops, db_path, column_families, &handles_, &db_);
}

Expand All @@ -101,6 +102,16 @@ Status RedisZSets::GetProperty(const std::string& property, uint64_t* out) {
std::string value;
db_->GetProperty(handles_[0], property, &value);
*out = std::strtoull(value.c_str(), nullptr, 10);

// If share_block_cache is enabled, block cache related properties are shared among CFs,
// so we only need to get the value from the first CF to avoid double counting.
if (share_block_cache_ &&
(property == "rocksdb.block-cache-usage" ||
property == "rocksdb.block-cache-capacity" ||
property == "rocksdb.block-cache-pinned-usage")) {
return Status::OK();
}

db_->GetProperty(handles_[1], property, &value);
*out += std::strtoull(value.c_str(), nullptr, 10);
db_->GetProperty(handles_[2], property, &value);
Expand Down
27 changes: 27 additions & 0 deletions tests/integration/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,33 @@ var _ = Describe("Server", func() {
Expect(adminCmdList).To(ContainSubstring("ping"))
Expect(adminCmdList).To(ContainSubstring("monitor"))
})
// fix: verify that shared block cache does not cause double counting of block cache metrics
It("should report correct block cache capacity when share-block-cache is yes", func() {
// Verify share-block-cache is enabled
shareBlockCacheConfig := client.ConfigGet(ctx, "share-block-cache")
Expect(shareBlockCacheConfig.Err()).NotTo(HaveOccurred())
shareBlockCacheVal := shareBlockCacheConfig.Val()["share-block-cache"]
if shareBlockCacheVal != "yes" {
return
}

info := client.Info(ctx, "rocksdb")
Expect(info.Err()).NotTo(HaveOccurred())
infoStr := info.Val()

Expect(infoStr).To(ContainSubstring("strings_block_cache_capacity:"))
Expect(infoStr).To(ContainSubstring("hashes_block_cache_capacity:"))
Expect(infoStr).To(ContainSubstring("lists_block_cache_capacity:"))
Expect(infoStr).To(ContainSubstring("sets_block_cache_capacity:"))
Expect(infoStr).To(ContainSubstring("zsets_block_cache_capacity:"))

// Simple string-based verification that values are present
Expect(infoStr).To(MatchRegexp(`strings_block_cache_capacity:\d+`))
Expect(infoStr).To(MatchRegexp(`hashes_block_cache_capacity:\d+`))
Expect(infoStr).To(MatchRegexp(`lists_block_cache_capacity:\d+`))
Expect(infoStr).To(MatchRegexp(`sets_block_cache_capacity:\d+`))
Expect(infoStr).To(MatchRegexp(`zsets_block_cache_capacity:\d+`))
})

// fix add auth command to admin-thread-pool
It("should process auth command in admin thread pool", func() {
Expand Down
Loading