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

Fix RocksDB can't auto resume after disk quota exceeded error #628

Merged
merged 4 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
29 changes: 22 additions & 7 deletions src/event_listener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ const std::string compressType2String(const rocksdb::CompressionType type) {
return iter->second;
}

bool isDiskQuotaExceeded(const rocksdb::Status &bg_error) {
// EDQUOT: Disk quota exceeded (POSIX.1-2001)
std::string exceeded_quota_str = "Disk quota exceeded";
std::string err_msg = bg_error.ToString();

std::size_t found = err_msg.find(exceeded_quota_str);
return found != std::string::npos;
git-hulk marked this conversation as resolved.
Show resolved Hide resolved
}

void EventListener::OnCompactionCompleted(rocksdb::DB *db, const rocksdb::CompactionJobInfo &ci) {
LOG(INFO) << "[event_listener/compaction_completed] column family: " << ci.cf_name
<< ", compaction reason: " << static_cast<int>(ci.compaction_reason)
Expand Down Expand Up @@ -92,26 +101,32 @@ void EventListener::OnFlushCompleted(rocksdb::DB *db, const rocksdb::FlushJobInf
<< ", smallest seqno: " << fi.smallest_seqno;
}

void EventListener::OnBackgroundError(rocksdb::BackgroundErrorReason reason, rocksdb::Status *status) {
void EventListener::OnBackgroundError(rocksdb::BackgroundErrorReason reason, rocksdb::Status *bg_error) {
std::string reason_str;
switch (reason) {
case rocksdb::BackgroundErrorReason::kCompaction:reason_str = "compact";
case rocksdb::BackgroundErrorReason::kCompaction:
reason_str = "compact";
break;
case rocksdb::BackgroundErrorReason::kFlush:reason_str = "flush";
case rocksdb::BackgroundErrorReason::kFlush:
reason_str = "flush";
break;
case rocksdb::BackgroundErrorReason::kMemTable:reason_str = "memtable";
case rocksdb::BackgroundErrorReason::kMemTable:
reason_str = "memtable";
break;
case rocksdb::BackgroundErrorReason::kWriteCallback:reason_str = "writecallback";
case rocksdb::BackgroundErrorReason::kWriteCallback:
reason_str = "writecallback";
break;
default:
// Should not arrive here
break;
}
if (status->IsNoSpace() && status->severity() < rocksdb::Status::kFatalError) {
if ((bg_error->IsNoSpace() || isDiskQuotaExceeded(*bg_error)) &&
bg_error->severity() < rocksdb::Status::kFatalError) {
storage_->SetDBInRetryableIOError(true);
}

LOG(ERROR) << "[event_listener/background_error] reason: " << reason_str
<< ", status: " << status->ToString();
<< ", bg_error: " << bg_error->ToString();
}

void EventListener::OnTableFileDeleted(const rocksdb::TableFileDeletionInfo &info) {
Expand Down
10 changes: 6 additions & 4 deletions src/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -613,12 +613,14 @@ void Server::cron() {
}
}
// check if DB need to be resumed every minute
// rocksdb has auto resume feature after retryable io error, but the current implement can't trigger auto resume
// when the no space error is only trigger by db_->Write without any other background action (compact/flush),
// so manual trigger resume every minute after no space error to resume db under this scenario.
// Rocksdb has auto resume feature after retryable io error, earlier version(before v6.22.1) had
// bug when encounter no space error. The current version fixes the no space error issue, but it
// does not completely resolve, which still exists when encountered disk quota exceeded error.
// In order to properly handle all possible situations on rocksdb, we manually resume here
// when encountering no space error and disk quota exceeded error.
if (counter != 0 && counter % 600 == 0 && storage_->IsDBInRetryableIOError()) {
storage_->GetDB()->Resume();
LOG(INFO) << "[server] Schedule to resume DB after no space error";
LOG(INFO) << "[server] Schedule to resume DB after retryable io error";
storage_->SetDBInRetryableIOError(false);
}

Expand Down