This commit is contained in:
rockzheng 2025-03-10 15:15:19 +08:00 committed by GitHub
commit 77a6966e2e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1233,18 +1233,17 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* updates) {
{ {
mutex_.Unlock(); mutex_.Unlock();
status = log_->AddRecord(WriteBatchInternal::Contents(write_batch)); status = log_->AddRecord(WriteBatchInternal::Contents(write_batch));
bool sync_error = false; bool log_error = false;
if (status.ok() && options.sync) { if (status.ok() && options.sync) {
status = logfile_->Sync(); status = logfile_->Sync();
if (!status.ok()) {
sync_error = true;
}
} }
if (status.ok()) { if (status.ok()) {
status = WriteBatchInternal::InsertInto(write_batch, mem_); status = WriteBatchInternal::InsertInto(write_batch, mem_);
} else {
log_error = true;
} }
mutex_.Lock(); mutex_.Lock();
if (sync_error) { if (log_error) {
// The state of the log file is indeterminate: the log record we // The state of the log file is indeterminate: the log record we
// just added may or may not show up when the DB is re-opened. // just added may or may not show up when the DB is re-opened.
// So we force the DB into a mode where all future writes fail. // So we force the DB into a mode where all future writes fail.