diff --git a/src/daemons/MetaDaemonInit.cpp b/src/daemons/MetaDaemonInit.cpp index e5faa16a2e0..198318e9820 100644 --- a/src/daemons/MetaDaemonInit.cpp +++ b/src/daemons/MetaDaemonInit.cpp @@ -142,28 +142,30 @@ std::unique_ptr initKV(std::vector p } auto version = nebula::meta::MetaVersionMan::getMetaVersionFromKV(kvstore.get()); - LOG(INFO) << "Get meta version is " << static_cast(version); - if (version == nebula::meta::MetaVersion::UNKNOWN) { - LOG(ERROR) << "Meta version is invalid"; - return nullptr; - } else if (version == nebula::meta::MetaVersion::V1) { - LOG(ERROR) << "Can't upgrade meta from V1 to V3_4"; - return nullptr; - } else if (version == nebula::meta::MetaVersion::V2) { - auto ret = nebula::meta::MetaVersionMan::updateMetaV2ToV3_4(engine); - if (!ret.ok()) { - LOG(ERROR) << "Update meta from V2 to V3_4 failed " << ret; - return nullptr; - } - } else if (version == nebula::meta::MetaVersion::V3) { + if (!nebula::ok(version)) { auto ret = nebula::meta::MetaVersionMan::updateMetaV3ToV3_4(engine); if (!ret.ok()) { LOG(ERROR) << "Update meta from V3 to V3_4 failed " << ret; return nullptr; } - nebula::meta::MetaVersionMan::setMetaVersionToKV(engine, nebula::meta::MetaVersion::V3_4); + } else { + auto v = nebula::value(version); + LOG(INFO) << "Get meta version is " << static_cast(v); + if (v == nebula::meta::MetaVersion::UNKNOWN) { + LOG(ERROR) << "Meta version is invalid"; + return nullptr; + } else if (v == nebula::meta::MetaVersion::V1) { + LOG(ERROR) << "Can't upgrade meta from V1 to V3_4"; + return nullptr; + } else if (v == nebula::meta::MetaVersion::V2) { + auto ret = nebula::meta::MetaVersionMan::updateMetaV2ToV3_4(engine); + if (!ret.ok()) { + LOG(ERROR) << "Update meta from V2 to V3_4 failed " << ret; + return nullptr; + } + } } - + nebula::meta::MetaVersionMan::setMetaVersionToKV(engine, nebula::meta::MetaVersion::V3_4); LOG(INFO) << "Nebula store init succeeded, clusterId " << gClusterId; return kvstore; } diff --git a/src/meta/MetaVersionMan.cpp b/src/meta/MetaVersionMan.cpp index 60708d502bb..6d850c499cd 100644 --- a/src/meta/MetaVersionMan.cpp +++ b/src/meta/MetaVersionMan.cpp @@ -21,7 +21,8 @@ namespace meta { static const std::string kMetaVersionKey = "__meta_version__"; // NOLINT // static -MetaVersion MetaVersionMan::getMetaVersionFromKV(kvstore::KVStore* kv) { +ErrorOr MetaVersionMan::getMetaVersionFromKV( + kvstore::KVStore* kv) { CHECK_NOTNULL(kv); std::string value; auto code = kv->get(kDefaultSpaceId, kDefaultPartId, kMetaVersionKey, &value, true); @@ -29,26 +30,10 @@ MetaVersion MetaVersionMan::getMetaVersionFromKV(kvstore::KVStore* kv) { auto version = *reinterpret_cast(value.data()); return version; } else { - return getVersionByHost(kv); + return code; } } -// static -MetaVersion MetaVersionMan::getVersionByHost(kvstore::KVStore* kv) { - const auto& hostPrefix = nebula::MetaKeyUtils::hostPrefix(); - std::unique_ptr iter; - auto code = kv->prefix(kDefaultSpaceId, kDefaultPartId, hostPrefix, &iter, true); - if (code != nebula::cpp2::ErrorCode::SUCCEEDED) { - return MetaVersion::UNKNOWN; - } - if (iter->valid()) { - auto v1KeySize = hostPrefix.size() + sizeof(int64_t); - return (iter->key().size() == v1KeySize) ? MetaVersion::V1 : MetaVersion::V3_4; - } - // No hosts exists, regard as version 3 - return MetaVersion::V3_4; -} - // static bool MetaVersionMan::setMetaVersionToKV(kvstore::KVEngine* engine, MetaVersion version) { CHECK_NOTNULL(engine); diff --git a/src/meta/MetaVersionMan.h b/src/meta/MetaVersionMan.h index dad31820cb3..9d39508cf56 100644 --- a/src/meta/MetaVersionMan.h +++ b/src/meta/MetaVersionMan.h @@ -7,6 +7,7 @@ #define META_METAVERSIONMAN_H_ #include "common/base/Base.h" +#include "common/base/ErrorOr.h" #include "common/utils/MetaKeyUtils.h" #include "kvstore/KVEngine.h" #include "kvstore/KVStore.h" @@ -35,7 +36,7 @@ class MetaVersionMan final { * @param kv * @return */ - static MetaVersion getMetaVersionFromKV(kvstore::KVStore* kv); + static ErrorOr getMetaVersionFromKV(kvstore::KVStore* kv); static bool setMetaVersionToKV(kvstore::KVEngine* engine, MetaVersion version); @@ -44,8 +45,6 @@ class MetaVersionMan final { static Status updateMetaV3ToV3_4(kvstore::KVEngine* engine); private: - static MetaVersion getVersionByHost(kvstore::KVStore* kv); - static Status doUpgradeV3ToV3_4(kvstore::KVEngine* engine); static Status doUpgradeV2ToV3(kvstore::KVEngine* engine); diff --git a/src/meta/processors/admin/HBProcessor.cpp b/src/meta/processors/admin/HBProcessor.cpp index 83ec67f8251..13ca5f8aa2b 100644 --- a/src/meta/processors/admin/HBProcessor.cpp +++ b/src/meta/processors/admin/HBProcessor.cpp @@ -108,7 +108,12 @@ void HBProcessor::process(const cpp2::HBReq& req) { auto version = metaVersion_.load(); if (version == -1) { - metaVersion_.store(static_cast(MetaVersionMan::getMetaVersionFromKV(kvstore_))); + auto v = MetaVersionMan::getMetaVersionFromKV(kvstore_); + if (nebula::ok(v)) { + metaVersion_.store(static_cast(nebula::value(v))); + } else { + metaVersion_.store(static_cast(MetaVersion::V3_4)); + } } resp_.meta_version_ref() = metaVersion_.load(); diff --git a/src/tools/meta-dump/MetaDumpTool.cpp b/src/tools/meta-dump/MetaDumpTool.cpp index 52074aa3756..cd36e36732e 100644 --- a/src/tools/meta-dump/MetaDumpTool.cpp +++ b/src/tools/meta-dump/MetaDumpTool.cpp @@ -56,20 +56,7 @@ class MetaDumper { } if (!found) { - prefix = MetaKeyUtils::hostPrefix(); - iter->Seek(rocksdb::Slice(prefix)); - while (iter->Valid() && iter->key().starts_with(prefix)) { - found = true; - auto v1KeySize = prefix.size() + sizeof(int64_t); - auto version = (iter->key().size() == v1KeySize) ? MetaVersion::V1 : MetaVersion::V3_4; - LOG(INFO) << "Meta version=" << static_cast(version); - iter->Next(); - break; - } - - if (!found) { - LOG(INFO) << "Meta version= Unknown"; - } + LOG(INFO) << "Meta version= Unknown"; } } {