Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix crash when schema version is greater than 255 #3893

Merged
merged 2 commits into from
Feb 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions src/clients/meta/MetaClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ bool MetaClient::loadData() {

TagSchemas MetaClient::buildTagSchemas(std::vector<cpp2::TagItem> tagItemVec) {
TagSchemas tagSchemas;
TagID lastTagId = -1;
for (auto& tagIt : tagItemVec) {
// meta will return the different version from new to old
auto schema = std::make_shared<NebulaSchemaProvider>(tagIt.get_version());
Expand All @@ -409,20 +408,21 @@ TagSchemas MetaClient::buildTagSchemas(std::vector<cpp2::TagItem> tagItemVec) {
}
// handle schema property
schema->setProp(tagIt.get_schema().get_schema_prop());
if (tagIt.get_tag_id() != lastTagId) {
// init schema vector, since schema version is zero-based, need to add one
tagSchemas[tagIt.get_tag_id()].resize(schema->getVersion() + 1);
lastTagId = tagIt.get_tag_id();
auto& schemas = tagSchemas[tagIt.get_tag_id()];
// Because of the byte order of schema version in meta is not same as numerical order, we have
// to check schema version
if (schemas.size() <= static_cast<size_t>(schema->getVersion())) {
// since schema version is zero-based, need to add one
schemas.resize(schema->getVersion() + 1);
}
tagSchemas[tagIt.get_tag_id()][schema->getVersion()] = std::move(schema);
schemas[schema->getVersion()] = std::move(schema);
}
return tagSchemas;
}

EdgeSchemas MetaClient::buildEdgeSchemas(std::vector<cpp2::EdgeItem> edgeItemVec) {
EdgeSchemas edgeSchemas;
std::unordered_set<std::pair<GraphSpaceID, EdgeType>> edges;
EdgeType lastEdgeType = -1;
for (auto& edgeIt : edgeItemVec) {
// meta will return the different version from new to old
auto schema = std::make_shared<NebulaSchemaProvider>(edgeIt.get_version());
Expand All @@ -431,12 +431,14 @@ EdgeSchemas MetaClient::buildEdgeSchemas(std::vector<cpp2::EdgeItem> edgeItemVec
}
// handle shcem property
schema->setProp(edgeIt.get_schema().get_schema_prop());
if (edgeIt.get_edge_type() != lastEdgeType) {
// init schema vector, since schema version is zero-based, need to add one
edgeSchemas[edgeIt.get_edge_type()].resize(schema->getVersion() + 1);
lastEdgeType = edgeIt.get_edge_type();
auto& schemas = edgeSchemas[edgeIt.get_edge_type()];
// Because of the byte order of schema version in meta is not same as numerical order, we have
// to check schema version
if (schemas.size() <= static_cast<size_t>(schema->getVersion())) {
// since schema version is zero-based, need to add one
schemas.resize(schema->getVersion() + 1);
}
edgeSchemas[edgeIt.get_edge_type()][schema->getVersion()] = std::move(schema);
schemas[schema->getVersion()] = std::move(schema);
}
return edgeSchemas;
}
Expand Down