Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: hset/hdel wrote by braft and binlog #213

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
bc9356d
style: clear include headers
longfar-ncy Mar 11, 2024
e093290
feat: add WriteDoneClosure and Apply
longfar-ncy Mar 11, 2024
7401b39
feat: generate binlog.proto in cmake
longfar-ncy Mar 11, 2024
5d2528e
feat: add binlog write callback in storage
longfar-ncy Mar 11, 2024
2dc674a
feat: finish on apply
longfar-ncy Mar 11, 2024
8a5aadb
feat: 'hset' wrote by braft
longfar-ncy Mar 11, 2024
c205ce1
style
longfar-ncy Mar 11, 2024
ff0a38d
feat: cmd hdel write by binlog
longfar-ncy Mar 12, 2024
478fe1f
fix: add depends of custom command
longfar-ncy Mar 16, 2024
512e4f2
feat: add storage option is_use_raft
longfar-ncy Mar 16, 2024
06a6ef7
fix: comment
longfar-ncy Mar 21, 2024
629744c
fix: initialize member variable
longfar-ncy Mar 21, 2024
f76a1d2
Merge branch 'import-braft' into feat/praft-binlog
longfar-ncy Mar 26, 2024
404e8ae
fix: return leader info when write on follower
longfar-ncy Mar 26, 2024
34e4368
fix: remove assert(0)
longfar-ncy Mar 26, 2024
a3180ee
fix: raft_timeout_s
longfar-ncy Mar 26, 2024
08910ee
test: add a simple script to test consistency
longfar-ncy Mar 27, 2024
1c34047
feat: avoid include praft.h in storage and add config option for raft…
longfar-ncy Mar 28, 2024
8fa8f15
fix: remove spare space in pikiwidb.conf
longfar-ncy Mar 28, 2024
673f0b2
test: add consistency go test
longfar-ncy Mar 29, 2024
565285a
test: remove shell script
longfar-ncy Mar 29, 2024
b5560be
fix: default raft_timeout value and tab size
longfar-ncy Apr 3, 2024
c3d1c8b
fix: create `PARENT` dir bug
longfar-ncy Apr 4, 2024
d1a7312
style: format
longfar-ncy Apr 5, 2024
772556b
refactor: use protobuf-lite
longfar-ncy Apr 5, 2024
6359d6d
fix: add dummy service
longfar-ncy Apr 5, 2024
cbc6603
fix: details
longfar-ncy Apr 5, 2024
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
1 change: 1 addition & 0 deletions src/storage/include/storage/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct StorageOptions {
size_t small_compaction_duration_threshold = 10000;
size_t db_instance_num = 3; // default = 3
bool is_use_raft = true;
uint32_t raft_timeout = 10;
longfar-ncy marked this conversation as resolved.
Show resolved Hide resolved
Status ResetOptions(const OptionType& option_type, const std::unordered_map<std::string, std::string>& options_map);
};

Expand Down
17 changes: 10 additions & 7 deletions src/storage/src/batch.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (c) 2024-present, Qihoo, Inc. All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

#pragma once
longfar-ncy marked this conversation as resolved.
Show resolved Hide resolved

#include <chrono>
Expand Down Expand Up @@ -47,7 +54,7 @@ class RocksBatch : public Batch {

class BinlogBatch : public Batch {
public:
BinlogBatch(int32_t index, int32_t seconds = 10) : seconds_(seconds) {
BinlogBatch(int32_t index, uint32_t seconds = 10) : seconds_(seconds) {
binlog_.set_db_id(0);
binlog_.set_slot_idx(index);
}
Expand All @@ -71,10 +78,6 @@ class BinlogBatch : public Batch {
std::promise<Status> promise;
auto future = promise.get_future();
pikiwidb::PRaft::Instance().AppendLog(binlog_, std::move(promise));
if (seconds_ == -1) { // if do not require timeout
return future.get();
}

auto status = future.wait_for(std::chrono::seconds(seconds_));
longfar-ncy marked this conversation as resolved.
Show resolved Hide resolved
if (status == std::future_status::timeout) {
return Status::Incomplete("Wait for write timeout");
Expand All @@ -84,12 +87,12 @@ class BinlogBatch : public Batch {

private:
pikiwidb::Binlog binlog_;
int32_t seconds_;
uint32_t seconds_;
longfar-ncy marked this conversation as resolved.
Show resolved Hide resolved
};

inline auto Batch::CreateBatch(Redis* redis, bool use_binlog) -> std::unique_ptr<Batch> {
if (use_binlog) {
return std::make_unique<BinlogBatch>(redis->GetIndex());
return std::make_unique<BinlogBatch>(redis->GetIndex(), redis->GetRaftTimeout());
}
return std::make_unique<RocksBatch>(redis->GetDB(), redis->GetWriteOptions(), redis->GetColumnFamilyHandles());
}
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 @@ -53,6 +53,7 @@ Redis::~Redis() {

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

Expand Down
2 changes: 2 additions & 0 deletions src/storage/src/redis.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ class Redis {
void GetRocksDBInfo(std::string& info, const char* prefix);
auto GetWriteOptions() const -> const rocksdb::WriteOptions& { return default_write_options_; }
auto GetColumnFamilyHandles() const -> const std::vector<rocksdb::ColumnFamilyHandle*>& { return handles_; }
auto GetRaftTimeout() const -> uint32_t { return raft_timeout_; }

// Sets Commands
Status SAdd(const Slice& key, const std::vector<std::string>& members, int32_t* ret);
Expand Down Expand Up @@ -358,6 +359,7 @@ class Redis {

// For raft
bool is_use_raft_;
uint32_t raft_timeout_;
longfar-ncy marked this conversation as resolved.
Show resolved Hide resolved

Status UpdateSpecificKeyStatistics(const DataType& dtype, const std::string& key, uint64_t count);
Status UpdateSpecificKeyDuration(const DataType& dtype, const std::string& key, uint64_t duration);
Expand Down
Loading