Log SubCode and Severity for RocksDB erros (#5515)

This commit is contained in:
yao-xiao-github 2021-08-31 21:03:02 -07:00 committed by GitHub
parent 75d7260597
commit f7842ff3db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 6 deletions

View File

@ -181,6 +181,14 @@ ACTOR Future<Void> rocksDBMetricLogger(std::shared_ptr<rocksdb::Statistics> stat
}
}
void logRocksDBError(const rocksdb::Status& status, const std::string& method) {
TraceEvent e(SevError, "RocksDBError");
e.detail("Error", status.ToString()).detail("Method", method).detail("RocksDBSeverity", status.severity());
if (status.IsIOError()) {
e.detail("SubCode", status.subcode());
}
}
Error statusToError(const rocksdb::Status& s) {
if (s.IsIOError()) {
return io_error();
@ -224,7 +232,7 @@ struct RocksDBKeyValueStore : IKeyValueStore {
auto options = getOptions();
auto status = rocksdb::DB::Open(options, a.path, defaultCF, &handle, &db);
if (!status.ok()) {
TraceEvent(SevError, "RocksDBError").detail("Error", status.ToString()).detail("Method", "Open");
logRocksDBError(status, "Open");
a.done.sendError(statusToError(status));
} else {
TraceEvent(SevInfo, "RocksDB").detail("Path", a.path).detail("Method", "Open");
@ -266,7 +274,7 @@ struct RocksDBKeyValueStore : IKeyValueStore {
options.sync = !SERVER_KNOBS->ROCKSDB_UNSAFE_AUTO_FSYNC;
auto s = db->Write(options, a.batchToCommit.get());
if (!s.ok()) {
TraceEvent(SevError, "RocksDBError").detail("Error", s.ToString()).detail("Method", "Commit");
logRocksDBError(s, "Commit");
a.done.sendError(statusToError(s));
} else {
a.done.send(Void());
@ -292,14 +300,14 @@ struct RocksDBKeyValueStore : IKeyValueStore {
}
auto s = db->Close();
if (!s.ok()) {
TraceEvent(SevError, "RocksDBError").detail("Error", s.ToString()).detail("Method", "Close");
logRocksDBError(s, "Close");
}
if (a.deleteOnClose) {
std::vector<rocksdb::ColumnFamilyDescriptor> defaultCF = { rocksdb::ColumnFamilyDescriptor{
"default", getCFOptions() } };
s = rocksdb::DestroyDB(a.path, getOptions(), defaultCF);
if (!s.ok()) {
TraceEvent(SevError, "RocksDBError").detail("Error", s.ToString()).detail("Method", "Destroy");
logRocksDBError(s, "Destroy");
} else {
TraceEvent(SevInfo, "RocksDB").detail("Path", a.path).detail("Method", "Destroy");
}
@ -420,7 +428,7 @@ struct RocksDBKeyValueStore : IKeyValueStore {
} else if (s.IsNotFound()) {
a.result.send(Optional<Value>());
} else {
TraceEvent(SevError, "RocksDBError").detail("Error", s.ToString()).detail("Method", "ReadValuePrefix");
logRocksDBError(s, "ReadValuePrefix");
a.result.sendError(statusToError(s));
}
}
@ -512,7 +520,7 @@ struct RocksDBKeyValueStore : IKeyValueStore {
}
if (!s.ok()) {
TraceEvent(SevError, "RocksDBError").detail("Error", s.ToString()).detail("Method", "ReadRange");
logRocksDBError(s, "ReadRange");
a.result.sendError(statusToError(s));
return;
}