diff --git a/src/clients/meta/MetaClient.cpp b/src/clients/meta/MetaClient.cpp index c860b12c61a..0bc1909181c 100644 --- a/src/clients/meta/MetaClient.cpp +++ b/src/clients/meta/MetaClient.cpp @@ -68,6 +68,9 @@ namespace meta { // 28800 secs is 8 hours. const uint32 kLicenseCheckPeriodInSecs = 28800; +// Update the hardware information every hour. +const uint32 kHwUploadPeriodInSecs = 3600; + Indexes buildIndexes(std::vector indexItemVec); MetaClient::MetaClient() : metadata_(new MetaData()) {} @@ -86,6 +89,7 @@ MetaClient::MetaClient(std::shared_ptr ioThreadPool FLAGS_enable_ssl || FLAGS_enable_meta_ssl); updateActive(); updateLeader(); + cpuCores_ = std::thread::hardware_concurrency(); bgThread_ = std::make_unique(); LOG(INFO) << "Create meta client to " << active_; LOG(INFO) << folly::sformat( @@ -142,6 +146,8 @@ bool MetaClient::waitForMetadReady(int count, int retryIntervalSecs) { // Repeatedly request and check license from meta size_t delayMS = FLAGS_heartbeat_interval_secs * 1000 + folly::Random::rand32(900); bgThread_->addDelayTask(delayMS, &MetaClient::licenseCheckThreadFunc, this); + bgThread_->addDelayTask(delayMS, &MetaClient::updateHwThreadFunc, this); + return ready_; } @@ -3062,6 +3068,12 @@ folly::Future> MetaClient::heartbeat() { req.host_ref() = options_.localHost_; req.role_ref() = options_.role_; req.git_info_sha_ref() = options_.gitInfoSHA_; + req.cpu_cores_ref() = cpuCores_; + + VLOG(2) << "Heartbeat to meta server, role: " + << apache::thrift::util::enumNameSafe(req.get_role()) + << " cpu cores: " << *req.get_cpu_cores(); + if (options_.role_ == cpp2::HostRole::STORAGE || options_.role_ == cpp2::HostRole::META_LISTENER || options_.role_ == cpp2::HostRole::STORAGE_LISTENER) { @@ -4885,5 +4897,12 @@ void MetaClient::licenseCheckThreadFunc() { LOG(INFO) << "[License] Scheduled license checking passed"; } +void MetaClient::updateHwThreadFunc() { + SCOPE_EXIT { + bgThread_->addDelayTask(kHwUploadPeriodInSecs * 1000, &MetaClient::updateHwThreadFunc, this); + }; + cpuCores_ = std::thread::hardware_concurrency(); +} + } // namespace meta } // namespace nebula diff --git a/src/clients/meta/MetaClient.h b/src/clients/meta/MetaClient.h index 47079742101..cc722a8e984 100644 --- a/src/clients/meta/MetaClient.h +++ b/src/clients/meta/MetaClient.h @@ -866,19 +866,20 @@ class MetaClient : public BaseMetaClient { return options_.localHost_.toString(); } + // TODO(Aiee) Deprecated when license manager is implemented // Requests license content StatusOr getLicenseFromMeta(); // Repeatedly request and validate the license void licenseCheckThreadFunc(); + // Repeatedly update hardware information and store it in the cache + void updateHwThreadFunc(); protected: // Return true if load succeeded. bool loadData(); bool loadCfg(); void heartBeatThreadFunc(); - // Periodically check if the meta service is enterprise version - void entMetaCheckThreadFunc(); bool registerCfg(); void updateGflagsValue(const cpp2::ConfigItem& item); @@ -1070,6 +1071,8 @@ class MetaClient : public BaseMetaClient { SessionMap sessionMap_; folly::F14FastSet> killedPlans_; std::atomic metadata_; + // The cpu cores of the machine which will be validated by license manager + int32_t cpuCores_{0}; }; } // namespace meta diff --git a/src/daemons/MetaDaemonInit.cpp b/src/daemons/MetaDaemonInit.cpp index c07561851ef..e655e90f4b2 100644 --- a/src/daemons/MetaDaemonInit.cpp +++ b/src/daemons/MetaDaemonInit.cpp @@ -209,6 +209,11 @@ std::unique_ptr initMetaKV( LOG(ERROR) << "Update meta from V3 to V3_4 failed " << ret; return nullptr; } + ret = nebula::meta::MetaVersionMan::updateMetaV3_4ToV3_5(engine); + if (!ret.ok()) { + LOG(ERROR) << "Update meta from V3_4 to V3_5 failed " << ret; + return nullptr; + } } else { auto v = nebula::value(version); LOG(INFO) << "Get meta version is " << static_cast(v); @@ -224,6 +229,12 @@ std::unique_ptr initMetaKV( LOG(ERROR) << "Update meta from V2 to V3_4 failed " << ret; return nullptr; } + } else if (v == nebula::meta::MetaVersion::V3_4) { + auto ret = nebula::meta::MetaVersionMan::updateMetaV3_4ToV3_5(engine); + if (!ret.ok()) { + LOG(ERROR) << "Update meta from V3_4 to V3_5 failed " << ret; + return nullptr; + } } } nebula::meta::MetaVersionMan::setMetaVersionToKV(engine, nebula::meta::MetaVersion::V3_4); diff --git a/src/interface/meta.thrift b/src/interface/meta.thrift index b8a7d0fd089..2916c8a0ba7 100644 --- a/src/interface/meta.thrift +++ b/src/interface/meta.thrift @@ -597,6 +597,8 @@ struct HBReq { 7: optional common.DirInfo dir, // version of binary 8: optional binary version, + // used in the enterprise version + 9: optional i32 cpu_cores = -1, } // service(agent/metad/storaged/graphd) info @@ -1564,6 +1566,9 @@ service MetaService { // Requests the enterprise license from meta GetLicenseResp getLicense(1: GetLicenseReq req); + // Sends request to the license manager to check the resource usage + GetLicenseResp checkLicenseManager(1: GetLicenseReq req); + // Interfaces for backup and restore CreateBackupResp createBackup(1: CreateBackupReq req); RestoreMetaResp restoreMeta(1: RestoreMetaReq req); diff --git a/src/meta/ActiveHostsMan.cpp b/src/meta/ActiveHostsMan.cpp index 417f07d379b..f6077556f9f 100644 --- a/src/meta/ActiveHostsMan.cpp +++ b/src/meta/ActiveHostsMan.cpp @@ -270,5 +270,31 @@ void LastUpdateTimeMan::update(kvstore::BatchHolder* batchHolder, const int64_t MetaKeyUtils::lastUpdateTimeVal(timeInMilliSec)); } +ErrorOr> ActiveHostsMan::getHostInfoByRole( + kvstore::KVStore* kv, cpp2::HostRole role) { + // Get all alive hosts + auto activeHostsRet = getActiveHosts(kv, 0, role); + if (!nebula::ok(activeHostsRet)) { + return nebula::error(activeHostsRet); + } + + std::vector hostInfos; + // If no active hosts, return empty + auto activeHosts = nebula::value(activeHostsRet); + if (activeHosts.empty()) { + return hostInfos; + } + hostInfos.reserve(activeHosts.size()); + + // Get host info by host address + for (const auto& host : activeHosts) { + auto hostInfoRet = getHostInfo(kv, host); + if (!nebula::ok(hostInfoRet)) { + return nebula::error(hostInfoRet); + } + hostInfos.emplace_back(nebula::value(hostInfoRet)); + } + return hostInfos; +} } // namespace meta } // namespace nebula diff --git a/src/meta/ActiveHostsMan.h b/src/meta/ActiveHostsMan.h index 0ab35ddcfdf..68edcfa01df 100644 --- a/src/meta/ActiveHostsMan.h +++ b/src/meta/ActiveHostsMan.h @@ -18,10 +18,23 @@ struct HostInfo { HostInfo() = default; explicit HostInfo(int64_t lastHBTimeInMilliSec) : lastHBTimeInMilliSec_(lastHBTimeInMilliSec) {} + // For compatibility we keep the interface without cpuNum HostInfo(int64_t lastHBTimeInMilliSec, cpp2::HostRole role, std::string gitInfoSha) : lastHBTimeInMilliSec_(lastHBTimeInMilliSec), role_(role), - gitInfoSha_(std::move(gitInfoSha)) {} + gitInfoSha_(std::move(gitInfoSha)) { + cpuNum_ = -1; + } + + // With cpuNum + HostInfo(int64_t lastHBTimeInMilliSec, + cpp2::HostRole role, + std::string gitInfoSha, + int32_t cpuNum) + : lastHBTimeInMilliSec_(lastHBTimeInMilliSec), + role_(role), + gitInfoSha_(std::move(gitInfoSha)), + cpuNum_(cpuNum) {} bool operator==(const HostInfo& that) const { return this->lastHBTimeInMilliSec_ == that.lastHBTimeInMilliSec_; @@ -34,6 +47,7 @@ struct HostInfo { int64_t lastHBTimeInMilliSec_ = 0; cpp2::HostRole role_{cpp2::HostRole::UNKNOWN}; std::string gitInfoSha_; + int32_t cpuNum_ = 0; static HostInfo decode(const folly::StringPiece& data) { if (data.size() == sizeof(int64_t)) { @@ -56,6 +70,7 @@ struct HostInfo { * sizeof(HostRole) hostRole * size_t length of gitInfoSha * string gitInfoSha + * int cpuNum * * @param info * @return @@ -74,6 +89,8 @@ struct HostInfo { if (!info.gitInfoSha_.empty()) { encode.append(info.gitInfoSha_.data(), len); } + + encode.append(reinterpret_cast(&info.cpuNum_), sizeof(int32_t)); return encode; } @@ -107,6 +124,51 @@ struct HostInfo { } info.gitInfoSha_ = std::string(data.data() + offset, len); + + offset += len; + if (offset + sizeof(int32_t) > data.size()) { + FLOG_FATAL("decode out of range, offset=%zu, actual=%zu", offset, data.size()); + } else { + info.cpuNum_ = *reinterpret_cast(data.data() + offset); + } + + return info; + } + + /** + * @brief Parse a serialized value to HostInfo. + * For compatibility, we keep the interface without cpuNum + * This method is only used when upgrading meta data from 3.4.0 to 3.5.0 + * + * @param data + * @return + */ + static HostInfo decodeV3_4(const folly::StringPiece& data) { + HostInfo info; + size_t offset = sizeof(int8_t); + + info.lastHBTimeInMilliSec_ = *reinterpret_cast(data.data() + offset); + offset += sizeof(int64_t); + + if (data.size() - offset < sizeof(cpp2::HostRole)) { + FLOG_FATAL("decode out of range, offset=%zu, actual=%zu", offset, data.size()); + } + info.role_ = *reinterpret_cast(data.data() + offset); + offset += sizeof(cpp2::HostRole); + + if (offset + sizeof(size_t) > data.size()) { + FLOG_FATAL("decode out of range, offset=%zu, actual=%zu", offset, data.size()); + } + size_t len = *reinterpret_cast(data.data() + offset); + offset += sizeof(size_t); + + if (offset + len > data.size()) { + FLOG_FATAL("decode out of range, offset=%zu, actual=%zu", offset, data.size()); + } + + info.gitInfoSha_ = std::string(data.data() + offset, len); + // The cpuNum field is not exist in 3.4.0, set it to -1 and wait for update + info.cpuNum_ = -1; return info; } }; @@ -206,6 +268,16 @@ class ActiveHostsMan final { static ErrorOr getHostInfo(kvstore::KVStore* kv, const HostAddr& host); + /** + * @brief Get all alive host info by given host role + * + * @param kv From where to get + * @param hostRole + * @return + */ + static ErrorOr> getHostInfoByRole( + kvstore::KVStore* kv, cpp2::HostRole role); + protected: ActiveHostsMan() = default; }; diff --git a/src/meta/MetaVersionMan.cpp b/src/meta/MetaVersionMan.cpp index 6d850c499cd..f137800110c 100644 --- a/src/meta/MetaVersionMan.cpp +++ b/src/meta/MetaVersionMan.cpp @@ -47,18 +47,8 @@ Status MetaVersionMan::updateMetaV2ToV3_4(kvstore::KVEngine* engine) { CHECK_NOTNULL(engine); auto snapshot = folly::sformat("META_UPGRADE_SNAPSHOT_{}", MetaKeyUtils::genTimestampStr()); - std::string path = folly::sformat("{}/checkpoints/{}", engine->getDataRoot(), snapshot); - if (!fs::FileUtils::exist(path) && !fs::FileUtils::makeDir(path)) { - LOG(INFO) << "Make checkpoint dir: " << path << " failed"; - return Status::Error("Create snapshot file failed"); - } - - std::string dataPath = folly::sformat("{}/data", path); - auto code = engine->createCheckpoint(dataPath); - if (code != nebula::cpp2::ErrorCode::SUCCEEDED) { - LOG(INFO) << "Create snapshot failed: " << snapshot; - return Status::Error("Create snapshot failed"); - } + // create snapshot + NG_RETURN_IF_ERROR(createSnapshot(engine, snapshot)); auto status = doUpgradeV2ToV3(engine); if (!status.ok()) { @@ -67,17 +57,14 @@ Status MetaVersionMan::updateMetaV2ToV3_4(kvstore::KVEngine* engine) { } status = doUpgradeV3ToV3_4(engine); - if (!status.ok()) { // rollback by snapshot return status; } // delete snapshot file - auto checkpointPath = folly::sformat("{}/checkpoints/{}", engine->getDataRoot(), snapshot); - if (fs::FileUtils::exist(checkpointPath) && !fs::FileUtils::remove(checkpointPath.data(), true)) { - LOG(INFO) << "Delete snapshot: " << snapshot << " failed, You need to delete it manually"; - } + NG_RETURN_IF_ERROR(deleteSnapshot(engine, snapshot)); + return Status::OK(); } @@ -85,18 +72,8 @@ Status MetaVersionMan::updateMetaV3ToV3_4(kvstore::KVEngine* engine) { CHECK_NOTNULL(engine); auto snapshot = folly::sformat("META_UPGRADE_SNAPSHOT_{}", MetaKeyUtils::genTimestampStr()); - std::string path = folly::sformat("{}/checkpoints/{}", engine->getDataRoot(), snapshot); - if (!fs::FileUtils::exist(path) && !fs::FileUtils::makeDir(path)) { - LOG(INFO) << "Make checkpoint dir: " << path << " failed"; - return Status::Error("Create snapshot file failed"); - } - - std::string dataPath = folly::sformat("{}/data", path); - auto code = engine->createCheckpoint(dataPath); - if (code != nebula::cpp2::ErrorCode::SUCCEEDED) { - LOG(INFO) << "Create snapshot failed: " << snapshot; - return Status::Error("Create snapshot failed"); - } + // create snapshot + NG_RETURN_IF_ERROR(createSnapshot(engine, snapshot)); auto status = doUpgradeV3ToV3_4(engine); if (!status.ok()) { @@ -105,10 +82,29 @@ Status MetaVersionMan::updateMetaV3ToV3_4(kvstore::KVEngine* engine) { } // delete snapshot file - auto checkpointPath = folly::sformat("{}/checkpoints/{}", engine->getDataRoot(), snapshot); - if (fs::FileUtils::exist(checkpointPath) && !fs::FileUtils::remove(checkpointPath.data(), true)) { - LOG(INFO) << "Delete snapshot: " << snapshot << " failed, You need to delete it manually"; + NG_RETURN_IF_ERROR(deleteSnapshot(engine, snapshot)); + + return Status::OK(); +} + +Status MetaVersionMan::updateMetaV3_4ToV3_5(kvstore::KVEngine* engine) { + LOG(INFO) << "Upgrading meta data from V3_4 to V3_5..."; + + CHECK_NOTNULL(engine); + auto snapshot = folly::sformat("META_UPGRADE_SNAPSHOT_{}", MetaKeyUtils::genTimestampStr()); + + // create snapshot + NG_RETURN_IF_ERROR(createSnapshot(engine, snapshot)); + + auto status = doUpgradeV3_4ToV3_5(engine); + if (!status.ok()) { + // rollback by snapshot + return status; } + + // delete snapshot file + NG_RETURN_IF_ERROR(deleteSnapshot(engine, snapshot)); + LOG(INFO) << "Successfully upgraded meta data from V3_4 to V3_5"; return Status::OK(); } @@ -224,5 +220,69 @@ Status MetaVersionMan::doUpgradeV3ToV3_4(kvstore::KVEngine* engine) { } } +Status MetaVersionMan::doUpgradeV3_4ToV3_5(kvstore::KVEngine* engine) { + std::unique_ptr hostInfoIter; + auto code = engine->prefix(MetaKeyUtils::hostPrefix(), &hostInfoIter); + if (code != nebula::cpp2::ErrorCode::SUCCEEDED) { + LOG(ERROR) << "Upgrade meta failed, get host info failed"; + return Status::Error("Update meta failed, get host info failed"); + } + + // read all host info + std::vector hostInfoList; + while (hostInfoIter->valid()) { + hostInfoList.push_back(hostInfoIter->key().toString()); + hostInfoIter->next(); + } + + // encode all host info with new fields + std::vector newHostInfoList; + while (hostInfoIter->valid()) { + auto key = hostInfoIter->key().toString(); + auto val = hostInfoIter->val().toString(); + auto hostInfo = HostInfo::decodeV3_4(val); + auto newVal = HostInfo::encodeV2(hostInfo); + // write new host info back to kvstore + newHostInfoList.emplace_back(std::move(key), std::move(newVal)); + } + + // write new host info back to kvstore + code = engine->multiPut(std::move(newHostInfoList)); + if (code != nebula::cpp2::ErrorCode::SUCCEEDED) { + LOG(ERROR) << "Upgrade meta failed, write new host info failed"; + return Status::Error("Upgrade meta failed, write new host info failed"); + } + + if (!setMetaVersionToKV(engine, MetaVersion::V3_5)) { + return Status::Error("Persist meta version failed"); + } else { + return Status::OK(); + } +} + +Status MetaVersionMan::createSnapshot(kvstore::KVEngine* engine, const std::string& snapshot) { + std::string path = folly::sformat("{}/checkpoints/{}", engine->getDataRoot(), snapshot); + if (!fs::FileUtils::exist(path) && !fs::FileUtils::makeDir(path)) { + LOG(INFO) << "Make checkpoint dir: " << path << " failed"; + return Status::Error("Create snapshot file failed"); + } + + std::string dataPath = folly::sformat("{}/data", path); + auto code = engine->createCheckpoint(dataPath); + if (code != nebula::cpp2::ErrorCode::SUCCEEDED) { + LOG(INFO) << "Create snapshot failed: " << snapshot; + return Status::Error("Create snapshot failed"); + } + return Status::OK(); +} + +Status MetaVersionMan::deleteSnapshot(kvstore::KVEngine* engine, const std::string& snapshot) { + auto checkpointPath = folly::sformat("{}/checkpoints/{}", engine->getDataRoot(), snapshot); + if (fs::FileUtils::exist(checkpointPath) && !fs::FileUtils::remove(checkpointPath.data(), true)) { + LOG(INFO) << "Delete snapshot: " << snapshot << " failed, You need to delete it manually"; + } + return Status::OK(); +} + } // namespace meta } // namespace nebula diff --git a/src/meta/MetaVersionMan.h b/src/meta/MetaVersionMan.h index 9d39508cf56..aa314f94c4c 100644 --- a/src/meta/MetaVersionMan.h +++ b/src/meta/MetaVersionMan.h @@ -21,6 +21,8 @@ enum class MetaVersion { V2 = 2, V3 = 3, V3_4 = 4, + // Add cpuNum field to HostInfo + V3_5 = 5, }; /** @@ -44,10 +46,19 @@ class MetaVersionMan final { static Status updateMetaV3ToV3_4(kvstore::KVEngine* engine); + // Read host info from the kvstore and add cpuNum field to it + static Status updateMetaV3_4ToV3_5(kvstore::KVEngine* engine); + private: static Status doUpgradeV3ToV3_4(kvstore::KVEngine* engine); static Status doUpgradeV2ToV3(kvstore::KVEngine* engine); + + static Status doUpgradeV3_4ToV3_5(kvstore::KVEngine* engine); + + static Status createSnapshot(kvstore::KVEngine* engine, const std::string& snapshot); + + static Status deleteSnapshot(kvstore::KVEngine* engine, const std::string& snapshot); }; } // namespace meta diff --git a/src/meta/processors/admin/HBProcessor.cpp b/src/meta/processors/admin/HBProcessor.cpp index 5dfb9098546..61aea837747 100644 --- a/src/meta/processors/admin/HBProcessor.cpp +++ b/src/meta/processors/admin/HBProcessor.cpp @@ -83,7 +83,8 @@ void HBProcessor::process(const cpp2::HBReq& req) { } // update host info - HostInfo info(time::WallClock::fastNowInMilliSec(), role, req.get_git_info_sha()); + HostInfo info( + time::WallClock::fastNowInMilliSec(), role, req.get_git_info_sha(), *req.get_cpu_cores()); if (req.leader_partIds_ref().has_value()) { ret = ActiveHostsMan::updateHostInfo(kvstore_, host, info, data, &*req.leader_partIds_ref()); } else { diff --git a/src/meta/test/ActiveHostsManTest.cpp b/src/meta/test/ActiveHostsManTest.cpp index 76508243e7a..5caabd0889b 100644 --- a/src/meta/test/ActiveHostsManTest.cpp +++ b/src/meta/test/ActiveHostsManTest.cpp @@ -22,6 +22,7 @@ TEST(ActiveHostsManTest, EncodeDecodeHostInfoV2) { auto now = time::WallClock::fastNowInMilliSec(); auto role = cpp2::HostRole::STORAGE; auto strGitInfoSHA = gitInfoSha(); + auto cpuCoreNum = 64; { HostInfo hostInfo(now, role, strGitInfoSHA); auto encodeHostInfo = HostInfo::encodeV2(hostInfo); @@ -41,11 +42,14 @@ TEST(ActiveHostsManTest, EncodeDecodeHostInfoV2) { ASSERT_EQ(hostInfo.gitInfoSha_, decodeHostInfo.gitInfoSha_); } { - HostInfo hostInfo(now, role, strGitInfoSHA); + HostInfo hostInfo(now, role, strGitInfoSHA, cpuCoreNum); auto encodeHostInfo = HostInfo::encodeV2(hostInfo); auto decodeHostInfo = HostInfo::decode(encodeHostInfo); ASSERT_EQ(hostInfo.lastHBTimeInMilliSec_, decodeHostInfo.lastHBTimeInMilliSec_); + ASSERT_EQ(hostInfo.role_, decodeHostInfo.role_); + ASSERT_EQ(hostInfo.gitInfoSha_, decodeHostInfo.gitInfoSha_); + ASSERT_EQ(hostInfo.cpuNum_, decodeHostInfo.cpuNum_); } } @@ -199,6 +203,60 @@ TEST(ActiveHostsManTest, LeaderTest) { ASSERT_EQ(1, nebula::value(hostsRet).size()); } +TEST(ActiveHostsManTest, GetHostInfoByRoleTest) { + fs::TempDir rootPath("/tmp/ActiveHostsManTest.XXXXXX"); + FLAGS_heartbeat_interval_secs = 1; + std::unique_ptr kv(MockCluster::initMetaKV(rootPath.path())); + + std::vector data; + // storage host key + data.emplace_back(nebula::MetaKeyUtils::machineKey("0", 0), ""); + data.emplace_back(nebula::MetaKeyUtils::machineKey("0", 1), ""); + + // graph host key + data.emplace_back(nebula::MetaKeyUtils::machineKey("0", 2), ""); + data.emplace_back(nebula::MetaKeyUtils::machineKey("0", 3), ""); + data.emplace_back(nebula::MetaKeyUtils::machineKey("0", 4), ""); + folly::Baton baton; + kv->asyncMultiPut(kDefaultSpaceId, kDefaultPartId, std::move(data), [&](auto) { baton.post(); }); + baton.wait(); + + std::vector times; + auto now = time::WallClock::fastNowInMilliSec(); + + // storage host info + HostInfo storageInfo(now, cpp2::HostRole::STORAGE, gitInfoSha(), 32); + ActiveHostsMan::updateHostInfo(kv.get(), HostAddr("0", 0), storageInfo, times); + ActiveHostsMan::updateHostInfo(kv.get(), HostAddr("0", 1), storageInfo, times); + + // graph host info + HostInfo graphInfo(now, cpp2::HostRole::GRAPH, gitInfoSha(), 64); + ActiveHostsMan::updateHostInfo(kv.get(), HostAddr("0", 2), graphInfo, times); + ActiveHostsMan::updateHostInfo(kv.get(), HostAddr("0", 3), graphInfo, times); + ActiveHostsMan::updateHostInfo(kv.get(), HostAddr("0", 4), graphInfo, times); + TestUtils::doPut(kv.get(), times); + + // check storage hosts info + auto res = ActiveHostsMan::getHostInfoByRole(kv.get(), cpp2::HostRole::STORAGE); + ASSERT_TRUE(nebula::ok(res)); + ASSERT_EQ(2, nebula::value(res).size()); + auto storageInfos = nebula::value(res); + + for (auto& info : storageInfos) { + ASSERT_EQ(storageInfo, info); + } + + // check graph hosts info + res = ActiveHostsMan::getHostInfoByRole(kv.get(), cpp2::HostRole::GRAPH); + ASSERT_TRUE(nebula::ok(res)); + ASSERT_EQ(3, nebula::value(res).size()); + auto graphInfos = nebula::value(res); + + for (auto& info : graphInfos) { + ASSERT_EQ(graphInfo, info); + } +} + } // namespace meta } // namespace nebula diff --git a/src/meta/test/AgentHBProcessorTest.cpp b/src/meta/test/AgentHBProcessorTest.cpp index 52290b6b48e..c484c901f39 100644 --- a/src/meta/test/AgentHBProcessorTest.cpp +++ b/src/meta/test/AgentHBProcessorTest.cpp @@ -37,6 +37,7 @@ TEST(AgentHBProcessorTest, AgentHBTest) { req.host_ref() = HostAddr(std::to_string(i), i); req.cluster_id_ref() = kClusterId; req.role_ref() = cpp2::HostRole::STORAGE; + req.cpu_cores_ref() = 1; nebula::cpp2::DirInfo dir; dir.root_ref() = "/tmp/nebula"; std::vector ds; diff --git a/src/meta/test/HBProcessorTest.cpp b/src/meta/test/HBProcessorTest.cpp index 7bd9156c97f..edbba7b6c1e 100644 --- a/src/meta/test/HBProcessorTest.cpp +++ b/src/meta/test/HBProcessorTest.cpp @@ -37,6 +37,7 @@ TEST(HBProcessorTest, HBTest) { req.host_ref() = HostAddr(std::to_string(i), i); req.cluster_id_ref() = kClusterId; req.role_ref() = cpp2::HostRole::STORAGE; + req.cpu_cores_ref() = 1; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); processor->process(req); @@ -57,6 +58,7 @@ TEST(HBProcessorTest, HBTest) { req.host_ref() = HostAddr(std::to_string(11), 11); req.cluster_id_ref() = 1; req.role_ref() = cpp2::HostRole::STORAGE; + req.cpu_cores_ref() = 1; auto* processor = HBProcessor::instance(kv.get(), nullptr); auto f = processor->getFuture(); processor->process(req); diff --git a/src/meta/test/ProcessorTest.cpp b/src/meta/test/ProcessorTest.cpp index 9e9940eb492..b68483a2a45 100644 --- a/src/meta/test/ProcessorTest.cpp +++ b/src/meta/test/ProcessorTest.cpp @@ -330,6 +330,7 @@ TEST(ProcessorTest, SpaceTest) { req.role_ref() = cpp2::HostRole::STORAGE; req.host_ref() = HostAddr(std::to_string(i), i); req.cluster_id_ref() = kClusterId; + req.cpu_cores_ref() = 1; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); processor->process(req); @@ -3099,6 +3100,7 @@ TEST(ProcessorTest, HostsTest) { cpp2::HBReq req; req.host_ref() = HostAddr("127.0.0.1", i); req.cluster_id_ref() = kClusterId; + req.cpu_cores_ref() = 1; req.role_ref() = cpp2::HostRole::STORAGE; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); @@ -3139,6 +3141,7 @@ TEST(ProcessorTest, HostsTest) { cpp2::HBReq req; req.host_ref() = HostAddr("127.0.0.1", i); req.cluster_id_ref() = kClusterId; + req.cpu_cores_ref() = 1; req.role_ref() = cpp2::HostRole::STORAGE; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); @@ -3277,6 +3280,7 @@ TEST(ProcessorTest, HostsTest) { cpp2::HBReq req; req.host_ref() = HostAddr("127.0.0.1", i); req.cluster_id_ref() = kClusterId; + req.cpu_cores_ref() = 1; req.role_ref() = cpp2::HostRole::STORAGE; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); @@ -3296,6 +3300,7 @@ TEST(ProcessorTest, AddHostsError) { cpp2::HBReq req; req.host_ref() = HostAddr("127.0.0.1", 8987); req.cluster_id_ref() = kClusterId; + req.cpu_cores_ref() = 1; req.role_ref() = cpp2::HostRole::GRAPH; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); @@ -3307,6 +3312,7 @@ TEST(ProcessorTest, AddHostsError) { cpp2::HBReq req; req.host_ref() = HostAddr("127.0.0.1", 8988); req.cluster_id_ref() = kClusterId; + req.cpu_cores_ref() = 1; req.role_ref() = cpp2::HostRole::STORAGE_LISTENER; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); @@ -3375,6 +3381,7 @@ TEST(ProcessorTest, AddHostsIntoNewZoneTest) { cpp2::HBReq req; req.host_ref() = HostAddr("127.0.0.1", i); req.cluster_id_ref() = kClusterId; + req.cpu_cores_ref() = 1; req.role_ref() = cpp2::HostRole::STORAGE; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); @@ -3428,6 +3435,7 @@ TEST(ProcessorTest, AddHostsIntoNewZoneTest) { cpp2::HBReq req; req.host_ref() = HostAddr("127.0.0.1", i); req.cluster_id_ref() = kClusterId; + req.cpu_cores_ref() = 1; req.role_ref() = cpp2::HostRole::STORAGE; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); @@ -3476,6 +3484,7 @@ TEST(ProcessorTest, AddHostsIntoZoneTest) { cpp2::HBReq req; req.host_ref() = HostAddr("127.0.0.1", i); req.cluster_id_ref() = kClusterId; + req.cpu_cores_ref() = 1; req.role_ref() = cpp2::HostRole::STORAGE; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); @@ -3632,6 +3641,7 @@ TEST(ProcessorTest, AddHostsIntoZoneTest) { cpp2::HBReq req; req.host_ref() = HostAddr("127.0.0.1", i); req.cluster_id_ref() = kClusterId; + req.cpu_cores_ref() = 1; req.role_ref() = cpp2::HostRole::STORAGE; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); @@ -3652,6 +3662,7 @@ TEST(ProcessorTest, DropHostsTest) { cpp2::HBReq req; req.host_ref() = HostAddr("127.0.0.1", i); req.cluster_id_ref() = kClusterId; + req.cpu_cores_ref() = 1; req.role_ref() = cpp2::HostRole::STORAGE; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); @@ -3682,6 +3693,7 @@ TEST(ProcessorTest, DropHostsTest) { cpp2::HBReq req; req.host_ref() = HostAddr("127.0.0.1", i); req.cluster_id_ref() = kClusterId; + req.cpu_cores_ref() = 1; req.role_ref() = cpp2::HostRole::STORAGE; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); @@ -4047,6 +4059,7 @@ TEST(ProcessorTest, RenameZoneTest) { cpp2::HBReq req; req.host_ref() = HostAddr("127.0.0.1", i); req.cluster_id_ref() = kClusterId; + req.cpu_cores_ref() = 1; req.role_ref() = cpp2::HostRole::STORAGE; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); @@ -4168,6 +4181,7 @@ TEST(ProcessorTest, MergeZoneTest) { cpp2::HBReq req; req.host_ref() = HostAddr("127.0.0.1", i); req.cluster_id_ref() = kClusterId; + req.cpu_cores_ref() = 1; req.role_ref() = cpp2::HostRole::STORAGE; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); @@ -4195,6 +4209,7 @@ TEST(ProcessorTest, MergeZoneTest) { req.role_ref() = cpp2::HostRole::STORAGE; req.host_ref() = HostAddr("127.0.0.1", i); req.cluster_id_ref() = kClusterId; + req.cpu_cores_ref() = 1; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); processor->process(req); @@ -4332,6 +4347,7 @@ TEST(ProcessorTest, MergeZoneTest) { req.role_ref() = cpp2::HostRole::STORAGE; req.host_ref() = HostAddr("127.0.0.1", i); req.cluster_id_ref() = kClusterId; + req.cpu_cores_ref() = 1; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); processor->process(req); @@ -4893,6 +4909,7 @@ TEST(ProcessorTest, DropZoneTest) { req.role_ref() = cpp2::HostRole::STORAGE; req.host_ref() = HostAddr("127.0.0.1", i); req.cluster_id_ref() = kClusterId; + req.cpu_cores_ref() = 1; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); processor->process(req); diff --git a/src/meta/test/VerifyClientVersionTest.cpp b/src/meta/test/VerifyClientVersionTest.cpp index 7a36717184e..507ab3a185d 100644 --- a/src/meta/test/VerifyClientVersionTest.cpp +++ b/src/meta/test/VerifyClientVersionTest.cpp @@ -48,6 +48,7 @@ TEST(VerifyClientVersionTest, VersionTest) { req.role_ref() = cpp2::HostRole::GRAPH; req.host_ref() = HostAddr(std::to_string(i), i); req.cluster_id_ref() = kClusterId; + req.cpu_cores_ref() = 1; auto* processor = HBProcessor::instance(kv.get(), nullptr, kClusterId); auto f = processor->getFuture(); processor->process(req);