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

Improved snapshot creation logic. #2318

Merged
merged 8 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
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
32 changes: 15 additions & 17 deletions src/kvstore/NebulaStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,23 +794,21 @@ ResultCode NebulaStore::setWriteBlocking(GraphSpaceID spaceId, bool sign) {
return error(partRet);
}
auto p = nebula::value(partRet);
if (p->isLeader()) {
auto ret = ResultCode::SUCCEEDED;
p->setBlocking(sign);
if (sign) {
folly::Baton<true, std::atomic> baton;
p->sync([&ret, &baton] (kvstore::ResultCode code) {
if (kvstore::ResultCode::SUCCEEDED != code) {
ret = code;
}
baton.post();
});
baton.wait();
}
if (ret != ResultCode::SUCCEEDED) {
LOG(ERROR) << "Part sync failed. space : " << spaceId << " Part : " << part;
return ret;
}
auto ret = ResultCode::SUCCEEDED;
p->setBlocking(sign);
if (sign) {
folly::Baton<true, std::atomic> baton;
p->sync([&ret, &baton] (kvstore::ResultCode code) {
if (kvstore::ResultCode::SUCCEEDED != code) {
ret = code;
}
baton.post();
});
baton.wait();
}
if (ret != ResultCode::SUCCEEDED) {
LOG(ERROR) << "Part sync failed. space : " << spaceId << " Part : " << part;
return ret;
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/kvstore/RocksEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,10 @@ ResultCode RocksEngine::createCheckpoint(const std::string& name) {
auto checkpointPath = folly::stringPrintf("%s/checkpoints/%s/data",
dataPath_.c_str(), name.c_str());
LOG(INFO) << "Target checkpoint path : " << checkpointPath;
if (fs::FileUtils::exist(checkpointPath)) {
LOG(ERROR) << "The snapshot file already exists: " << checkpointPath;
return ResultCode::ERR_CHECKPOINT_ERROR;
if (fs::FileUtils::exist(checkpointPath) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not return success?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not return success?

Because we don't have a way to verify the validity of the snapshot that has been created. For data security, I need to delete and recreate it at here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine.

!fs::FileUtils::remove(checkpointPath.data(), true)) {
LOG(ERROR) << "Remove exist dir failed of checkpoint : " << checkpointPath;
return ResultCode::ERR_IO_ERROR;
}

auto parent = checkpointPath.substr(0, checkpointPath.rfind('/'));
Expand Down
8 changes: 5 additions & 3 deletions src/kvstore/raftex/RaftPart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,10 +554,12 @@ folly::Future<AppendLogResult> RaftPart::appendLogAsync(ClusterID source,
LogType logType,
std::string log,
AtomicOp op) {
if (blocking_ && (logType == LogType::NORMAL || logType == LogType::ATOMIC_OP)) {
return AppendLogResult::E_WRITE_BLOCKING;
if (blocking_) {
// No need to block heartbeats and empty log.
if ((logType == LogType::NORMAL && !log.empty()) || logType == LogType::ATOMIC_OP) {
return AppendLogResult::E_WRITE_BLOCKING;
}
}

LogCache swappedOutLogs;
auto retFuture = folly::Future<AppendLogResult>::makeEmpty();

Expand Down
7 changes: 7 additions & 0 deletions src/kvstore/wal/FileBasedWal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,13 @@ bool FileBasedWal::linkCurrentWAL(const char* newPath) {
LOG(INFO) << idStr_ << "No wal files found, skip link";
return true;
}

if (fs::FileUtils::exist(newPath) &&
!fs::FileUtils::remove(newPath, true)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

LOG(ERROR) << "Remove exist dir failed of wal : " << newPath;
return false;
}

if (!fs::FileUtils::makeDir(newPath)) {
LOG(INFO) << idStr_ << "Link file parent dir make failed : " << newPath;
return false;
Expand Down
10 changes: 3 additions & 7 deletions src/meta/processors/admin/AdminClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,13 +600,9 @@ folly::Future<Status> AdminClient::createSnapshot(GraphSpaceID spaceId,
folly::Promise<Status> pro;
auto f = pro.getFuture();

/**
* Don't need retry.
* Because existing checkpoint directories leads to fail again.
**/
getResponse({host}, 0, std::move(req), [] (auto client, auto request) {
return client->future_createCheckpoint(request);
}, 0, std::move(pro), 0);
}, 0, std::move(pro), 3 /*The snapshot operation need to retry 3 times*/);
return f;
}

Expand All @@ -625,7 +621,7 @@ folly::Future<Status> AdminClient::dropSnapshot(GraphSpaceID spaceId,
auto f = pro.getFuture();
getResponse({host}, 0, std::move(req), [] (auto client, auto request) {
return client->future_dropCheckpoint(request);
}, 0, std::move(pro), 1 /*The snapshot operation only needs to be retried twice*/);
}, 0, std::move(pro), 3 /*The snapshot operation need to retry 3 times*/);
return f;
}

Expand All @@ -640,7 +636,7 @@ folly::Future<Status> AdminClient::blockingWrites(GraphSpaceID spaceId,
auto f = pro.getFuture();
getResponse({host}, 0, std::move(req), [] (auto client, auto request) {
return client->future_blockingWrites(request);
}, 0, std::move(pro), 1 /*The blocking needs to be retried twice*/);
}, 0, std::move(pro), 32 /*The blocking need to retry 32 times*/);
return f;
}

Expand Down
1 change: 0 additions & 1 deletion src/meta/processors/admin/CreateSnapshotProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace nebula {
namespace meta {

void CreateSnapshotProcessor::process(const cpp2::CreateSnapshotReq&) {
folly::SharedMutex::ReadHolder rHolder(LockUtils::spaceLock());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, 👍

// check the index rebuild. not allowed to create snapshot when index rebuilding.
auto prefix = MetaServiceUtils::rebuildIndexStatusPrefix();
std::unique_ptr<kvstore::KVIterator> iter;
Expand Down