diff --git a/db/db_test.cc b/db/db_test.cc index 7aea863f8..b81b7c08e 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -1270,6 +1270,27 @@ TEST(DBTest, Empty) { } while (ChangeOptions()); } +TEST(DBTest, WriteEmptyBatch) { + Options options; + options.env = env_; + options.write_buffer_size = 100000; + options = CurrentOptions(options); + CreateAndReopenWithCF({"pikachu"}, options); + + ASSERT_OK(Put(1, "foo", "bar")); + env_->sync_counter_.store(0); + WriteOptions wo; + wo.sync = true; + wo.disableWAL = false; + WriteBatch empty_batch; + ASSERT_OK(dbfull()->Write(wo, &empty_batch)); + ASSERT_GE(env_->sync_counter_.load(), 1); + + // make sure we can re-open it. + ASSERT_OK(TryReopenWithColumnFamilies({"default", "pikachu"}, options)); + ASSERT_EQ("bar", Get(1, "foo")); +} + TEST(DBTest, ReadOnlyDB) { ASSERT_OK(Put("foo", "v1")); ASSERT_OK(Put("bar", "v2")); diff --git a/include/rocksdb/db.h b/include/rocksdb/db.h index 21fa43838..65b517f54 100644 --- a/include/rocksdb/db.h +++ b/include/rocksdb/db.h @@ -195,6 +195,8 @@ class DB { } // Apply the specified updates to the database. + // If `updates` contains no update, WAL will still be synced if + // options.sync=true. // Returns OK on success, non-OK on failure. // Note: consider setting options.sync = true. virtual Status Write(const WriteOptions& options, WriteBatch* updates) = 0;