nebula版本:3.1.0,部署方式:分布式,磁盘:SSD。
hi,社区的大佬,请教一个use space相关的问题。
我们在使用过程中,发现部分用户喜欢在每条nGQL前加上一个use space的语句,这个语句有时会触发graph的慢查询。
看了代码发现session在切换space时,在UseValidator里首先从MetaClient的Cache里查询了一次space,
// Choose graph space, first from validator context (space created in previous sentence),
// then from meta data cache.
Status UseValidator::validateImpl() {
auto useSentence = static_cast<UseSentence*>(sentence_);
spaceName_ = useSentence->space();
SpaceInfo spaceInfo;
spaceInfo.name = *spaceName_;
// firstly get from validate context
if (!vctx_->hasSpace(*spaceName_)) {
// secondly get from cache
auto spaceId = qctx_->schemaMng()->toGraphSpaceID(*spaceName_);
if (!spaceId.ok()) {
LOG(ERROR) << "Unknown space: " << *spaceName_ << " : " << spaceId.status();
return spaceId.status();
}
auto spaceDesc = qctx_->getMetaClient()->getSpaceDesc(spaceId.value());
if (!spaceDesc.ok()) {
return spaceDesc.status();
}
spaceInfo.id = spaceId.value();
spaceInfo.spaceDesc = std::move(spaceDesc).value();
vctx_->switchToSpace(std::move(spaceInfo));
return Status::OK();
}
spaceInfo.id = -1;
vctx_->switchToSpace(std::move(spaceInfo));
return Status::OK();
}
随后又在SwitchSpaceExecutor中,调用Meta的rpc接口查询了一次space信息,
folly::Future<Status> SwitchSpaceExecutor::execute() {
SCOPED_TIMER(&execTime_);
auto *spaceToNode = asNode<SwitchSpace>(node());
auto spaceName = spaceToNode->getSpaceName();
return qctx()->getMetaClient()->getSpace(spaceName).via(runner()).thenValue(
[spaceName, this](StatusOr<meta::cpp2::SpaceItem> resp) {
if (!resp.ok()) {
LOG(WARNING) << "Switch space :`" << spaceName << "' fail: " << resp.status();
return resp.status();
}
auto spaceId = resp.value().get_space_id();
auto *session = qctx_->rctx()->session();
NG_RETURN_IF_ERROR(PermissionManager::canReadSpace(session, spaceId));
const auto &properties = resp.value().get_properties();
SpaceInfo spaceInfo;
spaceInfo.id = spaceId;
spaceInfo.name = spaceName;
spaceInfo.spaceDesc = std::move(properties);
qctx_->rctx()->session()->setSpace(std::move(spaceInfo));
LOG(INFO) << "Graph switched to `" << spaceName << "', space id: " << spaceId;
return Status::OK();
});
}
想要请教一下为什么需要查询两次space的信息,能不能去掉后面那次meta的rpc调用,会不会引发什么问题?