Skip to content

Commit 8c5cb8e

Browse files
committed
fix blockcache
1 parent 8afe87f commit 8c5cb8e

7 files changed

Lines changed: 64 additions & 2 deletions

File tree

src/storage/src/redis.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,18 @@ void Redis::GetRocksDBInfo(std::string &info, const char *prefix) {
115115
string_stream << "#" << prefix << "RocksDB" << "\r\n";
116116

117117
auto write_stream_key_value=[&](const Slice& property, const char *metric) {
118-
uint64_t value;
119-
db_->GetAggregatedIntProperty(property, &value);
118+
uint64_t value = 0;
119+
// Avoids double-counting of shared cache.
120+
if (share_block_cache_ && handles_.size() > 0 &&
121+
(property == rocksdb::DB::Properties::kBlockCacheCapacity ||
122+
property == rocksdb::DB::Properties::kBlockCacheUsage ||
123+
property == rocksdb::DB::Properties::kBlockCachePinnedUsage)) {
124+
std::string sval;
125+
db_->GetProperty(handles_[0], property, &sval);
126+
value = std::strtoull(sval.c_str(), nullptr, 10);
127+
} else {
128+
db_->GetAggregatedIntProperty(property, &value);
129+
}
120130
string_stream << prefix << metric << ':' << value << "\r\n";
121131
};
122132

src/storage/src/redis.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class Redis {
122122
std::shared_ptr<LockMgr> lock_mgr_;
123123
rocksdb::DB* db_ = nullptr;
124124

125+
bool share_block_cache_ = false;
125126
std::vector<rocksdb::ColumnFamilyHandle*> handles_;
126127
rocksdb::WriteOptions default_write_options_;
127128
rocksdb::ReadOptions default_read_options_;

src/storage/src/redis_hashes.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Status RedisHashes::Open(const StorageOptions& storage_options, const std::strin
6464
column_families.emplace_back(rocksdb::kDefaultColumnFamilyName, meta_cf_ops);
6565
// Data CF
6666
column_families.emplace_back("data_cf", data_cf_ops);
67+
share_block_cache_ = storage_options.share_block_cache;
6768
return rocksdb::DB::Open(db_ops, db_path, column_families, &handles_, &db_);
6869
}
6970

@@ -81,6 +82,15 @@ Status RedisHashes::GetProperty(const std::string& property, uint64_t* out) {
8182
std::string value;
8283
db_->GetProperty(handles_[0], property, &value);
8384
*out = std::strtoull(value.c_str(), nullptr, 10);
85+
86+
// Avoids double counting when share_block_cache is enabled.
87+
if (share_block_cache_ &&
88+
(property == "rocksdb.block-cache-usage" ||
89+
property == "rocksdb.block-cache-capacity" ||
90+
property == "rocksdb.block-cache-pinned-usage")) {
91+
return Status::OK();
92+
}
93+
8494
db_->GetProperty(handles_[1], property, &value);
8595
*out += std::strtoull(value.c_str(), nullptr, 10);
8696
return Status::OK();

src/storage/src/redis_lists.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Status RedisLists::Open(const StorageOptions& storage_options, const std::string
7171
column_families.emplace_back(rocksdb::kDefaultColumnFamilyName, meta_cf_ops);
7272
// Data CF
7373
column_families.emplace_back("data_cf", data_cf_ops);
74+
share_block_cache_ = storage_options.share_block_cache;
7475
return rocksdb::DB::Open(db_ops, db_path, column_families, &handles_, &db_);
7576
}
7677

@@ -88,6 +89,15 @@ Status RedisLists::GetProperty(const std::string& property, uint64_t* out) {
8889
std::string value;
8990
db_->GetProperty(handles_[0], property, &value);
9091
*out = std::strtoull(value.c_str(), nullptr, 10);
92+
93+
// Avoids double counting when share_block_cache is enabled.
94+
if (share_block_cache_ &&
95+
(property == "rocksdb.block-cache-usage" ||
96+
property == "rocksdb.block-cache-capacity" ||
97+
property == "rocksdb.block-cache-pinned-usage")) {
98+
return Status::OK();
99+
}
100+
91101
db_->GetProperty(handles_[1], property, &value);
92102
*out += std::strtoull(value.c_str(), nullptr, 10);
93103
return Status::OK();

src/storage/src/redis_sets.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ rocksdb::Status RedisSets::Open(const StorageOptions& storage_options, const std
7171
column_families.emplace_back(rocksdb::kDefaultColumnFamilyName, meta_cf_ops);
7272
// Member CF
7373
column_families.emplace_back("member_cf", member_cf_ops);
74+
share_block_cache_ = storage_options.share_block_cache;
7475
return rocksdb::DB::Open(db_ops, db_path, column_families, &handles_, &db_);
7576
}
7677

@@ -88,6 +89,15 @@ rocksdb::Status RedisSets::GetProperty(const std::string& property, uint64_t* ou
8889
std::string value;
8990
db_->GetProperty(handles_[0], property, &value);
9091
*out = std::strtoull(value.c_str(), nullptr, 10);
92+
93+
// Avoids double counting when share_block_cache is enabled.
94+
if (share_block_cache_ &&
95+
(property == "rocksdb.block-cache-usage" ||
96+
property == "rocksdb.block-cache-capacity" ||
97+
property == "rocksdb.block-cache-pinned-usage")) {
98+
return rocksdb::Status::OK();
99+
}
100+
91101
db_->GetProperty(handles_[1], property, &value);
92102
*out += std::strtoull(value.c_str(), nullptr, 10);
93103
return rocksdb::Status::OK();

src/storage/src/redis_streams.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ Status RedisStreams::Open(const StorageOptions& storage_options, const std::stri
367367
column_families.emplace_back(rocksdb::kDefaultColumnFamilyName, meta_cf_ops);
368368
// Data CF
369369
column_families.emplace_back("data_cf", data_cf_ops);
370+
share_block_cache_ = storage_options.share_block_cache;
370371
return rocksdb::DB::Open(db_ops, db_path, column_families, &handles_, &db_);
371372
}
372373

@@ -385,6 +386,15 @@ Status RedisStreams::GetProperty(const std::string& property, uint64_t* out) {
385386
std::string value;
386387
db_->GetProperty(handles_[0], property, &value);
387388
*out = std::strtoull(value.c_str(), nullptr, 10);
389+
390+
// Avoids double counting when share_block_cache is enabled.
391+
if (share_block_cache_ &&
392+
(property == "rocksdb.block-cache-usage" ||
393+
property == "rocksdb.block-cache-capacity" ||
394+
property == "rocksdb.block-cache-pinned-usage")) {
395+
return Status::OK();
396+
}
397+
388398
db_->GetProperty(handles_[1], property, &value);
389399
*out += std::strtoull(value.c_str(), nullptr, 10);
390400
return Status::OK();

src/storage/src/redis_zsets.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ Status RedisZSets::Open(const StorageOptions& storage_options, const std::string
8383
column_families.emplace_back(rocksdb::kDefaultColumnFamilyName, meta_cf_ops);
8484
column_families.emplace_back("data_cf", data_cf_ops);
8585
column_families.emplace_back("score_cf", score_cf_ops);
86+
share_block_cache_ = storage_options.share_block_cache;
8687
return rocksdb::DB::Open(db_ops, db_path, column_families, &handles_, &db_);
8788
}
8889

@@ -101,6 +102,16 @@ Status RedisZSets::GetProperty(const std::string& property, uint64_t* out) {
101102
std::string value;
102103
db_->GetProperty(handles_[0], property, &value);
103104
*out = std::strtoull(value.c_str(), nullptr, 10);
105+
106+
// If share_block_cache is enabled, block cache related properties are shared among CFs,
107+
// so we only need to get the value from the first CF to avoid double counting.
108+
if (share_block_cache_ &&
109+
(property == "rocksdb.block-cache-usage" ||
110+
property == "rocksdb.block-cache-capacity" ||
111+
property == "rocksdb.block-cache-pinned-usage")) {
112+
return Status::OK();
113+
}
114+
104115
db_->GetProperty(handles_[1], property, &value);
105116
*out += std::strtoull(value.c_str(), nullptr, 10);
106117
db_->GetProperty(handles_[2], property, &value);

0 commit comments

Comments
 (0)