diff --git a/db/db_impl.cc b/db/db_impl.cc index 597be5739a..db04e29f74 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -2020,12 +2020,13 @@ void DBImpl::MarkLogsSynced( assert(log.getting_synced); if (status.ok() && logs_.size() > 1) { logs_to_free_.push_back(log.ReleaseWriter()); - logs_.erase(it++); + it = logs_.erase(it); } else { log.getting_synced = false; ++it; } } + assert(logs_.empty() || (logs_.size() == 1 && !logs_[0].getting_synced)); log_sync_cv_.SignalAll(); } diff --git a/db/db_test.cc b/db/db_test.cc index 0646e01293..788414a2ac 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -4745,6 +4745,30 @@ TEST_F(DBTest, PurgeInfoLogs) { } } +TEST_F(DBTest, SyncMultipleLogs) { + const uint64_t kNumBatches = 2; + const int kBatchSize = 1000; + + Options options = CurrentOptions(); + options.create_if_missing = true; + options.write_buffer_size = 4096; + Reopen(options); + + WriteBatch batch; + WriteOptions wo; + wo.sync = true; + + for (uint64_t b = 0; b < kNumBatches; b++) { + batch.Clear(); + for (int i = 0; i < kBatchSize; i++) { + batch.Put(Key(i), DummyString(128)); + } + + dbfull()->Write(wo, &batch); + } + + ASSERT_OK(dbfull()->SyncWAL()); +} // // Test WAL recovery for the various modes available