Skip to content

Commit f7d2997

Browse files
wangshao1wangshaoyiMixficsolwuxianrong
authored
feat: Feature/floyd rebase unstable (OpenAtomFoundation#2413)
* feat: add floyd (OpenAtomFoundation#2347) * floyd: refactor storage to support multi rocksdb instance && todis key format --------- Co-authored-by: wangshaoyi <wangshaoyi@360.cn> * fix floyd keys (OpenAtomFoundation#2364) Co-authored-by: wuxianrong <wuxianrong@360.cn> * floyd rebase unstable branch * fix by review comments --------- Co-authored-by: wangshaoyi <wangshaoyi@360.cn> Co-authored-by: Mixficsol <838844609@qq.com> Co-authored-by: wuxianrong <wuxianrong@360.cn>
1 parent 1dae356 commit f7d2997

99 files changed

Lines changed: 5882 additions & 8140 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ elseif(${BUILD_TYPE} STREQUAL RELWITHDEBINFO)
5252
else()
5353
set(LIB_BUILD_TYPE RELEASE)
5454
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -g -DNDEBUG")
55-
5655
endif()
5756

5857
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
@@ -172,7 +171,6 @@ set(GTEST_INCLUDE_DIR ${INSTALL_INCLUDEDIR})
172171
set(GTEST_MAIN_INCLUDE_DIR ${INSTALL_INCLUDEDIR})
173172
set(GMOCK_INCLUDE_DIR ${INSTALL_INCLUDEDIR})
174173

175-
176174
ExternalProject_Add(gflags
177175
URL
178176
https://github.com/gflags/gflags/archive/refs/tags/v2.2.2.tar.gz

conf/pika.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
# Port 10221 is used for Rsync, and port 11221 is used for Replication, while the listening port is 9221.
88
port : 9221
99

10+
db-instance-num : 3
11+
rocksdb-ttl-second : 86400 * 7;
12+
rocksdb-periodic-second : 86400 * 3;
13+
1014
# Random value identifying the Pika server, its string length must be 40.
1115
# If not set, Pika will generate a random string with a length of 40 random characters.
1216
# run-id :

include/pika_admin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ class DiskRecoveryCmd : public Cmd {
536536

537537
private:
538538
void DoInitial() override;
539-
std::map<std::string, uint64_t> background_errors_;
539+
std::map<int, uint64_t> background_errors_;
540540
};
541541

542542
class ClearReplicationIDCmd : public Cmd {

include/pika_binlog.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
#include "pstd/include/pstd_mutex.h"
1313
#include "pstd/include/pstd_status.h"
1414
#include "pstd/include/noncopyable.h"
15-
1615
#include "include/pika_define.h"
1716

18-
1917
std::string NewFileName(const std::string& name, uint32_t current);
2018

2119
class Version final : public pstd::noncopyable {

include/pika_cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,4 @@ class PikaCache : public pstd::noncopyable, public std::enable_shared_from_this<
223223
std::vector<std::shared_ptr<pstd::Mutex>> cache_mutexs_;
224224
};
225225

226-
#endif
226+
#endif

include/pika_cache_load_thread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class PikaCacheLoadThread : public net::Thread {
3838
private:
3939
std::atomic_bool should_exit_;
4040
std::deque<std::tuple<const char, std::string, const std::shared_ptr<DB>>> loadkeys_queue_;
41-
41+
4242
pstd::CondVar loadkeys_cond_;
4343
pstd::Mutex loadkeys_mutex_;
4444

include/pika_conf.h

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
#include <set>
1212
#include <unordered_set>
1313

14+
#include "rocksdb/compression_type.h"
15+
1416
#include "pstd/include/base_conf.h"
1517
#include "pstd/include/pstd_mutex.h"
1618
#include "pstd/include/pstd_string.h"
1719

1820
#include "acl.h"
1921
#include "include/pika_define.h"
20-
#include "include/pika_meta.h"
2122
#include "rocksdb/compression_type.h"
2223

2324
#define kBinlogReadWinDefaultSize 9000
@@ -76,6 +77,15 @@ class PikaConf : public pstd::BaseConf {
7677
std::shared_lock l(rwlock_);
7778
return db_path_;
7879
}
80+
int db_instance_num() {
81+
return db_instance_num_;
82+
}
83+
uint64_t rocksdb_ttl_second() {
84+
return rocksdb_ttl_second_.load();
85+
}
86+
uint64_t rocksdb_periodic_compaction_second() {
87+
return rocksdb_periodic_second_.load();
88+
}
7989
std::string db_sync_path() {
8090
std::shared_lock l(rwlock_);
8191
return db_sync_path_;
@@ -376,7 +386,6 @@ class PikaConf : public pstd::BaseConf {
376386
bool daemonize() { return daemonize_; }
377387
std::string pidfile() { return pidfile_; }
378388
int binlog_file_size() { return binlog_file_size_; }
379-
PikaMeta* local_meta() { return local_meta_.get(); }
380389
std::vector<rocksdb::CompressionType> compression_per_level();
381390
std::string compression_all_levels() const { return compression_per_level_; };
382391
static rocksdb::CompressionType GetCompression(const std::string& value);
@@ -416,6 +425,15 @@ class PikaConf : public pstd::BaseConf {
416425
TryPushDiffCommands("slaveof", value);
417426
slaveof_ = value;
418427
}
428+
429+
void SetRocksdbTTLSecond(uint64_t ttl) {
430+
rocksdb_ttl_second_.store(ttl);
431+
}
432+
433+
void SetRocksdbPeriodicSecond(uint64_t value) {
434+
rocksdb_periodic_second_.store(value);
435+
}
436+
419437
void SetReplicationID(const std::string& value) {
420438
std::lock_guard l(rwlock_);
421439
TryPushDiffCommands("replication-id", value);
@@ -655,6 +673,7 @@ class PikaConf : public pstd::BaseConf {
655673
int ConfigRewriteReplicationID();
656674

657675
private:
676+
// TODO: replace mutex with atomic value
658677
int port_ = 0;
659678
int slave_priority_ = 0;
660679
int thread_num_ = 0;
@@ -668,6 +687,7 @@ class PikaConf : public pstd::BaseConf {
668687
std::string log_path_;
669688
std::string log_level_;
670689
std::string db_path_;
690+
int db_instance_num_ = 0;
671691
std::string db_sync_path_;
672692
std::string compact_cron_;
673693
std::string compact_interval_;
@@ -719,6 +739,8 @@ class PikaConf : public pstd::BaseConf {
719739
int max_background_compactions_ = 0;
720740
int max_background_jobs_ = 0;
721741
int max_cache_files_ = 0;
742+
std::atomic<uint64_t> rocksdb_ttl_second_ = 0;
743+
std::atomic<uint64_t> rocksdb_periodic_second_ = 0;
722744
int max_bytes_for_level_multiplier_ = 0;
723745
int64_t block_size_ = 0;
724746
int64_t block_cache_ = 0;
@@ -787,7 +809,6 @@ class PikaConf : public pstd::BaseConf {
787809
int64_t blob_file_size_ = 256 * 1024 * 1024; // 256M
788810
std::string blob_compression_type_ = "none";
789811

790-
std::unique_ptr<PikaMeta> local_meta_;
791812
std::shared_mutex rwlock_;
792813

793814
// Rsync Rate limiting configuration

include/pika_consensus.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
#include <utility>
99

10+
#include "include/pika_define.h"
11+
#include "pstd/include/env.h"
1012
#include "include/pika_binlog_transverter.h"
1113
#include "include/pika_client_conn.h"
12-
#include "include/pika_define.h"
1314
#include "include/pika_slave_node.h"
1415
#include "include/pika_stable_log.h"
15-
#include "pstd/include/env.h"
1616

1717
class Context : public pstd::noncopyable {
1818
public:

include/pika_define.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ const std::string kDefaultRsyncAuth = "default";
4343
const int kMaxRsyncParallelNum = 4;
4444

4545
struct DBStruct {
46-
DBStruct(std::string tn)
47-
: db_name(std::move(tn)) {}
46+
DBStruct(std::string tn, int32_t inst_num)
47+
: db_name(std::move(tn)), db_instance_num(inst_num) {}
4848

4949
bool operator==(const DBStruct& db_struct) const {
50-
return db_name == db_struct.db_name;
50+
return db_name == db_struct.db_name && db_instance_num == db_struct.db_instance_num;
5151
}
5252
std::string db_name;
53+
int32_t db_instance_num = 0;
5354
};
5455

55-
// slave item
5656
struct SlaveItem {
5757
std::string ip_port;
5858
std::string ip;

include/pika_meta.h

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)