Skip to content

Commit f0d848f

Browse files
authoredFeb 28, 2022
Avoid flush all redis db in kvrocks2redis (apache#498)
In the kvrocks2redis tool, when kvrocks sends data to Redis, it will flush the whole target redis by using the FLUSHALL command. We shouldn't do that, we just need to clear the target DB. In addition, modify the comments in the configuration file to make it more accessible. And based on the output of cpplint, fixed the nonstandard header file.
1 parent 5c6fcfd commit f0d848f

File tree

8 files changed

+24
-28
lines changed

8 files changed

+24
-28
lines changed
 

‎tools/kvrocks2redis/config.cc

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
#include "config.h"
2-
#include <fcntl.h>
3-
#include <string.h>
2+
43
#include <strings.h>
5-
#include <glog/logging.h>
64
#include <rocksdb/env.h>
75

86
#include <fstream>
97
#include <iostream>
10-
#include <sstream>
8+
#include <utility>
119
#include <vector>
1210

1311
#include "../../src/util.h"
14-
#include "../../src/status.h"
1512
#include "../../src/config.h"
1613

1714
namespace Kvrocks2redis {
+11-11
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
################################ GENERAL #####################################
22

3-
# The value should be INFO, WARNING, ERROR, FATAL
4-
# default is INFO
3+
# The value should be INFO, WARNING, ERROR, FATAL.
4+
#
5+
# Default is INFO
56
loglevel INFO
67

78
# By default kvrocks2redis does not run as a daemon. Use 'yes' if you need it.
89
# Note that kvrocks2redis will write a pid file in /var/run/kvrocks2redis.pid when daemonized.
910
daemonize no
1011

11-
# The working directory
12-
#
13-
# The kvrocks node db directory
12+
# The kvrocks working directory.
1413
# Note that you must specify a directory here, not a file name.
1514
data-dir ./data
1615

17-
# Intermediate files are output to this directory when the kvrocks2redis program runs
18-
#
16+
# Intermediate files are output to this directory when the kvrocks2redis program runs.
1917
output-dir ./
2018

21-
# Sync kvrocks node. Use the node's Psync command to get the newest wal raw write_batch
19+
# Sync kvrocks node. Use the node's Psync command to get the newest wal raw write_batch.
2220
#
2321
# kvrocks <kvrocks_ip> <kvrocks_port> [<kvrocks_auth>]
2422
kvrocks 127.0.0.1 6666
@@ -29,7 +27,9 @@ kvrocks 127.0.0.1 6666
2927
cluster-enable yes
3028

3129
################################ NAMESPACE AND Sync Target Redis #####################################
32-
# namespace.{namespace} <redis_ip> <redis_port> [<auth> <db_number>]
33-
#
34-
# Default db_number is 0
30+
# Synchronize the specified namespace data to the specified Redis DB.
31+
# Warning: It will flush the target redis DB data.
32+
#
33+
# namespace.{namespace} <redis_ip> <redis_port> [<redis_auth> <redis_db_number>]
34+
# Default redis_db_number is 0
3535
namespace.__namespace 127.0.0.1 6379

‎tools/kvrocks2redis/parser.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#include "parser.h"
22

3-
#include <memory>
4-
53
#include <glog/logging.h>
64
#include <rocksdb/write_batch.h>
75

8-
#include "../../src/redis_bitmap.h"
6+
#include <memory>
7+
98
#include "../../src/redis_slot.h"
109
#include "../../src/redis_reply.h"
1110

‎tools/kvrocks2redis/redis_writer.cc

+3-4
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,15 @@ Status RedisWriter::Write(const std::string &ns, const std::vector<std::string>
3939
return Status::OK();
4040
}
4141

42-
Status RedisWriter::FlushAll(const std::string &ns) {
43-
auto s = Writer::FlushAll(ns);
42+
Status RedisWriter::FlushDB(const std::string &ns) {
43+
auto s = Writer::FlushDB(ns);
4444
if (!s.IsOK()) {
4545
return s;
4646
}
4747

4848
updateNextOffset(ns, 0);
4949

50-
//Warning: this will flush all redis data
51-
s = Write(ns, {Redis::Command2RESP({"FLUSHALL"})});
50+
s = Write(ns, {Redis::Command2RESP({"FLUSHDB"})});
5251
if (!s.IsOK()) return s;
5352

5453
return Status::OK();

‎tools/kvrocks2redis/redis_writer.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <glog/logging.h>
4+
#include <map>
45
#include <string>
56
#include <vector>
67
#include <thread>
@@ -12,7 +13,7 @@ class RedisWriter : public Writer {
1213
explicit RedisWriter(Kvrocks2redis::Config *config);
1314
~RedisWriter();
1415
Status Write(const std::string &ns, const std::vector<std::string> &aofs) override;
15-
Status FlushAll(const std::string &ns) override;
16+
Status FlushDB(const std::string &ns) override;
1617

1718
void Stop() override;
1819

‎tools/kvrocks2redis/sync.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,9 @@ Status Sync::incrementBatchLoop() {
189189
void Sync::parseKVFromLocalStorage() {
190190
LOG(INFO) << "[kvrocks2redis] Start parsing kv from the local storage";
191191
for (const auto &iter : config_->tokens) {
192-
auto s = writer_->FlushAll(iter.first);
192+
auto s = writer_->FlushDB(iter.first);
193193
if (!s.IsOK()) {
194-
LOG(ERROR) << "[kvrocks2redis] Failed to flush all in namespace: " << iter.first
194+
LOG(ERROR) << "[kvrocks2redis] Failed to flush target redis db in namespace: " << iter.first
195195
<< ", encounter error: " << s.Msg();
196196
return;
197197
}

‎tools/kvrocks2redis/writer.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Status Writer::Write(const std::string &ns, const std::vector<std::string> &aofs
2121
return Status::OK();
2222
}
2323

24-
Status Writer::FlushAll(const std::string &ns) {
24+
Status Writer::FlushDB(const std::string &ns) {
2525
auto s = GetAofFd(ns, true);
2626
if (!s.IsOK()) {
2727
return Status(Status::NotOK, s.Msg());

‎tools/kvrocks2redis/writer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Writer {
1414
explicit Writer(Kvrocks2redis::Config *config) : config_(config) {}
1515
~Writer();
1616
virtual Status Write(const std::string &ns, const std::vector<std::string> &aofs);
17-
virtual Status FlushAll(const std::string &ns);
17+
virtual Status FlushDB(const std::string &ns);
1818
virtual void Stop() {}
1919
Status OpenAofFile(const std::string &ns, bool truncate);
2020
Status GetAofFd(const std::string &ns, bool truncate = false);

0 commit comments

Comments
 (0)
Please sign in to comment.