-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
add db-upgrade V3 #3417
Merged
Merged
add db-upgrade V3 #3417
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
aabff08
add db-upgrade V3
cangfengzhs 3b62a1a
Merge remote-tracking branch 'vesoft/master' into upgrade
cangfengzhs 1f51f3b
use ingest
cangfengzhs 62f7d98
Merge branch 'master' into upgrade
cangfengzhs 84a3581
modify upgrade args
cangfengzhs 3a0412b
write data version key
cangfengzhs b8c118a
Merge branch 'upgrade' of github.com:cangfengzhs/nebula into upgrade
cangfengzhs 6399d5a
address wenhao's comment
cangfengzhs 7145f6b
address some comment
cangfengzhs 7b92dab
address some comment
cangfengzhs b4c80ad
Merge branch 'master' into upgrade
Sophie-Xie 06db765
Merge remote-tracking branch 'vesoft/master' into upgrade
cangfengzhs fdbf0c4
format
cangfengzhs cd9b0e5
Merge remote-tracking branch 'origin/upgrade' into upgrade
cangfengzhs 9c2ff71
Merge branch 'master' into upgrade
Sophie-Xie 19782be
Merge branch 'master' into upgrade
Sophie-Xie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,10 @@ | |
#include "common/fs/FileUtils.h" | ||
#include "common/utils/IndexKeyUtils.h" | ||
#include "common/utils/NebulaKeyUtils.h" | ||
#include "rocksdb/sst_file_writer.h" | ||
#include "tools/db-upgrade/NebulaKeyUtilsV1.h" | ||
#include "tools/db-upgrade/NebulaKeyUtilsV2.h" | ||
#include "tools/db-upgrade/NebulaKeyUtilsV3.h" | ||
|
||
DEFINE_string(src_db_path, | ||
"", | ||
|
@@ -22,10 +24,11 @@ DEFINE_string(dst_db_path, | |
"multi paths should be split by comma"); | ||
DEFINE_string(upgrade_meta_server, "127.0.0.1:45500", "Meta servers' address."); | ||
DEFINE_uint32(write_batch_num, 100, "The size of the batch written to rocksdb"); | ||
DEFINE_uint32(upgrade_version, | ||
0, | ||
"When the value is 1, upgrade the data from 1.x to 2.0 GA. " | ||
"When the value is 2, upgrade the data from 2.0 RC to 2.0 GA."); | ||
DEFINE_string(upgrade_version, | ||
"", | ||
"When the value is 1:2, upgrade the data from 1.x to 2.0 GA. " | ||
"When the value is 2RC:2, upgrade the data from 2.0 RC to 2.0 GA." | ||
"When the value is 2:3, upgrade the data from 2.0 GA to 3.0 ."); | ||
DEFINE_bool(compactions, | ||
true, | ||
"When the upgrade of the space is completed, " | ||
|
@@ -83,7 +86,7 @@ Status UpgraderSpace::initSpace(const std::string& sId) { | |
|
||
// Use readonly rocksdb | ||
readEngine_.reset(new nebula::kvstore::RocksEngine( | ||
spaceId_, spaceVidLen_, srcPath_, "", nullptr, nullptr, true)); | ||
spaceId_, spaceVidLen_, srcPath_, "", nullptr, nullptr, false)); | ||
writeEngine_.reset(new nebula::kvstore::RocksEngine(spaceId_, spaceVidLen_, dstPath_)); | ||
|
||
parts_.clear(); | ||
|
@@ -882,6 +885,114 @@ std::string UpgraderSpace::encodeRowVal(const RowReader* reader, | |
return std::move(rowWrite).moveEncodedStr(); | ||
} | ||
|
||
void UpgraderSpace::runPartV3() { | ||
std::chrono::milliseconds take_dura{10}; | ||
if (auto pId = partQueue_.try_take_for(take_dura)) { | ||
PartitionID partId = *pId; | ||
// Handle vertex and edge, if there is an index, generate index data | ||
LOG(INFO) << "Start to handle vertex/edge/index data in space id " << spaceId_ << " part id " | ||
<< partId; | ||
auto prefix = NebulaKeyUtilsV3::partTagPrefix(partId); | ||
std::unique_ptr<kvstore::KVIterator> iter; | ||
auto retCode = readEngine_->prefix(prefix, &iter); | ||
if (retCode != nebula::cpp2::ErrorCode::SUCCEEDED) { | ||
LOG(ERROR) << "Space id " << spaceId_ << " part " << partId << " no found!"; | ||
LOG(ERROR) << "Handle vertex/edge/index data in space id " << spaceId_ << " part id " | ||
<< partId << " failed"; | ||
|
||
auto unFinishedPart = --unFinishedPart_; | ||
if (unFinishedPart == 0) { | ||
// all parts has finished | ||
LOG(INFO) << "Handle last part: " << partId << " vertex/edge/index data in space id " | ||
<< spaceId_ << " finished"; | ||
} else { | ||
pool_->add(std::bind(&UpgraderSpace::runPartV3, this)); | ||
} | ||
return; | ||
} | ||
auto write_sst = [&, this](const std::vector<kvstore::KV>& data) { | ||
::rocksdb::Options option; | ||
option.create_if_missing = true; | ||
option.compression = ::rocksdb::CompressionType::kNoCompression; | ||
::rocksdb::SstFileWriter sst_file_writer(::rocksdb::EnvOptions(), option); | ||
std::string file = ::fmt::format( | ||
".nebula_upgrade.space-{}.part-{}.{}.sst", spaceId_, partId, std::time(nullptr)); | ||
::rocksdb::Status s = sst_file_writer.Open(file); | ||
if (!s.ok()) { | ||
LOG(FATAL) << "Faild upgrade V3 of space " << spaceId_ << ", part " << partId << ":" | ||
<< s.code(); | ||
} | ||
for (auto item : data) { | ||
s = sst_file_writer.Put(item.first, item.second); | ||
if (!s.ok()) { | ||
LOG(FATAL) << "Faild upgrade V3 of space " << spaceId_ << ", part " << partId << ":" | ||
<< s.code(); | ||
} | ||
} | ||
s = sst_file_writer.Finish(); | ||
if (!s.ok()) { | ||
LOG(FATAL) << "Faild upgrade V3 of space " << spaceId_ << ", part " << partId << ":" | ||
<< s.code(); | ||
} | ||
std::lock_guard<std::mutex> lck(this->ingest_sst_file_mut_); | ||
ingest_sst_file_.push_back(file); | ||
}; | ||
std::vector<kvstore::KV> data; | ||
std::string lastVertexKey = ""; | ||
while (iter && iter->valid()) { | ||
auto vertex = NebulaKeyUtilsV3::getVertexKey(iter->key()); | ||
if (vertex == lastVertexKey) { | ||
iter->next(); | ||
continue; | ||
SuperYoko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
data.emplace_back(vertex, ""); | ||
lastVertexKey = vertex; | ||
if (data.size() >= 100000) { | ||
write_sst(data); | ||
data.clear(); | ||
} | ||
iter->next(); | ||
} | ||
if (!data.empty()) { | ||
write_sst(data); | ||
data.clear(); | ||
} | ||
LOG(INFO) << "Handle vertex/edge/index data in space id " << spaceId_ << " part id " << partId | ||
<< " succeed"; | ||
|
||
auto unFinishedPart = --unFinishedPart_; | ||
if (unFinishedPart == 0) { | ||
// all parts has finished | ||
LOG(INFO) << "Handle last part: " << partId << " vertex/edge/index data in space id " | ||
<< spaceId_ << " finished."; | ||
} else { | ||
pool_->add(std::bind(&UpgraderSpace::runPartV3, this)); | ||
} | ||
} else { | ||
LOG(INFO) << "Handle vertex/edge/index of parts data in space id " << spaceId_ << " finished"; | ||
} | ||
} | ||
void UpgraderSpace::doProcessV3() { | ||
LOG(INFO) << "Start to handle data in space id " << spaceId_; | ||
// Parallel process part | ||
auto partConcurrency = std::min(static_cast<size_t>(FLAGS_max_concurrent_parts), parts_.size()); | ||
LOG(INFO) << "Max concurrent parts: " << partConcurrency; | ||
unFinishedPart_ = parts_.size(); | ||
|
||
LOG(INFO) << "Start to handle vertex/edge/index of parts data in space id " << spaceId_; | ||
for (size_t i = 0; i < partConcurrency; ++i) { | ||
pool_->add(std::bind(&UpgraderSpace::runPartV3, this)); | ||
} | ||
|
||
while (unFinishedPart_ != 0) { | ||
sleep(10); | ||
} | ||
auto code = readEngine_->ingest(ingest_sst_file_, true); | ||
if (code != ::nebula::cpp2::ErrorCode::SUCCEEDED) { | ||
LOG(FATAL) << "Faild upgrade 2:3 when ingest sst file:" << static_cast<int>(code); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, and if ingest failed, upgrader can do nothing except crash. |
||
} | ||
readEngine_->put(NebulaKeyUtils::dataVersionKey(), NebulaKeyUtilsV3::dataVersionValue()); | ||
} | ||
std::vector<std::string> UpgraderSpace::indexVertexKeys( | ||
PartitionID partId, | ||
VertexID& vId, | ||
|
@@ -1094,10 +1205,14 @@ void DbUpgrader::doSpace() { | |
LOG(INFO) << "Upgrade from path " << upgraderSpaceIter->srcPath_ << " space id " | ||
<< upgraderSpaceIter->entry_ << " to path " << upgraderSpaceIter->dstPath_ | ||
<< " begin"; | ||
if (FLAGS_upgrade_version == 1) { | ||
if (FLAGS_upgrade_version == "1:2") { | ||
upgraderSpaceIter->doProcessV1(); | ||
} else { | ||
} else if (FLAGS_upgrade_version == "2RC:2") { | ||
upgraderSpaceIter->doProcessV2(); | ||
} else if (FLAGS_upgrade_version == "2:3") { | ||
upgraderSpaceIter->doProcessV3(); | ||
} else { | ||
LOG(FATAL) << "error upgrade version " << FLAGS_upgrade_version; | ||
} | ||
|
||
auto ret = upgraderSpaceIter->copyWal(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* Copyright (c) 2021 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License. | ||
*/ | ||
|
||
#include "tools/db-upgrade/NebulaKeyUtilsV3.h" | ||
|
||
namespace nebula { | ||
std::string NebulaKeyUtilsV3::partTagPrefix(PartitionID partId) { | ||
PartitionID item = (partId << kPartitionOffset) | static_cast<uint32_t>(kTag_); | ||
std::string key; | ||
key.reserve(sizeof(PartitionID)); | ||
key.append(reinterpret_cast<const char*>(&item), sizeof(PartitionID)); | ||
return key; | ||
} | ||
std::string NebulaKeyUtilsV3::getVertexKey(folly::StringPiece tagKey) { | ||
std::string key = tagKey.toString(); | ||
key[3] = static_cast<uint32_t>(kVertex); | ||
key.resize(key.size() - sizeof(TagID)); | ||
return key; | ||
} | ||
std::string NebulaKeyUtilsV3::dataVersionValue() { | ||
return "3.0"; | ||
} | ||
|
||
} // namespace nebula |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* Copyright (c) 2021 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License. | ||
*/ | ||
#pragma once | ||
#include "common/utils/Types.h" | ||
namespace nebula { | ||
class NebulaKeyUtilsV3 { | ||
public: | ||
static std::string partTagPrefix(PartitionID partId); | ||
static std::string getVertexKey(folly::StringPiece tagKey); | ||
static std::string dataVersionValue(); | ||
|
||
private: | ||
enum NebulaKeyTypeV3 : uint32_t { kTag_ = 0x00000001, kVertex = 0x00000007 }; | ||
}; | ||
|
||
} // namespace nebula |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This rocksdb is originally a read-only
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because upgrade to 3.0 just need append new data by ingest sst file and write a
dataVersionKey
to identity the data encode version. So there is no need to write a new rocksdb, just upgrade in placeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confused about
readEngine_.reset
a writeable oneThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
read
means source andwrite
means destnation