diff --git a/src/daemons/MetaDaemonInit.cpp b/src/daemons/MetaDaemonInit.cpp index fe76db5f26b..69f17b44973 100644 --- a/src/daemons/MetaDaemonInit.cpp +++ b/src/daemons/MetaDaemonInit.cpp @@ -181,8 +181,9 @@ nebula::cpp2::ErrorCode initGodUser(nebula::kvstore::KVStore* kvstore, LOG(ERROR) << "Part leader get failed"; return nebula::error(ret); } + bool isLeader = nebula::value(ret) == localhost; LOG(INFO) << "Check root user"; // follower need to wait reading all ok, too. - auto checkRet = nebula::meta::RootUserMan::isGodExists(kvstore); + auto checkRet = nebula::meta::RootUserMan::isGodExists(kvstore, isLeader); if (!nebula::ok(checkRet)) { auto retCode = nebula::error(checkRet); if (retCode == nebula::cpp2::ErrorCode::E_LEADER_CHANGED) { @@ -193,7 +194,7 @@ nebula::cpp2::ErrorCode initGodUser(nebula::kvstore::KVStore* kvstore, LOG(ERROR) << "Parser God Role error:" << apache::thrift::util::enumNameSafe(retCode); return nebula::error(checkRet); } - if (nebula::value(ret) == localhost) { + if (isLeader) { auto existGod = nebula::value(checkRet); if (!existGod) { auto initGod = nebula::meta::RootUserMan::initRootUser(kvstore); diff --git a/src/meta/RootUserMan.h b/src/meta/RootUserMan.h index af3e454f312..db3ab131415 100644 --- a/src/meta/RootUserMan.h +++ b/src/meta/RootUserMan.h @@ -21,10 +21,10 @@ namespace meta { * */ class RootUserMan { public: - static ErrorOr isGodExists(kvstore::KVStore* kv) { + static ErrorOr isGodExists(kvstore::KVStore* kv, bool fromLeader) { auto rolePrefix = MetaKeyUtils::roleSpacePrefix(kDefaultSpaceId); std::unique_ptr iter; - auto code = kv->prefix(kDefaultSpaceId, kDefaultPartId, rolePrefix, &iter, false); + auto code = kv->prefix(kDefaultSpaceId, kDefaultPartId, rolePrefix, &iter, !fromLeader); if (code != nebula::cpp2::ErrorCode::SUCCEEDED) { return code; }