You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by "caipengbo (via GitHub)" <gi...@apache.org> on 2023/07/16 09:25:26 UTC

[GitHub] [kvrocks] caipengbo commented on a diff in pull request #1534: Support rapid slot migration based on raw key value

caipengbo commented on code in PR #1534:
URL: https://github.com/apache/kvrocks/pull/1534#discussion_r1264647731


##########
src/cluster/slot_migrate.cc:
##########
@@ -1110,3 +1162,224 @@ void SlotMigrator::resumeSyncCtx(const Status &migrate_result) {
     blocking_context_ = nullptr;
   }
 }
+
+void SlotMigrator::SetMigrateBatchRateLimit(size_t bytes_per_sec) {
+  migrate_batch_bytes_per_sec_ =
+      (bytes_per_sec == 0 || bytes_per_sec > kMaxMigrateBatchRate) ? kMaxMigrateBatchRate : bytes_per_sec;
+  migrate_batch_rate_limiter_->SetBytesPerSecond(static_cast<int64_t>(migrate_batch_bytes_per_sec_));
+}
+
+MigrateType SlotMigrator::GetMigrateType() { return static_cast<MigrateType>(svr_->GetConfig()->migrate_type); }
+
+Status SlotMigrator::getClockSkew(int64_t *diff_us) {
+  assert(dst_redis_context_ != nullptr);
+  uint64_t send_timestamp = util::GetTimeStampUS();
+  auto *reply = static_cast<redisReply *>(redisCommand(dst_redis_context_, "TIME"));
+  uint64_t receive_timestamp = util::GetTimeStampUS();
+
+  auto exit = MakeScopeExit([reply] { freeReplyObject(reply); });
+
+  if (dst_redis_context_->err != 0) {
+    return {Status::NotOK, std::string(dst_redis_context_->errstr)};
+  }
+
+  if (reply == nullptr) {
+    return {Status::NotOK, "get null reply from TIME command"};
+  }
+
+  if (reply->type == REDIS_REPLY_ERROR) {
+    auto error_str = std::string(reply->str);
+    return {Status::NotOK, error_str};
+  }
+
+  if (reply->elements != 2) {
+    return {Status::NotOK, "get invalid reply from TIME command"};
+  }
+
+  uint64_t dst_timestamp = std::stoul(reply->element[0]->str) * 1000000 + std::stoul(reply->element[1]->str);

Review Comment:
   Yes, normal `TIME` command will parse successfully.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org