Skip to content

Commit

Permalink
Correct the checkpoint testing which write before all leaders elected. (
Browse files Browse the repository at this point in the history
  • Loading branch information
Shylock-Hg committed Mar 11, 2020
1 parent f980976 commit 38e4a09
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/storage/test/CheckpointTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ namespace nebula {
namespace storage {
TEST(CheckpointTest, simpleTest) {
fs::TempDir dataPath("/tmp/Checkpoint_Test_src.XXXXXX");
std::unique_ptr<kvstore::KVStore> kv(TestUtils::initKV(dataPath.path()));
constexpr int32_t partitions = 6;
std::unique_ptr<kvstore::KVStore> kv(TestUtils::initKV(dataPath.path(), partitions,
{0, network::NetworkUtils::getAvailablePort()}));
// Hard code the default space 0, partitions set
TestUtils::waitUntilAllElected(kv.get(), 0, {0, 1, 2, 3, 4, 5}/*partitions*/);
auto schemaMan = TestUtils::mockSchemaMan();
auto indexMan = TestUtils::mockIndexMan();
// Add vertices
Expand Down
25 changes: 25 additions & 0 deletions src/storage/test/TestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,31 @@ class TestUtils {
usleep(100000);
}
}

// Wait the specified partition elected
static void waitUntilAllElected(kvstore::KVStore* kvstore, GraphSpaceID spaceId,
std::set<PartitionID> parts) {
auto* nKV = static_cast<kvstore::NebulaStore*>(kvstore);
const int32_t partNum = parts.size();
// wait until all part leader exists
while (true) {
int readyNum = 0;
for (const auto partId : parts) {
auto retLeader = nKV->partLeader(spaceId, partId);
if (ok(retLeader)) {
auto leader = value(std::move(retLeader));
if (leader != HostAddr(0, 0)) {
readyNum++;
}
}
}
if (readyNum == partNum) {
LOG(INFO) << "All leaders have been elected!";
break;
}
usleep(100000);
}
}
};

template <typename T>
Expand Down

0 comments on commit 38e4a09

Please sign in to comment.