diff options
author | Sanjay Ghemawat <sanjay@google.com> | 2023-01-04 18:22:18 +0000 |
---|---|---|
committer | Victor Costan <pwnall@chromium.org> | 2023-01-04 20:41:21 +0000 |
commit | fb644cb44539925a7f444b1b0314f402a456c5f4 (patch) | |
tree | 826c7c3fa6b05656675978f6b6c1907c43ff8db6 /db/db_impl.cc | |
parent | aa5479bbf47e9df86e0afbb89e6246085f22cdd4 (diff) | |
download | leveldb-fb644cb44539925a7f444b1b0314f402a456c5f4.tar.gz |
Stop future writes if a log file Close() fails.
See https://github.com/google/leveldb/issues/1081
PiperOrigin-RevId: 499519182
Diffstat (limited to 'db/db_impl.cc')
-rw-r--r-- | db/db_impl.cc | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/db/db_impl.cc b/db/db_impl.cc index 1a4e459..1ec2afb 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -1368,8 +1368,22 @@ Status DBImpl::MakeRoomForWrite(bool force) { versions_->ReuseFileNumber(new_log_number); break; } + delete log_; + + s = logfile_->Close(); + if (!s.ok()) { + // We may have lost some data written to the previous log file. + // Switch to the new log file anyway, but record as a background + // error so we do not attempt any more writes. + // + // We could perhaps attempt to save the memtable corresponding + // to log file and suppress the error if that works, but that + // would add more complexity in a critical code path. + RecordBackgroundError(s); + } delete logfile_; + logfile_ = lfile; logfile_number_ = new_log_number; log_ = new log::Writer(lfile); |