From 0d2dbbaa844dcde96d7019bf1cf755f829429463 Mon Sep 17 00:00:00 2001 From: Doodle <13706157+critical27@users.noreply.github.com> Date: Sat, 2 Apr 2022 12:35:42 +0800 Subject: [PATCH] fix transfer leader to '':0 cause crash --- src/kvstore/LogEncoder.cpp | 4 +--- src/meta/processors/admin/AdminClient.cpp | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/kvstore/LogEncoder.cpp b/src/kvstore/LogEncoder.cpp index db5adfa08df..170bcaad02d 100644 --- a/src/kvstore/LogEncoder.cpp +++ b/src/kvstore/LogEncoder.cpp @@ -217,8 +217,6 @@ decodeBatchValue(folly::StringPiece encoded) { std::string encodeHost(LogType type, const HostAddr& host) { std::string encoded; - // 15 refers to "255.255.255.255" - encoded.reserve(sizeof(int64_t) + 1 + 15 + sizeof(int)); int64_t ts = time::WallClock::fastNowInMilliSec(); std::string encodedHost; apache::thrift::CompactSerializer::serialize(host, &encodedHost); @@ -232,7 +230,7 @@ std::string encodeHost(LogType type, const HostAddr& host) { HostAddr decodeHost(LogType type, const folly::StringPiece& encoded) { HostAddr addr; - CHECK_GE(encoded.size(), sizeof(int64_t) + 1 + sizeof(size_t) + sizeof(Port)); + CHECK_GE(encoded.size(), sizeof(int64_t) + 1); CHECK(encoded[sizeof(int64_t)] == type); folly::StringPiece raw = encoded; diff --git a/src/meta/processors/admin/AdminClient.cpp b/src/meta/processors/admin/AdminClient.cpp index dbcfdd90a2d..d9e493df81f 100644 --- a/src/meta/processors/admin/AdminClient.cpp +++ b/src/meta/processors/admin/AdminClient.cpp @@ -43,6 +43,7 @@ folly::Future AdminClient::transLeader(GraphSpaceID spaceId, } auto target = dst; if (dst == kRandomPeer) { + // pick a alive host as target when dst not specified for (auto& p : peers) { if (p != src) { auto retCode = ActiveHostsMan::isLived(kv_, p); @@ -53,6 +54,9 @@ folly::Future AdminClient::transLeader(GraphSpaceID spaceId, } } } + if (target == kRandomPeer) { + return Status::Error("No active peers found"); + } req.new_leader_ref() = std::move(target); return getResponseFromPart( Utils::getAdminAddrFromStoreAddr(src),