You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kvrocks.apache.org by tw...@apache.org on 2022/06/28 14:06:13 UTC
[incubator-kvrocks] branch unstable updated: Use unique_ptr in SlotMigrate and FeedSlaveThread (#682)
This is an automated email from the ASF dual-hosted git repository.
twice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/incubator-kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new ef7cd21 Use unique_ptr in SlotMigrate and FeedSlaveThread (#682)
ef7cd21 is described below
commit ef7cd2149cfb70c88e1a818608fabb1d72faa740
Author: 428 <29...@qq.com>
AuthorDate: Tue Jun 28 22:06:08 2022 +0800
Use unique_ptr in SlotMigrate and FeedSlaveThread (#682)
Co-authored-by: Twice <tw...@gmail.com>
---
src/replication.cc | 4 ----
src/replication.h | 6 +++---
src/slot_migrate.cc | 18 +++++++++++-------
src/slot_migrate.h | 2 +-
4 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/src/replication.cc b/src/replication.cc
index 76bd4f7..c1a4a29 100644
--- a/src/replication.cc
+++ b/src/replication.cc
@@ -39,10 +39,6 @@
#include "server.h"
#include "event_util.h"
-FeedSlaveThread::~FeedSlaveThread() {
- delete conn_;
-}
-
Status FeedSlaveThread::Start() {
try {
t_ = std::thread([this]() {
diff --git a/src/replication.h b/src/replication.h
index f4e33b8..69e3eef 100644
--- a/src/replication.h
+++ b/src/replication.h
@@ -58,20 +58,20 @@ class FeedSlaveThread {
public:
explicit FeedSlaveThread(Server *srv, Redis::Connection *conn, rocksdb::SequenceNumber next_repl_seq)
: srv_(srv), conn_(conn), next_repl_seq_(next_repl_seq) {}
- ~FeedSlaveThread();
+ ~FeedSlaveThread() = default;
Status Start();
void Stop();
void Join();
bool IsStopped() { return stop_; }
- Redis::Connection *GetConn() { return conn_; }
+ Redis::Connection *GetConn() { return conn_.get(); }
rocksdb::SequenceNumber GetCurrentReplSeq() { return next_repl_seq_ == 0 ? 0 : next_repl_seq_-1; }
private:
uint64_t interval = 0;
bool stop_ = false;
Server *srv_ = nullptr;
- Redis::Connection *conn_ = nullptr;
+ std::unique_ptr<Redis::Connection> conn_ = nullptr;
rocksdb::SequenceNumber next_repl_seq_ = 0;
std::thread t_;
std::unique_ptr<rocksdb::TransactionLogIterator> iter_ = nullptr;
diff --git a/src/slot_migrate.cc b/src/slot_migrate.cc
index 9273493..4e6ec41 100644
--- a/src/slot_migrate.cc
+++ b/src/slot_migrate.cc
@@ -19,9 +19,13 @@
*/
#include "slot_migrate.h"
+
+#include <utility>
+
#include "batch_extractor.h"
#include "event_util.h"
+
static std::map<RedisType, std::string> type_to_cmd = {
{kRedisString, "set"},
{kRedisList, "rpush"},
@@ -104,12 +108,13 @@ Status SlotMigrate::MigrateStart(Server *svr, const std::string &node_id, const
dst_node_ = node_id;
// Create migration job
- SlotMigrateJob *job = new SlotMigrateJob(slot, dst_ip, dst_port,
- speed, pipeline_size, seq_gap);
- std::lock_guard<std::mutex> guard(job_mutex_);
- slot_job_ = job;
- job_cv_.notify_one();
-
+ auto job = std::unique_ptr<SlotMigrateJob>(new SlotMigrateJob(slot, dst_ip, dst_port,
+ speed, pipeline_size, seq_gap));
+ {
+ std::lock_guard<std::mutex> guard(job_mutex_);
+ slot_job_ = std::move(job);
+ job_cv_.notify_one();
+ }
LOG(INFO) << "[migrate] Start migrating slot " << slot
<< " to " << dst_ip << ":" << dst_port;
return Status::OK();
@@ -382,7 +387,6 @@ Status SlotMigrate::Clean(void) {
wal_begin_seq_ = 0;
wal_increment_seq_ = 0;
std::lock_guard<std::mutex> guard(job_mutex_);
- delete slot_job_;
slot_job_ = nullptr;
migrate_slot_ = -1;
SetMigrateStopFlag(false);
diff --git a/src/slot_migrate.h b/src/slot_migrate.h
index 1c3c234..4eae263 100644
--- a/src/slot_migrate.h
+++ b/src/slot_migrate.h
@@ -160,7 +160,7 @@ class SlotMigrate : public Redis::Database {
std::thread t_;
std::mutex job_mutex_;
std::condition_variable job_cv_;
- SlotMigrateJob *slot_job_;
+ std::unique_ptr<SlotMigrateJob> slot_job_ = nullptr;
std::string dst_node_;
std::string dst_ip_;
int dst_port_;