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

Flush rocksdb before clean expired wal #2128

Merged
merged 3 commits into from
May 15, 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
16 changes: 16 additions & 0 deletions src/kvstore/NebulaStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ DEFINE_string(engine_type, "rocksdb", "rocksdb, memory...");
DEFINE_int32(custom_filter_interval_secs, 24 * 3600, "interval to trigger custom compaction");
DEFINE_int32(num_workers, 4, "Number of worker threads");
DEFINE_bool(check_leader, true, "Check leader or not");
DEFINE_int32(clean_wal_interval_secs, 600, "inerval to trigger clean expired wal");

namespace nebula {
namespace kvstore {
Expand Down Expand Up @@ -185,6 +186,8 @@ bool NebulaStore::init() {
}
}

bgWorkers_->addDelayTask(FLAGS_clean_wal_interval_secs * 1000, &NebulaStore::cleanWAL, this);

LOG(INFO) << "Register handler...";
options_.partMan_->registerHandler(this);
return true;
Expand Down Expand Up @@ -820,6 +823,19 @@ bool NebulaStore::checkLeader(std::shared_ptr<Part> part) const {
return !FLAGS_check_leader || (part->isLeader() && part->leaseValid());
}

void NebulaStore::cleanWAL() {
for (const auto& spaceEntry : spaces_) {
for (const auto& engine : spaceEntry.second->engines_) {
engine->flush();
}
for (const auto& partEntry : spaceEntry.second->parts_) {
auto& part = partEntry.second;
if (part->needToCleanWal()) {
part->wal()->cleanWAL();
}
}
}
}

} // namespace kvstore
} // namespace nebula
Expand Down
2 changes: 2 additions & 0 deletions src/kvstore/NebulaStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ class NebulaStore : public KVStore, public Handler {

bool checkLeader(std::shared_ptr<Part> part) const;

void cleanWAL();

private:
// The lock used to protect spaces_
folly::RWSpinLock lock_;
Expand Down
3 changes: 0 additions & 3 deletions src/kvstore/raftex/RaftPart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1223,9 +1223,6 @@ void RaftPart::statusPolling() {
LOG(INFO) << idStr_ << "Clean up the snapshot";
cleanupSnapshot();
}
if (needToCleanWal()) {
wal_->cleanWAL(FLAGS_wal_ttl);
}
{
std::lock_guard<std::mutex> g(raftLock_);
if (status_ == Status::RUNNING || status_ == Status::WAITING_SNAPSHOT) {
Expand Down
4 changes: 2 additions & 2 deletions src/kvstore/raftex/RaftPart.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ class RaftPart : public std::enable_shared_from_this<RaftPart> {

bool leaseValid();

bool needToCleanWal();

protected:
// Protected constructor to prevent from instantiating directly
RaftPart(ClusterID clusterId,
Expand Down Expand Up @@ -332,8 +334,6 @@ class RaftPart : public std::enable_shared_from_this<RaftPart> {

void cleanupSnapshot();

bool needToCleanWal();

// The method sends out AskForVote request
// It return true if a leader is elected, otherwise returns false
bool leaderElection();
Expand Down