Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow check god user read from follower #4674

Merged
merged 1 commit into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/daemons/MetaDaemonInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/meta/RootUserMan.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ namespace meta {
* */
class RootUserMan {
public:
static ErrorOr<nebula::cpp2::ErrorCode, bool> isGodExists(kvstore::KVStore* kv) {
static ErrorOr<nebula::cpp2::ErrorCode, bool> isGodExists(kvstore::KVStore* kv, bool fromLeader) {
auto rolePrefix = MetaKeyUtils::roleSpacePrefix(kDefaultSpaceId);
std::unique_ptr<kvstore::KVIterator> 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;
}
Expand Down