Skip to content

Commit

Permalink
fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
jievince committed Nov 23, 2021
1 parent 061be2f commit c0448de
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 13 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ jobs:
echo '127.0.0.1 graphd' >> /etc/hosts
echo '127.0.0.1 graphd1' >> /etc/hosts
echo '127.0.0.1 graphd2' >> /etc/hosts
echo '127.0.0.1 server' >> /etc/hosts
- name: CTest
env:
ASAN_OPTIONS: fast_unwind_on_malloc=1
Expand Down
39 changes: 32 additions & 7 deletions src/mclient/MetaClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@ MetaClient::MetaClient(const std::vector<std::string>& metaAddrs) {
ioExecutor_ = std::make_shared<folly::IOThreadPoolExecutor>(std::thread::hardware_concurrency());
clientsMan_ =
std::make_shared<thrift::ThriftClientManager<meta::cpp2::MetaServiceAsyncClient>>(false);
loadData(); // load data into cache
bool b = loadData(); // load data into cache
if (!b) {
LOG(INFO) << "load data failed";
} else {
LOG(INFO) << "load data succecced";
LOG(INFO) << spaceIndexByName_.size();
LOG(INFO) << spaceEdgeIndexByName_.size();
LOG(INFO) << spacePartLeaderMap_.size();
LOG(INFO) << spacePartsMap_.size();
}
}

MetaClient::~MetaClient() = default;
Expand All @@ -52,22 +61,29 @@ std::pair<bool, EdgeType> MetaClient::getEdgeTypeByNameFromCache(GraphSpaceID sp
}

std::pair<bool, std::vector<PartitionID>> MetaClient::getPartsFromCache(GraphSpaceID spaceId) {
LOG(INFO) << "getPartsFromCache(" << spaceId << ")";
for (auto kv : spacePartsMap_) {
LOG(INFO) << kv.first << ", ";
for (auto partId : kv.second) {
LOG(INFO) << partId;
}
}
auto iter = spacePartsMap_.find(spaceId);
if (iter != spacePartsMap_.end()) {
return {true, iter->second};
if (iter == spacePartsMap_.end()) {
return {false, {}};
}

return {false, {}};
return {true, iter->second};
}

std::pair<bool, HostAddr> MetaClient::getPartLeaderFromCache(GraphSpaceID spaceId,
PartitionID partId) {
auto iter = spacePartLeaderMap_.find({spaceId, partId});
if (iter != spacePartLeaderMap_.end()) {
return {true, iter->second};
if (iter == spacePartLeaderMap_.end()) {
return {false, HostAddr()};
}

return {false, HostAddr()};
return {true, iter->second};
}

bool MetaClient::loadData() {
Expand Down Expand Up @@ -148,20 +164,29 @@ std::pair<bool, std::vector<meta::cpp2::EdgeItem>> MetaClient::listEdgeSchemas(

void MetaClient::loadLeader(const std::vector<meta::cpp2::HostItem>& hostItems,
const SpaceNameIdMap& spaceIndexByName) {
LOG(INFO) << "loadLeader start";
for (auto& item : hostItems) {
LOG(INFO) << "item.get_leader_parts().size()=" << item.get_leader_parts().size();
for (auto& spaceEntry : item.get_leader_parts()) {
auto spaceName = spaceEntry.first;
LOG(INFO) << "[" << spaceName << "]";
auto iter = spaceIndexByName.find(spaceName);
if (iter == spaceIndexByName.end()) {
LOG(INFO) << "dont' find " << spaceName;
continue;
}
auto spaceId = iter->second;
LOG(INFO) << "spaceId:" << spaceId;
LOG(INFO) << "spaceEntry.second.size()" << spaceEntry.second.size();
for (const auto& partId : spaceEntry.second) {
LOG(INFO) << "spaceId: " << spaceId << ", partId: " << partId
<< ", host: " << item.get_hostAddr();
spacePartLeaderMap_[{spaceId, partId}] = item.get_hostAddr();
spacePartsMap_[spaceId].emplace_back(partId);
}
}
}
LOG(INFO) << "loadLeader end";
}

std::vector<SpaceIdName> MetaClient::toSpaceIdName(
Expand Down
17 changes: 14 additions & 3 deletions src/mclient/tests/MetaClientTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

// Require a nebula server could access

#define kServerHost "127.0.0.1"
#define kServerHost "server"

class MetaClientTest : public ClientTest {
protected:
Expand All @@ -36,6 +36,14 @@ class MetaClientTest : public ClientTest {

auto result2 = session.execute("CREATE EDGE IF NOT EXISTS like(likeness int)");
ASSERT_EQ(result2.errorCode, nebula::ErrorCode::SUCCEEDED);

::sleep(10);

auto result3 = session.execute(
"INSERT EDGE like(likeness) VALUES '101'->'102':(78), '102'->'103':(99), "
"'103'->'201':(43), '201'->'202':(56), '202'->'203':(-13), '203'->'301':(431), "
"'301'->'302':(457)");
ASSERT_EQ(result3.errorCode, nebula::ErrorCode::SUCCEEDED);
}

static void runOnce(nebula::MetaClient &c) {
Expand All @@ -58,13 +66,16 @@ class MetaClientTest : public ClientTest {

auto ret4 = c.getPartLeaderFromCache(spaceId, 1);
ASSERT_TRUE(ret4.first);
EXPECT_EQ(ret4.second, nebula::HostAddr("127.0.0.1", 9779));
EXPECT_EQ(ret4.second, nebula::HostAddr(kServerHost, 9779));
}
};

TEST_F(MetaClientTest, Basic) {
nebula::MetaClient c({kServerHost ":9559"});
LOG(INFO) << "Prepare data.";
prepare();

LOG(INFO) << "Run once.";
nebula::MetaClient c({kServerHost ":9559"});
runOnce(c);
}

Expand Down
1 change: 1 addition & 0 deletions src/sclient/ScanEdgeIter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ DataSet ScanEdgeIter::next() {
auto partCursorMapReq = req_->get_parts();
DCHECK_EQ(partCursorMapReq.size(), 1);
partCursorMapReq.begin()->second.set_next_cursor(nextCursor_);
LOG(INFO) << "nextCursor of req: " << partCursorMapReq.begin()->second.get_next_cursor();
req_->set_parts(partCursorMapReq);
}
auto r = client_->doScanEdge(*req_);
Expand Down
7 changes: 4 additions & 3 deletions src/sclient/tests/StorageClientTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

// Require a nebula server could access

#define kServerHost "127.0.0.1"
#define kServerHost "server"

class StorageClientTest : public ClientTest {
protected:
Expand All @@ -37,7 +37,7 @@ class StorageClientTest : public ClientTest {
auto result2 = session.execute("CREATE EDGE IF NOT EXISTS like(likeness int)");
ASSERT_EQ(result2.errorCode, nebula::ErrorCode::SUCCEEDED);

::sleep(30);
::sleep(10);

auto result3 = session.execute(
"INSERT EDGE like(likeness) VALUES '101'->'102':(78), '102'->'103':(99), "
Expand Down Expand Up @@ -107,8 +107,9 @@ class StorageClientTest : public ClientTest {
};

TEST_F(StorageClientTest, Basic) {
nebula::StorageClient c({kServerHost ":9559"});
LOG(INFO) << "Prepare data.";
prepare();
nebula::StorageClient c({kServerHost ":9559"});
LOG(INFO) << "Testing run get parts.";
runGetParts(c);
LOG(INFO) << "Testing run scan edge with part.";
Expand Down

0 comments on commit c0448de

Please sign in to comment.