Skip to content

Commit

Permalink
fix transfer leader to '':0 cause crash
Browse files Browse the repository at this point in the history
  • Loading branch information
critical27 committed Apr 2, 2022
1 parent 04fb5fa commit 0d2dbba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/kvstore/LogEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/meta/processors/admin/AdminClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ folly::Future<Status> 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);
Expand All @@ -53,6 +54,9 @@ folly::Future<Status> 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),
Expand Down

0 comments on commit 0d2dbba

Please sign in to comment.