Skip to content
Merged
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
10 changes: 8 additions & 2 deletions src/redis_db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -358,15 +358,21 @@ void Database::AppendNamespacePrefix(const Slice &user_key, std::string *output)
ComposeNamespaceKey(namespace_, user_key, output);
}

rocksdb::Status Database::FindKeyRangeWithPrefix(const std::string &prefix, std::string *begin, std::string *end) {
rocksdb::Status Database::FindKeyRangeWithPrefix(const std::string &prefix,
std::string *begin,
std::string *end,
rocksdb::ColumnFamilyHandle *cf_handle) {
if (cf_handle == nullptr) {
cf_handle = metadata_cf_handle_;
}
begin->clear();
end->clear();

LatestSnapShot ss(db_);
rocksdb::ReadOptions read_options;
read_options.snapshot = ss.GetSnapShot();
read_options.fill_cache = false;
auto iter = db_->NewIterator(read_options, metadata_cf_handle_);
auto iter = db_->NewIterator(read_options, cf_handle);
iter->Seek(prefix);
if (!iter->Valid() || !iter->key().starts_with(prefix)) {
delete iter;
Expand Down
5 changes: 4 additions & 1 deletion src/redis_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ class Database {
std::vector<std::string> *keys);
rocksdb::Status RandomKey(const std::string &cursor, std::string *key);
void AppendNamespacePrefix(const Slice &user_key, std::string *output);
rocksdb::Status FindKeyRangeWithPrefix(const std::string &prefix, std::string *begin, std::string *end);
rocksdb::Status FindKeyRangeWithPrefix(const std::string &prefix,
std::string *begin,
std::string *end,
rocksdb::ColumnFamilyHandle *cf_handle = nullptr);

protected:
Engine::Storage *storage_;
Expand Down
9 changes: 4 additions & 5 deletions src/storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -472,16 +472,15 @@ uint64_t Storage::GetTotalSize(const std::string &ns) {
ComposeNamespaceKey(ns, "", &prefix);

Redis::Database db(this, ns);
auto s = db.FindKeyRangeWithPrefix(prefix, &begin_key, &end_key);
if (!s.ok()) {
return 0;
}
uint64_t size, total_size = 0;
rocksdb::Range r(begin_key, end_key);
uint8_t include_both = rocksdb::DB::SizeApproximationFlags::INCLUDE_FILES |
rocksdb::DB::SizeApproximationFlags::INCLUDE_MEMTABLES;
for (auto cf_handle : cf_handles_) {
if (cf_handle == GetCFHandle(kPubSubColumnFamilyName)) continue;
auto s = db.FindKeyRangeWithPrefix(prefix, &begin_key, &end_key, cf_handle);
if (!s.ok()) continue;

rocksdb::Range r(begin_key, end_key);
db_->GetApproximateSizes(cf_handle, &r, 1, &size, include_both);
total_size += size;
}
Expand Down