Skip to content

Commit

Permalink
fix crash when schema version is greater or equal than 255 (#3893)
Browse files Browse the repository at this point in the history
Co-authored-by: Sophie <[email protected]>
  • Loading branch information
critical27 and Sophie-Xie authored Feb 15, 2022
1 parent 2561d2f commit 9de3ead
Showing 1 changed file with 14 additions and 12 deletions.
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

0 comments on commit 9de3ead

Please sign in to comment.