Skip to content

Commit

Permalink
fix test and engine pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
pengweisong committed Mar 15, 2022
1 parent 188bd30 commit 9f61253
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
3 changes: 2 additions & 1 deletion src/kvstore/NebulaStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ void NebulaStore::loadPartFromDataPath() {
}

// add to spaces if the part should exist
KVEngine* enginePtr = nullptr;
{
folly::RWSpinLock::WriteHolder wh(&lock_);
auto spaceIt = this->spaces_.find(spaceId);
Expand All @@ -152,11 +153,11 @@ void NebulaStore::loadPartFromDataPath() {
spaceIt = this->spaces_.emplace(spaceId, std::make_unique<SpacePartInfo>()).first;
}
spaceIt->second->engines_.emplace_back(std::move(engine));
enginePtr = spaceIt->second->engines_.back().get();
}

std::atomic<size_t> counter(partRaftPeers.size());
folly::Baton<true, std::atomic> baton;
auto enginePtr = engine.get();
LOG(INFO) << "Need to open " << partRaftPeers.size() << " parts of space " << spaceId;
for (auto& it : partRaftPeers) {
auto& partId = it.first;
Expand Down
49 changes: 26 additions & 23 deletions src/kvstore/test/NebulaStoreTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,20 @@ TEST(NebulaStoreTest, PartsTest) {
auto ioThreadPool = std::make_shared<folly::IOThreadPoolExecutor>(4);
auto partMan = std::make_unique<MemPartManager>();

auto space1 = 1; // 0 is system space, then we could not use it
// GraphSpaceID => {PartitionIDs}
// 0 => {0, 1, 2, 3...9}
// 1 => {0, 1, 2, 3...9}
// The parts on PartMan is 0...9
for (auto partId = 0; partId < 10; partId++) {
partMan->addPart(0, partId);
partMan->addPart(space1, partId);
}

std::vector<std::string> paths;
paths.emplace_back(folly::stringPrintf("%s/disk1", rootPath.path()));
paths.emplace_back(folly::stringPrintf("%s/disk2", rootPath.path()));

for (size_t i = 0; i < paths.size(); i++) {
auto db = std::make_unique<RocksEngine>(0, /* spaceId */
auto db = std::make_unique<RocksEngine>(space1, /* spaceId */
kDefaultVidLen,
paths[i]);
for (auto partId = 0; partId < 3; partId++) {
Expand Down Expand Up @@ -180,21 +181,21 @@ TEST(NebulaStoreTest, PartsTest) {
ASSERT_EQ(5, parts.size());
}
};
check(0);
check(space1);
// After init, the parts should be 0-9, and the distribution should be
// disk1: 0, 1, 2, 3, 8
// disk2: 4, 5, 6, 7, 9
// After restart, the original order should not been broken.
{
auto parts = store->spaces_[0]->engines_[0]->allParts();
auto parts = store->spaces_[space1]->engines_[0]->allParts();
ASSERT_EQ(0, parts[0]);
ASSERT_EQ(1, parts[1]);
ASSERT_EQ(2, parts[2]);
ASSERT_EQ(3, parts[3]);
ASSERT_EQ(8, parts[4]);
}
{
auto parts = store->spaces_[0]->engines_[1]->allParts();
auto parts = store->spaces_[space1]->engines_[1]->allParts();
ASSERT_EQ(4, parts[0]);
ASSERT_EQ(5, parts[1]);
ASSERT_EQ(6, parts[2]);
Expand All @@ -204,46 +205,47 @@ TEST(NebulaStoreTest, PartsTest) {

auto* pm = dynamic_cast<MemPartManager*>(store->options_.partMan_.get());
// Let's create another space with 10 parts.
auto space2 = 2;
for (auto partId = 0; partId < 10; partId++) {
pm->addPart(1, partId);
pm->addPart(space2, partId);
}
check(1);
check(space2);
{
auto parts = store->spaces_[1]->engines_[0]->allParts();
auto parts = store->spaces_[space2]->engines_[0]->allParts();
ASSERT_EQ(0, parts[0]);
ASSERT_EQ(2, parts[1]);
ASSERT_EQ(4, parts[2]);
ASSERT_EQ(6, parts[3]);
ASSERT_EQ(8, parts[4]);
}
{
auto parts = store->spaces_[1]->engines_[1]->allParts();
auto parts = store->spaces_[space2]->engines_[1]->allParts();
ASSERT_EQ(1, parts[0]);
ASSERT_EQ(3, parts[1]);
ASSERT_EQ(5, parts[2]);
ASSERT_EQ(7, parts[3]);
ASSERT_EQ(9, parts[4]);
}

// Let's remove space some parts in GraphSpace 0
// Let's remove space some parts in GraphSpace 1
for (auto partId = 0; partId < 5; partId++) {
pm->removePart(0, partId);
pm->removePart(space1, partId);
}

int32_t totalParts = 0;
for (auto i = 0; i < 2; i++) {
ASSERT_EQ(folly::stringPrintf("%s/disk%d/nebula/0", rootPath.path(), i + 1),
store->spaces_[0]->engines_[i]->getDataRoot());
auto parts = store->spaces_[0]->engines_[i]->allParts();
ASSERT_EQ(folly::stringPrintf("%s/disk%d/nebula/%d", rootPath.path(), i + 1, space1),
store->spaces_[space1]->engines_[i]->getDataRoot());
auto parts = store->spaces_[space1]->engines_[i]->allParts();
dump(parts);
totalParts += parts.size();
}
ASSERT_EQ(5, totalParts);

for (auto partId = 5; partId < 10; partId++) {
pm->removePart(0, partId);
pm->removePart(space1, partId);
}
ASSERT_TRUE(store->spaces_.find(0) == store->spaces_.end());
ASSERT_TRUE(store->spaces_.find(space1) == store->spaces_.end());
}

TEST(NebulaStoreTest, PersistPeersTest) {
Expand All @@ -252,10 +254,11 @@ TEST(NebulaStoreTest, PersistPeersTest) {
auto partMan = std::make_unique<MemPartManager>();

// GraphSpaceID => {PartitionIDs}
// 0 => {0, 1, 2, 3...9}
// 1 => {0, 1, 2, 3...9}
// The parts on PartMan is 0...9
auto space1 = 1;
for (auto partId = 0; partId < 10; partId++) {
partMan->addPart(0, partId);
partMan->addPart(space1, partId);
}

std::vector<std::string> paths;
Expand All @@ -264,7 +267,7 @@ TEST(NebulaStoreTest, PersistPeersTest) {

HostAddr local = {"", 0};
for (size_t i = 0; i < paths.size(); i++) {
auto db = std::make_unique<RocksEngine>(0, /* spaceId */
auto db = std::make_unique<RocksEngine>(space1, /* spaceId */
kDefaultVidLen,
paths[i]);
for (auto partId = 0; partId < 3; partId++) {
Expand Down Expand Up @@ -306,13 +309,13 @@ TEST(NebulaStoreTest, PersistPeersTest) {
}
}
};
check(0);
check(space1);
// After init, the parts should be 0-9, and the distribution should be
// disk1: 0, 1, 2, 3, 8, 10
// disk2: 4, 5, 6, 7, 9, 15
// After restart, the original order should not been broken.
{
auto parts = store->spaces_[0]->engines_[0]->allParts();
auto parts = store->spaces_[space1]->engines_[0]->allParts();
dump(parts);
ASSERT_EQ(0, parts[0]);
ASSERT_EQ(1, parts[1]);
Expand All @@ -322,7 +325,7 @@ TEST(NebulaStoreTest, PersistPeersTest) {
ASSERT_EQ(10, parts[5]);
}
{
auto parts = store->spaces_[0]->engines_[1]->allParts();
auto parts = store->spaces_[space1]->engines_[1]->allParts();
dump(parts);
ASSERT_EQ(4, parts[0]);
ASSERT_EQ(5, parts[1]);
Expand Down

0 comments on commit 9f61253

Please sign in to comment.