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

enhancement in rebuild #2825

Merged
merged 2 commits into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion src/storage/admin/AdminTaskManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ namespace storage {

bool AdminTaskManager::init() {
LOG(INFO) << "max concurrenct subtasks: " << FLAGS_max_concurrent_subtasks;
pool_ = std::make_unique<ThreadPool>(FLAGS_max_concurrent_subtasks);
auto threadFactory = std::make_shared<folly::NamedThreadFactory>("TaskManager");
pool_ = std::make_unique<ThreadPool>(FLAGS_max_concurrent_subtasks, threadFactory);
bgThread_ = std::make_unique<thread::GenericWorker>();
if (!bgThread_->start()) {
LOG(ERROR) << "background thread start failed";
Expand Down
35 changes: 15 additions & 20 deletions src/storage/admin/RebuildEdgeIndexTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ nebula::cpp2::ErrorCode RebuildEdgeIndexTask::buildIndexGlobal(GraphSpaceID spac
edgeTypes.emplace(item->get_schema_id().get_edge_type());
}

auto schemasRet = env_->schemaMan_->getAllLatestVerEdgeSchema(space);
if (!schemasRet.ok()) {
LOG(ERROR) << "Get space edge schema failed";
return nebula::cpp2::ErrorCode::E_EDGE_NOT_FOUND;
}
auto schemas = schemasRet.value();

auto vidSize = vidSizeRet.value();
std::unique_ptr<kvstore::KVIterator> iter;
const auto& prefix = NebulaKeyUtils::edgePrefix(part);
Expand All @@ -53,9 +60,6 @@ nebula::cpp2::ErrorCode RebuildEdgeIndexTask::buildIndexGlobal(GraphSpaceID spac
return ret;
}

VertexID currentSrcVertex = "";
VertexID currentDstVertex = "";
EdgeRanking currentRanking = 0;
std::vector<kvstore::KV> data;
data.reserve(kReserveNum);
RowReaderWrapper reader;
Expand All @@ -67,7 +71,7 @@ nebula::cpp2::ErrorCode RebuildEdgeIndexTask::buildIndexGlobal(GraphSpaceID spac
}

if (batchSize >= FLAGS_rebuild_index_batch_size) {
auto result = writeData(space, part, data, batchSize, rateLimiter);
auto result = writeData(space, part, std::move(data), batchSize, rateLimiter);
if (result != nebula::cpp2::ErrorCode::SUCCEEDED) {
LOG(ERROR) << "Write Part " << part << " Index Failed";
return result;
Expand Down Expand Up @@ -97,15 +101,6 @@ nebula::cpp2::ErrorCode RebuildEdgeIndexTask::buildIndexGlobal(GraphSpaceID spac
auto ranking = NebulaKeyUtils::getRank(vidSize, key);
VLOG(3) << "Source " << source << " Destination " << destination << " Ranking " << ranking
<< " Edge Type " << edgeType;
if (currentSrcVertex == source && currentDstVertex == destination &&
currentRanking == ranking) {
iter->next();
continue;
} else {
currentSrcVertex = source.toString();
currentDstVertex = destination.toString();
currentRanking = ranking;
}

reader = RowReaderWrapper::getEdgePropReader(env_->schemaMan_, space, edgeType, val);
if (reader == nullptr) {
Expand All @@ -114,17 +109,17 @@ nebula::cpp2::ErrorCode RebuildEdgeIndexTask::buildIndexGlobal(GraphSpaceID spac
continue;
}

auto schema = env_->schemaMan_->getEdgeSchema(space, edgeType);
if (!schema) {
auto schemaIter = schemas.find(edgeType);
if (schemaIter == schemas.end()) {
LOG(WARNING) << "Space " << space << ", edge " << edgeType << " invalid";
iter->next();
continue;
}
auto* schema = schemaIter->second.get();

auto ttlProp = CommonUtils::ttlProps(schema.get());
if (ttlProp.first &&
CommonUtils::checkDataExpiredForTTL(
schema.get(), reader.get(), ttlProp.second.second, ttlProp.second.first)) {
auto ttlProp = CommonUtils::ttlProps(schema);
if (ttlProp.first && CommonUtils::checkDataExpiredForTTL(
schema, reader.get(), ttlProp.second.second, ttlProp.second.first)) {
VLOG(3) << "ttl expired : "
<< "Source " << source << " Destination " << destination << " Ranking " << ranking
<< " Edge Type " << edgeType;
Expand All @@ -134,7 +129,7 @@ nebula::cpp2::ErrorCode RebuildEdgeIndexTask::buildIndexGlobal(GraphSpaceID spac

std::string indexVal = "";
if (ttlProp.first) {
auto ttlValRet = CommonUtils::ttlValue(schema.get(), reader.get());
auto ttlValRet = CommonUtils::ttlValue(schema, reader.get());
if (ttlValRet.ok()) {
indexVal = IndexKeyUtils::indexVal(std::move(ttlValRet).value());
}
Expand Down
30 changes: 15 additions & 15 deletions src/storage/admin/RebuildTagIndexTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ nebula::cpp2::ErrorCode RebuildTagIndexTask::buildIndexGlobal(GraphSpaceID space
tagIds.emplace(item->get_schema_id().get_tag_id());
}

auto schemasRet = env_->schemaMan_->getAllLatestVerTagSchema(space);
if (!schemasRet.ok()) {
LOG(ERROR) << "Get space tag schema failed";
return nebula::cpp2::ErrorCode::E_TAG_NOT_FOUND;
}
auto schemas = schemasRet.value();

auto vidSize = vidSizeRet.value();
std::unique_ptr<kvstore::KVIterator> iter;
auto prefix = NebulaKeyUtils::vertexPrefix(part);
Expand All @@ -53,7 +60,6 @@ nebula::cpp2::ErrorCode RebuildTagIndexTask::buildIndexGlobal(GraphSpaceID space
return ret;
}

VertexID currentVertex = "";
std::vector<kvstore::KV> data;
data.reserve(kReserveNum);
RowReaderWrapper reader;
Expand All @@ -65,7 +71,7 @@ nebula::cpp2::ErrorCode RebuildTagIndexTask::buildIndexGlobal(GraphSpaceID space
}

if (batchSize >= FLAGS_rebuild_index_batch_size) {
auto result = writeData(space, part, data, batchSize, rateLimiter);
auto result = writeData(space, part, std::move(data), batchSize, rateLimiter);
if (result != nebula::cpp2::ErrorCode::SUCCEEDED) {
LOG(ERROR) << "Write Part " << part << " Index Failed";
return result;
Expand All @@ -88,30 +94,24 @@ nebula::cpp2::ErrorCode RebuildTagIndexTask::buildIndexGlobal(GraphSpaceID space

auto vertex = NebulaKeyUtils::getVertexId(vidSize, key);
VLOG(3) << "Tag ID " << tagID << " Vertex ID " << vertex;
if (currentVertex == vertex) {
iter->next();
continue;
} else {
currentVertex = vertex.toString();
}

reader = RowReaderWrapper::getTagPropReader(env_->schemaMan_, space, tagID, val);
if (reader == nullptr) {
iter->next();
continue;
}

auto schema = env_->schemaMan_->getTagSchema(space, tagID);
if (!schema) {
auto schemaIter = schemas.find(tagID);
if (schemaIter == schemas.end()) {
LOG(WARNING) << "Space " << space << ", tag " << tagID << " invalid";
iter->next();
continue;
}
auto* schema = schemaIter->second.get();

auto ttlProp = CommonUtils::ttlProps(schema.get());
if (ttlProp.first &&
CommonUtils::checkDataExpiredForTTL(
schema.get(), reader.get(), ttlProp.second.second, ttlProp.second.first)) {
auto ttlProp = CommonUtils::ttlProps(schema);
if (ttlProp.first && CommonUtils::checkDataExpiredForTTL(
schema, reader.get(), ttlProp.second.second, ttlProp.second.first)) {
VLOG(3) << "ttl expired : "
<< "Tag ID " << tagID << " Vertex ID " << vertex;
iter->next();
Expand All @@ -120,7 +120,7 @@ nebula::cpp2::ErrorCode RebuildTagIndexTask::buildIndexGlobal(GraphSpaceID space

std::string indexVal = "";
if (ttlProp.first) {
auto ttlValRet = CommonUtils::ttlValue(schema.get(), reader.get());
auto ttlValRet = CommonUtils::ttlValue(schema, reader.get());
if (ttlValRet.ok()) {
indexVal = IndexKeyUtils::indexVal(std::move(ttlValRet).value());
}
Expand Down