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

check god role exist when meta init #4330

Merged
merged 3 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/daemons/MetaDaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ 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::isGodExists(gKVStore.get())) {
if (!nebula::meta::RootUserMan::initRootUser(gKVStore.get())) {
LOG(ERROR) << "Init root user failed";
return EXIT_FAILURE;
Expand Down
2 changes: 1 addition & 1 deletion src/daemons/StandAloneDaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ 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::isGodExists(gMetaKVStore.get())) {
if (!nebula::meta::RootUserMan::initRootUser(gMetaKVStore.get())) {
LOG(ERROR) << "Init root user failed";
return;
Expand Down
21 changes: 21 additions & 0 deletions src/meta/RootUserMan.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@ namespace meta {
* */
class RootUserMan {
public:
static 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) {
LOG(INFO) << "Prefix God Role Failed";
return false;
}
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