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

[auto-pick-to-release-3.2]check god role exist when meta init #4347

Closed
wants to merge 1 commit into from
Closed
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
15 changes: 10 additions & 5 deletions src/daemons/MetaDaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,16 @@ int main(int argc, char* argv[]) {
}
if (nebula::value(ret) == localhost) {
LOG(INFO) << "Check and init root user";
if (!nebula::meta::RootUserMan::isUserExists(gKVStore.get())) {
if (!nebula::meta::RootUserMan::initRootUser(gKVStore.get())) {
LOG(ERROR) << "Init root user failed";
return EXIT_FAILURE;
}
auto checkRet = nebula::meta::RootUserMan::isGodExists(gKVStore.get());
if (!nebula::ok(checkRet)) {
auto retCode = nebula::error(checkRet);
LOG(ERROR) << "Parser God Role error:" << apache::thrift::util::enumNameSafe(retCode);
return EXIT_FAILURE;
}
auto existGod = nebula::value(checkRet);
if (!existGod && !nebula::meta::RootUserMan::initRootUser(gKVStore.get())) {
LOG(ERROR) << "Init root user failed";
return EXIT_FAILURE;
}
}
}
Expand Down
15 changes: 10 additions & 5 deletions src/daemons/StandAloneDaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,16 @@ int main(int argc, char *argv[]) {
}
if (nebula::value(ret) == metaLocalhost) {
LOG(INFO) << "Check and init root user";
if (!nebula::meta::RootUserMan::isUserExists(gMetaKVStore.get())) {
if (!nebula::meta::RootUserMan::initRootUser(gMetaKVStore.get())) {
LOG(ERROR) << "Init root user failed";
return;
}
auto checkRet = nebula::meta::RootUserMan::isGodExists(gMetaKVStore.get());
if (!nebula::ok(checkRet)) {
auto retCode = nebula::error(checkRet);
LOG(ERROR) << "Parser God Role error:" << apache::thrift::util::enumNameSafe(retCode);
return;
}
auto existGod = nebula::value(checkRet);
if (!existGod && !nebula::meta::RootUserMan::initRootUser(gMetaKVStore.get())) {
LOG(ERROR) << "Init root user failed";
return;
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/meta/RootUserMan.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ namespace meta {
* */
class RootUserMan {
public:
static ErrorOr<nebula::cpp2::ErrorCode, bool> isGodExists(kvstore::KVStore* kv) {
auto rolePrefix = MetaKeyUtils::roleSpacePrefix(kDefaultSpaceId);
std::unique_ptr<kvstore::KVIterator> iter;
auto code = kv->prefix(kDefaultSpaceId, kDefaultPartId, rolePrefix, &iter, false);
if (code != nebula::cpp2::ErrorCode::SUCCEEDED) {
return code;
}
while (iter->valid()) {
auto val = iter->val();
auto type = *reinterpret_cast<const meta::cpp2::RoleType*>(val.begin());
if (type == meta::cpp2::RoleType::GOD) {
LOG(INFO) << "God user exists";
return true;
}
iter->next();
}
LOG(INFO) << "God user is not exists";
return false;
}

static bool isUserExists(kvstore::KVStore* kv) {
auto userKey = MetaKeyUtils::userKey("root");
std::string val;
Expand Down