diff --git a/src/meta/processors/BaseProcessor-inl.h b/src/meta/processors/BaseProcessor-inl.h index 00769b0f377..2206d95f921 100644 --- a/src/meta/processors/BaseProcessor-inl.h +++ b/src/meta/processors/BaseProcessor-inl.h @@ -262,6 +262,15 @@ nebula::cpp2::ErrorCode BaseProcessor::machineExist(const std::string& mac return nebula::error(ret); } +template +nebula::cpp2::ErrorCode BaseProcessor::hostExist(const std::string& hostKey) { + auto ret = doGet(hostKey); + if (nebula::ok(ret)) { + return nebula::cpp2::ErrorCode::SUCCEEDED; + } + return nebula::error(ret); +} + template nebula::cpp2::ErrorCode BaseProcessor::includeByZone(const std::vector& hosts) { const auto& prefix = MetaKeyUtils::zonePrefix(); diff --git a/src/meta/processors/BaseProcessor.h b/src/meta/processors/BaseProcessor.h index c4f9c83d91e..738643ddf60 100644 --- a/src/meta/processors/BaseProcessor.h +++ b/src/meta/processors/BaseProcessor.h @@ -193,6 +193,8 @@ class BaseProcessor { * */ nebula::cpp2::ErrorCode machineExist(const std::string& machineKey); + nebula::cpp2::ErrorCode hostExist(const std::string& hostKey); + /** * Check hosts has been include by zone or not. * */ diff --git a/src/meta/processors/admin/HBProcessor.cpp b/src/meta/processors/admin/HBProcessor.cpp index c86777b9d96..84c0b0c3f64 100644 --- a/src/meta/processors/admin/HBProcessor.cpp +++ b/src/meta/processors/admin/HBProcessor.cpp @@ -61,7 +61,7 @@ void HBProcessor::process(const cpp2::HBReq& req) { for (const auto& [spaceId, partDiskMap] : *req.get_disk_parts()) { for (const auto& [path, partList] : partDiskMap) { auto partListVal = MetaKeyUtils::diskPartsVal(partList); - std::string key = MetaKeyUtils::diskPartsKey(host, spaceId, path); + auto key = MetaKeyUtils::diskPartsKey(host, spaceId, path); std::vector data; data.emplace_back(key, partListVal); // doPut() not work, will trigger the asan: use heap memory which is free diff --git a/src/meta/processors/parts/CreateSpaceProcessor.cpp b/src/meta/processors/parts/CreateSpaceProcessor.cpp index 8da74f9e0a3..e73667405ed 100644 --- a/src/meta/processors/parts/CreateSpaceProcessor.cpp +++ b/src/meta/processors/parts/CreateSpaceProcessor.cpp @@ -9,6 +9,7 @@ DEFINE_int32(default_parts_num, 100, "The default number of parts when a space is created"); DEFINE_int32(default_replica_factor, 1, "The default replica factor when a space is created"); +DECLARE_uint32(expired_time_factor); namespace nebula { namespace meta { @@ -129,19 +130,27 @@ void CreateSpaceProcessor::process(const cpp2::CreateSpaceReq& req) { zoneIter->next(); } - int32_t zoneNum = zones.size(); - if (replicaFactor > zoneNum) { - LOG(ERROR) << "Replication number should less than or equal to zone number."; - handleErrorCode(nebula::cpp2::ErrorCode::E_INVALID_PARM); - onFinished(); - return; - } - properties.zone_names_ref() = zones; } else { zones = properties.get_zone_names(); } + auto it = std::unique(zones.begin(), zones.end()); + if (it != zones.end()) { + LOG(ERROR) << "Zones have duplicated."; + handleErrorCode(nebula::cpp2::ErrorCode::E_INVALID_PARM); + onFinished(); + return; + } + + int32_t zoneNum = zones.size(); + if (replicaFactor > zoneNum) { + LOG(ERROR) << "Replication number should less than or equal to zone number."; + handleErrorCode(nebula::cpp2::ErrorCode::E_INVALID_PARM); + onFinished(); + return; + } + data.emplace_back(MetaKeyUtils::indexSpaceKey(spaceName), std::string(reinterpret_cast(&spaceId), sizeof(spaceId))); data.emplace_back(MetaKeyUtils::spaceKey(spaceId), MetaKeyUtils::spaceVal(properties)); @@ -165,28 +174,6 @@ void CreateSpaceProcessor::process(const cpp2::CreateSpaceReq& req) { return; } - int32_t zoneNum = zones.size(); - if (replicaFactor > zoneNum) { - LOG(ERROR) << "Replication number should less than or equal to zone number."; - LOG(ERROR) << "Replication number: " << replicaFactor << ", Zones size: " << zones.size(); - handleErrorCode(nebula::cpp2::ErrorCode::E_INVALID_PARM); - onFinished(); - return; - } - - auto hostLoadingRet = getHostLoading(); - if (!nebula::ok(hostLoadingRet)) { - LOG(ERROR) << "Get host loading failed."; - auto retCode = nebula::error(hostLoadingRet); - if (retCode != nebula::cpp2::ErrorCode::E_LEADER_CHANGED) { - retCode = nebula::cpp2::ErrorCode::E_INVALID_PARM; - } - handleErrorCode(retCode); - onFinished(); - return; - } - - hostLoading_ = std::move(nebula::value(hostLoadingRet)); std::unordered_map zoneHosts; for (auto& zone : zones) { auto zoneKey = MetaKeyUtils::zoneKey(zone); @@ -200,14 +187,23 @@ void CreateSpaceProcessor::process(const cpp2::CreateSpaceReq& req) { break; } + auto now = time::WallClock::fastNowInMilliSec(); auto hosts = MetaKeyUtils::parseZoneHosts(std::move(nebula::value(zoneValueRet))); for (auto& host : hosts) { - auto hostIter = hostLoading_.find(host); - if (hostIter == hostLoading_.end()) { - hostLoading_[host] = 0; - zoneLoading_[zone] += 0; + auto key = MetaKeyUtils::hostKey(host.host, host.port); + auto ret = doGet(key); + HostInfo info = HostInfo::decode(nebula::value(ret)); + if (now - info.lastHBTimeInMilliSec_ < + FLAGS_heartbeat_interval_secs * FLAGS_expired_time_factor * 1000) { + auto hostIter = hostLoading_.find(host); + if (hostIter == hostLoading_.end()) { + hostLoading_[host] = 0; + zoneLoading_[zone] += 0; + } else { + zoneLoading_[zone] += hostIter->second; + } } else { - zoneLoading_[zone] += hostIter->second; + LOG(WARNING) << "Host " << host << " expired"; } } zoneHosts[zone] = std::move(hosts); @@ -248,7 +244,7 @@ void CreateSpaceProcessor::process(const cpp2::CreateSpaceReq& req) { ss << host << ", "; } - VLOG(3) << "Space " << spaceId << " part " << partId << " hosts " << ss.str(); + LOG(INFO) << "Space " << spaceId << " part " << partId << " hosts " << ss.str(); data.emplace_back(MetaKeyUtils::partKey(spaceId, partId), MetaKeyUtils::partVal(partHosts)); } @@ -264,28 +260,6 @@ void CreateSpaceProcessor::process(const cpp2::CreateSpaceReq& req) { LOG(INFO) << "Create space " << spaceName; } -ErrorOr> -CreateSpaceProcessor::getHostLoading() { - const auto& prefix = MetaKeyUtils::partPrefix(); - auto iterRet = doPrefix(prefix); - - if (!nebula::ok(iterRet)) { - LOG(ERROR) << "Prefix Parts Failed"; - return nebula::error(iterRet); - } - - std::unordered_map result; - auto iter = nebula::value(iterRet).get(); - while (iter->valid()) { - auto hosts = MetaKeyUtils::parsePartVal(iter->val()); - for (auto& host : hosts) { - result[host]++; - } - iter->next(); - } - return result; -} - StatusOr CreateSpaceProcessor::pickHostsWithZone( const std::vector& zones, const std::unordered_map& zoneHosts) { diff --git a/src/meta/processors/parts/CreateSpaceProcessor.h b/src/meta/processors/parts/CreateSpaceProcessor.h index 570ab11cd74..67768039dbb 100644 --- a/src/meta/processors/parts/CreateSpaceProcessor.h +++ b/src/meta/processors/parts/CreateSpaceProcessor.h @@ -29,9 +29,6 @@ class CreateSpaceProcessor : public BaseProcessor { StatusOr pickHostsWithZone(const std::vector& zones, const std::unordered_map& zoneHosts); - // Get all host's part loading - ErrorOr> getHostLoading(); - // Get the zones with the least load StatusOr> pickLightLoadZones(int32_t replicaFactor); diff --git a/src/meta/processors/parts/ListHostsProcessor.cpp b/src/meta/processors/parts/ListHostsProcessor.cpp index 3b29a04d069..e7e17989ca8 100644 --- a/src/meta/processors/parts/ListHostsProcessor.cpp +++ b/src/meta/processors/parts/ListHostsProcessor.cpp @@ -121,6 +121,7 @@ nebula::cpp2::ErrorCode ListHostsProcessor::allHostsWithStatus(cpp2::HostRole ro auto now = time::WallClock::fastNowInMilliSec(); std::vector removeHostsKey; + std::vector heartbeatHosts; for (auto iter = nebula::value(ret).get(); iter->valid(); iter->next()) { HostInfo info = HostInfo::decode(iter->val()); if (info.role_ != role) { @@ -129,6 +130,7 @@ nebula::cpp2::ErrorCode ListHostsProcessor::allHostsWithStatus(cpp2::HostRole ro cpp2::HostItem item; auto host = MetaKeyUtils::parseHostKey(iter->key()); + heartbeatHosts.emplace_back(host); item.hostAddr_ref() = std::move(host); item.role_ref() = info.role_; @@ -160,6 +162,28 @@ nebula::cpp2::ErrorCode ListHostsProcessor::allHostsWithStatus(cpp2::HostRole ro } } + if (role == cpp2::HostRole::STORAGE) { + const auto& machinePrefix = MetaKeyUtils::machinePrefix(); + auto machineRet = doPrefix(machinePrefix); + if (!nebula::ok(machineRet)) { + auto retCode = nebula::error(machineRet); + LOG(ERROR) << "List Machines Failed, error: " << apache::thrift::util::enumNameSafe(retCode); + return retCode; + } + + for (auto iter = nebula::value(machineRet).get(); iter->valid(); iter->next()) { + auto host = MetaKeyUtils::parseMachineKey(iter->key()); + auto it = std::find(heartbeatHosts.begin(), heartbeatHosts.end(), host); + if (it == heartbeatHosts.end()) { + cpp2::HostItem item; + item.hostAddr_ref() = std::move(host); + item.role_ref() = cpp2::HostRole::STORAGE; + item.status_ref() = cpp2::HostStatus::OFFLINE; + hostItems_.emplace_back(std::move(item)); + } + } + } + removeExpiredHosts(std::move(removeHostsKey)); return nebula::cpp2::ErrorCode::SUCCEEDED; } diff --git a/src/meta/processors/zone/AddHostsIntoZoneProcessor.cpp b/src/meta/processors/zone/AddHostsIntoZoneProcessor.cpp index 5ad66ab7f30..93480117cad 100644 --- a/src/meta/processors/zone/AddHostsIntoZoneProcessor.cpp +++ b/src/meta/processors/zone/AddHostsIntoZoneProcessor.cpp @@ -5,8 +5,6 @@ #include "meta/processors/zone/AddHostsIntoZoneProcessor.h" -DECLARE_int32(heartbeat_interval_secs); - namespace nebula { namespace meta { @@ -98,11 +96,6 @@ void AddHostsIntoZoneProcessor::process(const cpp2::AddHostsIntoZoneReq& req) { zoneHosts.insert(zoneHosts.end(), hosts.begin(), hosts.end()); data.emplace_back(std::move(zoneKey), MetaKeyUtils::zoneVal(std::move(zoneHosts))); - HostInfo info(0, cpp2::HostRole::STORAGE, ""); - for (auto& host : hosts) { - data.emplace_back(MetaKeyUtils::hostKey(host.host, host.port), HostInfo::encodeV2(info)); - } - LOG(INFO) << "Add Hosts Into Zone " << zoneName; doSyncPutAndUpdate(std::move(data)); } diff --git a/src/meta/processors/zone/AddHostsProcessor.cpp b/src/meta/processors/zone/AddHostsProcessor.cpp index a4010ce0362..dc4096c7322 100644 --- a/src/meta/processors/zone/AddHostsProcessor.cpp +++ b/src/meta/processors/zone/AddHostsProcessor.cpp @@ -7,6 +7,9 @@ #include "version/Version.h" +DECLARE_uint32(expired_time_factor); +DECLARE_int32(removed_threshold_sec); + namespace nebula { namespace meta { @@ -62,10 +65,6 @@ void AddHostsProcessor::process(const cpp2::AddHostsReq& req) { return; } - HostInfo info(0, cpp2::HostRole::STORAGE, ""); - for (auto& host : hosts) { - data.emplace_back(MetaKeyUtils::hostKey(host.host, host.port), HostInfo::encodeV2(info)); - } doPut(std::move(data)); } diff --git a/src/meta/processors/zone/DropHostsProcessor.cpp b/src/meta/processors/zone/DropHostsProcessor.cpp index 81e74c9f70b..f9138b7061e 100644 --- a/src/meta/processors/zone/DropHostsProcessor.cpp +++ b/src/meta/processors/zone/DropHostsProcessor.cpp @@ -127,11 +127,20 @@ void DropHostsProcessor::process(const cpp2::DropHostsReq& req) { auto machineKey = MetaKeyUtils::machineKey(host.host, host.port); auto ret = machineExist(machineKey); if (ret != nebula::cpp2::ErrorCode::SUCCEEDED) { - LOG(ERROR) << "The host " << host << " not existed!"; + LOG(ERROR) << "The machine " << host << " not existed!"; code = nebula::cpp2::ErrorCode::E_NO_HOSTS; break; } holder->remove(std::move(machineKey)); + + auto hostKey = MetaKeyUtils::hostKey(host.host, host.port); + ret = hostExist(hostKey); + if (ret != nebula::cpp2::ErrorCode::SUCCEEDED) { + LOG(ERROR) << "The host " << host << " not existed!"; + code = nebula::cpp2::ErrorCode::E_NO_HOSTS; + break; + } + holder->remove(std::move(hostKey)); } if (code != nebula::cpp2::ErrorCode::SUCCEEDED) { diff --git a/src/meta/processors/zone/GetZoneProcessor.cpp b/src/meta/processors/zone/GetZoneProcessor.cpp index 882424055de..f5445b456b4 100644 --- a/src/meta/processors/zone/GetZoneProcessor.cpp +++ b/src/meta/processors/zone/GetZoneProcessor.cpp @@ -11,19 +11,6 @@ namespace meta { void GetZoneProcessor::process(const cpp2::GetZoneReq& req) { folly::SharedMutex::ReadHolder rHolder(LockUtils::zoneLock()); auto zoneName = req.get_zone_name(); - auto zoneIdRet = getZoneId(zoneName); - if (!nebula::ok(zoneIdRet)) { - auto retCode = nebula::error(zoneIdRet); - if (retCode == nebula::cpp2::ErrorCode::E_ZONE_NOT_FOUND) { - LOG(ERROR) << "Get Zone Failed, Zone " << zoneName << " not found."; - } else { - LOG(ERROR) << "Get Zone Failed, error: " << apache::thrift::util::enumNameSafe(retCode); - } - handleErrorCode(retCode); - onFinished(); - return; - } - auto zoneKey = MetaKeyUtils::zoneKey(zoneName); auto zoneValueRet = doGet(std::move(zoneKey)); if (!nebula::ok(zoneValueRet)) { diff --git a/src/meta/processors/zone/RenameZoneProcessor.cpp b/src/meta/processors/zone/RenameZoneProcessor.cpp index 02bfa3ce0d9..11176c2fc6f 100644 --- a/src/meta/processors/zone/RenameZoneProcessor.cpp +++ b/src/meta/processors/zone/RenameZoneProcessor.cpp @@ -44,7 +44,6 @@ void RenameZoneProcessor::process(const cpp2::RenameZoneReq& req) { return; } - // std::vector data; auto batchHolder = std::make_unique(); auto iter = nebula::value(ret).get(); while (iter->valid()) { @@ -62,7 +61,7 @@ void RenameZoneProcessor::process(const cpp2::RenameZoneReq& req) { iter->next(); } - batchHolder->remove(MetaKeyUtils::zoneKey(originalZoneKey)); + batchHolder->remove(MetaKeyUtils::zoneKey(originalZoneName)); batchHolder->put(std::move(zoneKey), std::move(originalZoneValue)); auto batch = encodeBatchValue(std::move(batchHolder)->getBatch()); doBatchOperation(std::move(batch)); diff --git a/src/meta/test/AuthProcessorTest.cpp b/src/meta/test/AuthProcessorTest.cpp index 4c571db64c4..f4968222001 100644 --- a/src/meta/test/AuthProcessorTest.cpp +++ b/src/meta/test/AuthProcessorTest.cpp @@ -206,6 +206,10 @@ TEST(AuthProcessorTest, GrantRevokeTest) { auto resp = std::move(f).get(); ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); } + { + std::vector hosts = {{"0", 0}, {"1", 1}, {"2", 2}, {"3", 3}}; + TestUtils::registerHB(kv.get(), hosts); + } GraphSpaceID space1, space2; // create space1 { diff --git a/src/meta/test/IndexProcessorTest.cpp b/src/meta/test/IndexProcessorTest.cpp index 379e563e15a..a6fdd518372 100644 --- a/src/meta/test/IndexProcessorTest.cpp +++ b/src/meta/test/IndexProcessorTest.cpp @@ -2047,6 +2047,10 @@ TEST(ProcessorTest, IndexIdInSpaceRangeTest) { auto resp = std::move(f).get(); ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); } + { + std::vector hosts = {{"0", 0}, {"1", 1}, {"2", 2}, {"3", 3}}; + TestUtils::registerHB(kv.get(), hosts); + } // mock one space and ten tag, ten edge { // space Id is 1 diff --git a/src/meta/test/MetaClientTest.cpp b/src/meta/test/MetaClientTest.cpp index 4067116b38e..e98b59a5969 100644 --- a/src/meta/test/MetaClientTest.cpp +++ b/src/meta/test/MetaClientTest.cpp @@ -45,7 +45,8 @@ TEST(MetaClientTest, InterfacesTest) { GraphSpaceID spaceId = 0; { std::vector hosts = {{"0", 0}, {"1", 1}, {"2", 2}, {"3", 3}}; - auto result = client->addHosts(std::move(hosts)).get(); + auto result = client->addHosts(hosts).get(); + TestUtils::registerHB(cluster.metaKV_.get(), hosts); EXPECT_TRUE(result.ok()); } { @@ -356,7 +357,8 @@ TEST(MetaClientTest, TagTest) { auto* client = cluster.metaClient_.get(); { std::vector hosts = {{"0", 0}, {"1", 1}, {"2", 2}, {"3", 3}}; - auto result = client->addHosts(std::move(hosts)).get(); + auto result = client->addHosts(hosts).get(); + TestUtils::registerHB(cluster.metaKV_.get(), hosts); EXPECT_TRUE(result.ok()); } meta::cpp2::SpaceDesc spaceDesc; @@ -592,7 +594,8 @@ TEST(MetaClientTest, EdgeTest) { auto* client = cluster.metaClient_.get(); { std::vector hosts = {{"0", 0}, {"1", 1}, {"2", 2}, {"3", 3}}; - auto result = client->addHosts(std::move(hosts)).get(); + auto result = client->addHosts(hosts).get(); + TestUtils::registerHB(cluster.metaKV_.get(), hosts); EXPECT_TRUE(result.ok()); } meta::cpp2::SpaceDesc spaceDesc; @@ -702,7 +705,8 @@ TEST(MetaClientTest, TagIndexTest) { auto* client = cluster.metaClient_.get(); { std::vector hosts = {{"0", 0}, {"1", 1}, {"2", 2}, {"3", 3}}; - auto result = client->addHosts(std::move(hosts)).get(); + auto result = client->addHosts(hosts).get(); + TestUtils::registerHB(cluster.metaKV_.get(), hosts); EXPECT_TRUE(result.ok()); } @@ -882,7 +886,8 @@ TEST(MetaClientTest, EdgeIndexTest) { auto* client = cluster.metaClient_.get(); { std::vector hosts = {{"0", 0}, {"1", 1}, {"2", 2}, {"3", 3}}; - auto result = client->addHosts(std::move(hosts)).get(); + auto result = client->addHosts(hosts).get(); + TestUtils::registerHB(cluster.metaKV_.get(), hosts); EXPECT_TRUE(result.ok()); } @@ -1281,7 +1286,8 @@ TEST(MetaClientTest, ListenerDiffTest) { auto client = std::make_unique(threadPool, metaAddrs, options); { std::vector hosts = {{"0", 0}}; - auto result = client->addHosts(std::move(hosts)).get(); + auto result = client->addHosts(hosts).get(); + TestUtils::registerHB(cluster.metaKV_.get(), hosts); EXPECT_TRUE(result.ok()); } client->waitForMetadReady(); @@ -1700,7 +1706,8 @@ TEST(MetaClientTest, ListenerTest) { auto client = std::make_shared(threadPool, localhosts); { std::vector hosts = {{"0", 0}, {"1", 1}, {"2", 2}, {"3", 3}}; - auto result = client->addHosts(std::move(hosts)).get(); + auto result = client->addHosts(hosts).get(); + TestUtils::registerHB(cluster.metaKV_.get(), hosts); EXPECT_TRUE(result.ok()); } client->waitForMetadReady(); @@ -1899,6 +1906,7 @@ TEST(MetaClientTest, AddHostsIntoZoneTest) { cluster.startMeta(rootPath.path()); cluster.initMetaClient(); auto* client = cluster.metaClient_.get(); + auto* kv = cluster.metaKV_.get(); { // Add host into zone with duplicate hosts std::vector hosts = {{"127.0.0.1", 8988}, {"127.0.0.1", 8988}, {"127.0.0.1", 8989}}; @@ -1951,6 +1959,7 @@ TEST(MetaClientTest, AddHostsIntoZoneTest) { auto result = client->addHostsIntoZone(std::move(hosts), "zone_1", false).get(); EXPECT_FALSE(result.ok()); } + { TestUtils::registerHB(kv, {{"127.0.0.1", 8987}, {"127.0.0.1", 8988}, {"127.0.0.1", 8989}}); } { // Drop hosts which is empty. std::vector hosts = {}; diff --git a/src/meta/test/ProcessorTest.cpp b/src/meta/test/ProcessorTest.cpp index b942e98afdd..ca88c3bb999 100644 --- a/src/meta/test/ProcessorTest.cpp +++ b/src/meta/test/ProcessorTest.cpp @@ -324,6 +324,10 @@ TEST(ProcessorTest, SpaceTest) { auto resp = std::move(f).get(); ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); } + { + std::vector hosts = {{"0", 0}, {"1", 1}, {"2", 2}, {"3", 3}}; + TestUtils::registerHB(kv.get(), hosts); + } int32_t hostsNum = 4; { cpp2::SpaceDesc properties; @@ -490,6 +494,10 @@ TEST(ProcessorTest, CreateTagTest) { auto resp = std::move(f).get(); ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); } + { + std::vector hosts = {{"0", 0}, {"1", 1}, {"2", 2}, {"3", 3}}; + TestUtils::registerHB(kv.get(), hosts); + } { cpp2::SpaceDesc properties; properties.space_name_ref() = "first_space"; @@ -693,6 +701,10 @@ TEST(ProcessorTest, CreateEdgeTest) { auto resp = std::move(f).get(); ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); } + { + std::vector hosts = {{"0", 0}, {"1", 1}, {"2", 2}, {"3", 3}}; + TestUtils::registerHB(kv.get(), hosts); + } { cpp2::SpaceDesc properties; properties.space_name_ref() = "default_space"; @@ -885,6 +897,10 @@ TEST(ProcessorTest, KVOperationTest) { auto resp = std::move(f).get(); ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); } + { + std::vector hosts = {{"0", 0}, {"1", 1}, {"2", 2}, {"3", 3}}; + TestUtils::registerHB(kv.get(), hosts); + } { cpp2::SpaceDesc properties; properties.space_name_ref() = "default_space"; @@ -2286,6 +2302,10 @@ TEST(ProcessorTest, SameNameTagsTest) { auto resp = std::move(f).get(); ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); } + { + std::vector hosts = {{"0", 0}, {"1", 1}, {"2", 2}, {"3", 3}}; + TestUtils::registerHB(kv.get(), hosts); + } { cpp2::SpaceDesc properties; properties.space_name_ref() = "default_space"; @@ -2534,6 +2554,10 @@ TEST(ProcessorTest, TagIdAndEdgeTypeInSpaceRangeTest) { auto resp = std::move(f).get(); ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); } + { + std::vector hosts = {{"0", 0}, {"1", 1}, {"2", 2}, {"3", 3}}; + TestUtils::registerHB(kv.get(), hosts); + } // mock one space and ten tag, ten edge { // space Id is 1 @@ -3052,6 +3076,10 @@ TEST(ProcessorTest, AddHostsIntoZoneTest) { auto resp = std::move(f).get(); ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); } + { + std::vector hosts = {{"127.0.0.1", 8987}, {"127.0.0.1", 8988}, {"127.0.0.1", 8989}}; + TestUtils::registerHB(kv.get(), hosts); + } { // Add host into zone with zone name conflict. cpp2::AddHostsIntoZoneReq req; @@ -3077,6 +3105,10 @@ TEST(ProcessorTest, AddHostsIntoZoneTest) { auto resp = std::move(f).get(); ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); } + { + std::vector hosts = {{"127.0.0.1", 8977}, {"127.0.0.1", 8978}, {"127.0.0.1", 8979}}; + TestUtils::registerHB(kv.get(), hosts); + } { // Add existed hosts. cpp2::AddHostsReq req; @@ -3182,6 +3214,10 @@ TEST(ProcessorTest, DropHostsTest) { auto resp = std::move(f).get(); ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); } + { + std::vector hosts = {{"127.0.0.1", 8987}, {"127.0.0.1", 8988}, {"127.0.0.1", 8989}}; + TestUtils::registerHB(kv.get(), hosts); + } { // Attempt to register heartbeat const ClusterID kClusterId = 10; @@ -3297,6 +3333,11 @@ TEST(ProcessorTest, DropHostsTest) { auto resp = std::move(f).get(); ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); } + { + std::vector hosts = { + {"127.0.0.1", 8976}, {"127.0.0.1", 8977}, {"127.0.0.1", 8978}, {"127.0.0.1", 8979}}; + TestUtils::registerHB(kv.get(), hosts); + } { // Show the zones created by add hosts cpp2::ListZonesReq req; @@ -3338,6 +3379,24 @@ TEST(ProcessorTest, DropHostsTest) { ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); ASSERT_EQ(4, resp.get_id().get_space_id()); } + { + // Create Space on cluster, the replica number same with the zone size + cpp2::SpaceDesc properties; + properties.space_name_ref() = "default_space_on_zone_duplicate"; + properties.partition_num_ref() = 9; + properties.replica_factor_ref() = 3; + properties.charset_name_ref() = "utf8"; + properties.collate_name_ref() = "utf8_bin"; + std::vector zones = {"zone_0", "zone_1", "zone_1"}; + properties.zone_names_ref() = std::move(zones); + cpp2::CreateSpaceReq req; + req.properties_ref() = std::move(properties); + auto* processor = CreateSpaceProcessor::instance(kv.get()); + auto f = processor->getFuture(); + processor->process(req); + auto resp = std::move(f).get(); + ASSERT_EQ(nebula::cpp2::ErrorCode::E_INVALID_PARM, resp.get_code()); + } { // Create Space on cluster, the replica number less than the zone size cpp2::SpaceDesc properties; @@ -3355,7 +3414,7 @@ TEST(ProcessorTest, DropHostsTest) { processor->process(req); auto resp = std::move(f).get(); ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); - ASSERT_EQ(5, resp.get_id().get_space_id()); + ASSERT_EQ(6, resp.get_id().get_space_id()); } { // Create Space on cluster, the replica number greater than the zone size @@ -3945,6 +4004,11 @@ TEST(ProcessorTest, DivideZoneTest) { auto resp = std::move(f).get(); ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); } + { + std::vector hosts = { + {"127.0.0.1", 8986}, {"127.0.0.1", 8987}, {"127.0.0.1", 8988}, {"127.0.0.1", 8989}}; + TestUtils::registerHB(kv.get(), hosts); + } { cpp2::ListZonesReq req; auto* processor = ListZonesProcessor::instance(kv.get()); @@ -4102,6 +4166,11 @@ TEST(ProcessorTest, DivideZoneTest) { auto resp = std::move(f).get(); ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); } + { + std::vector hosts = { + {"127.0.0.1", 8976}, {"127.0.0.1", 8977}, {"127.0.0.1", 8978}, {"127.0.0.1", 8979}}; + TestUtils::registerHB(kv.get(), hosts); + } { cpp2::ListZonesReq req; auto* processor = ListZonesProcessor::instance(kv.get()); diff --git a/src/storage/test/KVClientTest.cpp b/src/storage/test/KVClientTest.cpp index e52c9451e95..26b9c2cc47b 100644 --- a/src/storage/test/KVClientTest.cpp +++ b/src/storage/test/KVClientTest.cpp @@ -51,6 +51,10 @@ TEST(KVClientTest, SimpleTest) { auto result = metaClient->addHosts(std::move(hosts)).get(); EXPECT_TRUE(result.ok()); } + { + std::vector hosts = {storageAddr}; + nebula::meta::TestUtils::registerHB(cluster.metaKV_.get(), hosts); + } cluster.startStorage(storageAddr, storagePath.path()); auto client = cluster.initGraphStorageClient();