-
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
cleanWal by commitLogId #4015
cleanWal by commitLogId #4015
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1151,16 +1151,16 @@ void NebulaStore::cleanWAL() { | |
auto& part = partEntry.second; | ||
if (part->needToCleanWal()) { | ||
// clean wal by expired time | ||
part->wal()->cleanWAL(); | ||
part->cleanWal(); | ||
} | ||
} | ||
} | ||
for (const auto& spaceEntry : spaceListeners_) { | ||
for (const auto& partEntry : spaceEntry.second->listeners_) { | ||
for (const auto& typeEntry : partEntry.second) { | ||
const auto& listener = typeEntry.second; | ||
// clean wal by log id | ||
listener->wal()->cleanWAL(listener->getApplyId()); | ||
// clean wal by commit log id | ||
listener->cleanWal(); | ||
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.
|
||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -672,23 +672,30 @@ void FileBasedWal::cleanWAL() { | |
|
||
void FileBasedWal::cleanWAL(LogID id) { | ||
std::lock_guard<std::mutex> g(walFilesMutex_); | ||
auto now = time::WallClock::fastNowInSec(); | ||
size_t index = 0; | ||
if (walFiles_.empty()) { | ||
return; | ||
} | ||
auto size = walFiles_.size(); | ||
if (size < 2) { | ||
return; | ||
} | ||
|
||
if (walFiles_.rbegin()->second->lastId() < id) { | ||
VLOG(3) << "Try to clean wal not existed " << id << ", lastWal is " | ||
<< walFiles_.rbegin()->second->lastId(); | ||
return; | ||
} | ||
|
||
int walTTL = FLAGS_wal_ttl; | ||
// remove wal file that lastId is less than target | ||
auto iter = walFiles_.begin(); | ||
while (iter != walFiles_.end()) { | ||
if (iter->second->lastId() < id) { | ||
if (iter->second->lastId() < id && index < size - 2 && (now - iter->second->mtime() > walTTL)) { | ||
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. If we do not use walTTL to limit the cleanWAL, what will happen? 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. Then no wal would be deleted |
||
VLOG(3) << "Clean wals, Remove " << iter->second->path(); | ||
unlink(iter->second->path()); | ||
iter = walFiles_.erase(iter); | ||
index++; | ||
} else { | ||
break; | ||
} | ||
|
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.
Maybe unify all usage, either implement
cleanWAL()
inPart
andListener
, or just callpart->wal()->cleanWAL(id)
.