Skip to content

Commit

Permalink
feat: add storage option is_use_raft
Browse files Browse the repository at this point in the history
  • Loading branch information
longfar-ncy committed Mar 16, 2024
1 parent 478fe1f commit 512e4f2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/storage/include/storage/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ struct StorageOptions {
size_t small_compaction_threshold = 5000;
size_t small_compaction_duration_threshold = 10000;
size_t db_instance_num = 3; // default = 3
bool is_use_raft = true;
Status ResetOptions(const OptionType& option_type, const std::unordered_map<std::string, std::string>& options_map);
};

Expand Down
1 change: 1 addition & 0 deletions src/storage/src/redis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Redis::~Redis() {
}

Status Redis::Open(const StorageOptions& storage_options, const std::string& db_path) {
is_use_raft_ = storage_options.is_use_raft;
statistics_store_->SetCapacity(storage_options.statistics_max_size);
small_compaction_threshold_ = storage_options.small_compaction_threshold;

Expand Down
3 changes: 3 additions & 0 deletions src/storage/src/redis.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ class Redis {
std::atomic_uint64_t small_compaction_duration_threshold_;
std::unique_ptr<LRUCache<std::string, KeyStatistics>> statistics_store_;

// For raft
bool is_use_raft_;

Status UpdateSpecificKeyStatistics(const DataType& dtype, const std::string& key, uint64_t count);
Status UpdateSpecificKeyDuration(const DataType& dtype, const std::string& key, uint64_t duration);
Status AddCompactKeyTaskIfNeeded(const DataType& dtype, const std::string& key, uint64_t count, uint64_t duration);
Expand Down
4 changes: 2 additions & 2 deletions src/storage/src/redis_hashes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Status Redis::HDel(const Slice& key, const std::vector<std::string>& fields, int
}
}

auto batch = Batch::CreateBatch(this, true);
auto batch = Batch::CreateBatch(this, is_use_raft_);
rocksdb::ReadOptions read_options;
const rocksdb::Snapshot* snapshot;

Expand Down Expand Up @@ -617,7 +617,7 @@ Status Redis::HMSet(const Slice& key, const std::vector<FieldValue>& fvs) {
}

Status Redis::HSet(const Slice& key, const Slice& field, const Slice& value, int32_t* res) {
auto batch = Batch::CreateBatch(this, true);
auto batch = Batch::CreateBatch(this, is_use_raft_);
ScopeRecordLock l(lock_mgr_, key);

uint64_t version = 0;
Expand Down

0 comments on commit 512e4f2

Please sign in to comment.