Skip to content

Commit f4a2299

Browse files
Sophie-XiejievinceczpmangoAieenevermore3
authored
Cherry pick v3.1.0 (0414-0420) (#4183)
* fix issue 4152 (#4158) * Fix optional of multi-match (#4159) * fix optional of multi-match * format Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com> * Fix incompatibility imported by #4116 (#4165) * Add SaveGraphVersionProcessor to separate client version check and version saving * Update error code * Update error code * optimizer path (#4162) * optimizer multi-shortest path * new algorithm * fix error * skip heartbeat for tool (#4177) Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com> * Fix/null pattern expression input (#4180) * Move input rows of Traverse and AppendVertices. * Avoid skip validate pattern expression with aggregate. * Fix case. * Revert "Move input rows of Traverse and AppendVertices." This reverts commit 7fd1d38. Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com> * fix wrong space key after dropping hosts (#4182) Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com> * fix vertex is missing from snapshot (#4189) Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com> * Expression is stateful to store the result of evaluation, so we can't… (#4190) * Expression is stateful to store the result of evaluation, so we can't share it inter threads. * Fix defef nullptr. Co-authored-by: jie.wang <38901892+jievince@users.noreply.github.com> Co-authored-by: kyle.cao <kyle.cao@vesoft.com> Co-authored-by: Yichen Wang <18348405+Aiee@users.noreply.github.com> Co-authored-by: jimingquan <mingquan.ji@vesoft.com> Co-authored-by: Doodle <13706157+critical27@users.noreply.github.com> Co-authored-by: shylock <33566796+Shylock-Hg@users.noreply.github.com> Co-authored-by: liwenhui-soul <38217397+liwenhui-soul@users.noreply.github.com>
1 parent 85b77a5 commit f4a2299

26 files changed

+428
-146
lines changed

src/clients/meta/MetaClient.cpp

+47-6
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,21 @@ bool MetaClient::waitForMetadReady(int count, int retryIntervalSecs) {
129129
LOG(ERROR) << "Connect to the MetaServer Failed";
130130
return false;
131131
}
132+
133+
// Verify the graph server version
132134
auto status = verifyVersion();
133135
if (!status.ok()) {
134136
LOG(ERROR) << status;
135137
return false;
136138
}
137139

140+
// Save graph version to meta
141+
status = saveVersionToMeta();
142+
if (!status.ok()) {
143+
LOG(ERROR) << status;
144+
return false;
145+
}
146+
138147
CHECK(bgThread_->start());
139148
LOG(INFO) << "Register time task for heartbeat!";
140149
size_t delayMS = FLAGS_heartbeat_interval_secs * 1000 + folly::Random::rand32(900);
@@ -161,10 +170,14 @@ void MetaClient::heartBeatThreadFunc() {
161170
bgThread_->addDelayTask(
162171
FLAGS_heartbeat_interval_secs * 1000, &MetaClient::heartBeatThreadFunc, this);
163172
};
164-
auto ret = heartbeat().get();
165-
if (!ret.ok()) {
166-
LOG(ERROR) << "Heartbeat failed, status:" << ret.status();
167-
return;
173+
// UNKNOWN is reserved for tools such as upgrader, in that case the ip/port is not set. We do
174+
// not send heartbeat to meta to avoid writing error host info (e.g. Host("", 0))
175+
if (options_.role_ != cpp2::HostRole::UNKNOWN) {
176+
auto ret = heartbeat().get();
177+
if (!ret.ok()) {
178+
LOG(ERROR) << "Heartbeat failed, status:" << ret.status();
179+
return;
180+
}
168181
}
169182

170183
// if MetaServer has some changes, refresh the localCache_
@@ -227,7 +240,9 @@ bool MetaClient::loadUsersAndRoles() {
227240
}
228241

229242
bool MetaClient::loadData() {
230-
if (localDataLastUpdateTime_ == metadLastUpdateTime_) {
243+
// UNKNOWN role will skip heartbeat
244+
if (options_.role_ != cpp2::HostRole::UNKNOWN &&
245+
localDataLastUpdateTime_ == metadLastUpdateTime_) {
231246
return true;
232247
}
233248

@@ -2949,7 +2964,9 @@ StatusOr<std::vector<RemoteListenerInfo>> MetaClient::getListenerHostTypeBySpace
29492964
}
29502965

29512966
bool MetaClient::loadCfg() {
2952-
if (options_.skipConfig_ || localCfgLastUpdateTime_ == metadLastUpdateTime_) {
2967+
// UNKNOWN role will skip heartbeat
2968+
if (options_.skipConfig_ || (options_.role_ != cpp2::HostRole::UNKNOWN &&
2969+
localCfgLastUpdateTime_ == metadLastUpdateTime_)) {
29532970
return true;
29542971
}
29552972
if (!configReady_ && !registerCfg()) {
@@ -3611,5 +3628,29 @@ Status MetaClient::verifyVersion() {
36113628
return Status::OK();
36123629
}
36133630

3631+
Status MetaClient::saveVersionToMeta() {
3632+
auto req = cpp2::SaveGraphVersionReq();
3633+
req.build_version_ref() = getOriginVersion();
3634+
req.host_ref() = options_.localHost_;
3635+
folly::Promise<StatusOr<cpp2::SaveGraphVersionResp>> promise;
3636+
auto future = promise.getFuture();
3637+
getResponse(
3638+
std::move(req),
3639+
[](auto client, auto request) { return client->future_saveGraphVersion(request); },
3640+
[](cpp2::SaveGraphVersionResp&& resp) { return std::move(resp); },
3641+
std::move(promise));
3642+
3643+
auto respStatus = std::move(future).get();
3644+
if (!respStatus.ok()) {
3645+
return respStatus.status();
3646+
}
3647+
auto resp = std::move(respStatus).value();
3648+
if (resp.get_code() != nebula::cpp2::ErrorCode::SUCCEEDED) {
3649+
return Status::Error("Failed to save graph version into meta, error code: %s",
3650+
apache::thrift::util::enumNameSafe(resp.get_code()).c_str());
3651+
}
3652+
return Status::OK();
3653+
}
3654+
36143655
} // namespace meta
36153656
} // namespace nebula

src/clients/meta/MetaClient.h

+6
Original file line numberDiff line numberDiff line change
@@ -733,8 +733,14 @@ class MetaClient : public BaseMetaClient {
733733

734734
ListenersMap doGetListenersMap(const HostAddr& host, const LocalCache& localCache);
735735

736+
// Checks if the the client version is compatible with the server version by checking the
737+
// whilelist in meta.
736738
Status verifyVersion();
737739

740+
// Save the version of the graph service into meta so that it could be looked up.
741+
// This method should be only called in the internal client.
742+
Status saveVersionToMeta();
743+
738744
private:
739745
std::shared_ptr<folly::IOThreadPoolExecutor> ioThreadPool_;
740746
std::shared_ptr<thrift::ThriftClientManager<cpp2::MetaServiceAsyncClient>> clientsMan_;

src/common/utils/NebulaKeyUtils.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ std::vector<std::string> NebulaKeyUtils::snapshotPrefix(PartitionID partId) {
253253
if (partId == 0) {
254254
result.emplace_back("");
255255
} else {
256+
result.emplace_back(vertexPrefix(partId));
256257
result.emplace_back(tagPrefix(partId));
257258
result.emplace_back(edgePrefix(partId));
258259
result.emplace_back(IndexKeyUtils::indexPrefix(partId));

src/graph/executor/algo/BFSShortestPathExecutor.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,12 @@ folly::Future<Status> BFSShortestPathExecutor::conjunctPath() {
135135
std::vector<folly::Future<DataSet>> futures;
136136
for (auto& vid : meetVids) {
137137
batchVids.push_back(vid);
138-
if (i == totalSize - 1 || batchVids.size() == batchSize) {
138+
if (++i == totalSize || batchVids.size() == batchSize) {
139139
auto future = folly::via(runner(), [this, vids = std::move(batchVids), oddStep]() {
140140
return doConjunct(vids, oddStep);
141141
});
142142
futures.emplace_back(std::move(future));
143143
}
144-
i++;
145144
}
146145

147146
return folly::collect(futures).via(runner()).thenValue([this](auto&& resps) {

0 commit comments

Comments
 (0)