Skip to content

Commit

Permalink
change strategy for collect user data
Browse files Browse the repository at this point in the history
  • Loading branch information
QlQlqiqi committed Sep 20, 2024
1 parent 9d1044b commit 2b59df0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions include/pika_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const uint32_t configReplicationIDSize = 50;
class PikaConf : public pstd::BaseConf {
public:
enum CompactionStrategy {
NONE,
FullCompact,
OldestOrBestDeleteRatioSstCompact
};
Expand Down
4 changes: 2 additions & 2 deletions src/pika_conf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ int PikaConf::Load() {
} else if (cs_ == "obd-compact") {
compaction_strategy_ = OldestOrBestDeleteRatioSstCompact;
} else {
compaction_strategy_ = FullCompact;
compaction_strategy_ = NONE;
}

// least-free-disk-resume-size
Expand Down Expand Up @@ -861,7 +861,7 @@ int PikaConf::ConfigRewrite() {
} else if (cs_ == "obd-compact") {
compaction_strategy_ = OldestOrBestDeleteRatioSstCompact;
} else {
compaction_strategy_ = FullCompact;
compaction_strategy_ = NONE;
}

SetConfStr("disable_auto_compactions", disable_auto_compactions_ ? "true" : "false");
Expand Down
27 changes: 17 additions & 10 deletions src/storage/src/redis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,17 @@ class MyTablePropertiesCollector : public rocksdb::TablePropertiesCollector {
total_keys++;
switch (type) {
case rocksdb::EntryType::kEntryPut: {
if (start_key.compare(key) > 0 || start_key.empty()) {
start_key = key;
const auto &k_str = key.ToString();
if (keys.find(k_str) != keys.end()) {
deleted_keys++;
break;
}
keys.emplace(k_str);
if (start_key > k_str || start_key.empty()) {
start_key = k_str;
}
if (stop_key.compare(key) < 0) {
stop_key = key;
if (stop_key > k_str) {
stop_key = k_str;
}
break;
}
Expand All @@ -94,8 +100,8 @@ class MyTablePropertiesCollector : public rocksdb::TablePropertiesCollector {
properties->emplace("total_keys", encoded);
pstd::PutFixed64(&encoded, deleted_keys);
properties->emplace("deleted_keys", encoded);
properties->emplace("start_key", start_key.ToString());
properties->emplace("stop_key", stop_key.ToString());
properties->emplace("start_key", start_key);
properties->emplace("stop_key", stop_key);
return rocksdb::Status::OK();
}

Expand All @@ -106,8 +112,8 @@ class MyTablePropertiesCollector : public rocksdb::TablePropertiesCollector {
properties.emplace("total_keys", encoded);
pstd::PutFixed64(&encoded, deleted_keys);
properties.emplace("deleted_keys", encoded);
properties.emplace("start_key", start_key.ToString());
properties.emplace("stop_key", stop_key.ToString());
properties.emplace("start_key", start_key);
properties.emplace("stop_key", stop_key);

return properties;
}
Expand All @@ -117,8 +123,9 @@ class MyTablePropertiesCollector : public rocksdb::TablePropertiesCollector {
private:
uint64_t total_keys;
uint64_t deleted_keys;
rocksdb::Slice start_key;
rocksdb::Slice stop_key;
std::string start_key;
std::string stop_key;
std::unordered_set<std::string> keys;
};

class MyTablePropertiesCollectorFactory : public rocksdb::TablePropertiesCollectorFactory {
Expand Down

0 comments on commit 2b59df0

Please sign in to comment.