rocksdb/utilities
Peter Dillinger 27f3af5966 Fix serious FSDirectory use-after-Close bug (missing fsync) (#10460)
Summary:
TL;DR: due to a recent change, if you drop a column family,
often that DB will no longer fsync after writing new SST files
to remaining or new column families, which could lead to data
loss on power loss.

More bug detail:
The intent of https://github.com/facebook/rocksdb/issues/10049 was to Close FSDirectory objects at
DB::Close time rather than waiting for DB object destruction.
Unfortunately, it also closes shared FSDirectory objects on
DropColumnFamily (& destroy remaining handles), which can lead
to use-after-Close on FSDirectory shared with remaining column
families. Those "uses" are only Fsyncs (or redundant Closes). In
the default Posix filesystem, an Fsync on a closed FSDirectory is a
quiet no-op. Consequently (under most configurations), if you drop
a column family, that DB will no longer fsync after writing new SST
files to column families sharing the same directory (true under most
configurations).

More fix detail:
Basically, this removes unnecessary Close ops on destroying
ColumnFamilyData. We let `shared_ptr` take care of calling the
destructor at the right time. If the intent was to require Close be
called before destroying FSDirectory, that was not made clear by the
author of FileSystem and was not at all enforced by https://github.com/facebook/rocksdb/issues/10049, which
could have added `assert(fd_ == -1)` to `~PosixDirectory()` but did
not. To keep this fix simple, we relax the unit test for https://github.com/facebook/rocksdb/issues/10049 to allow
timely destruction of FSDirectory to suffice as Close (in
CountedFileSystem). Added a TODO to revisit that.

Also in this PR:
* Added a TODO to share FSDirectory instances between DB and its column
families. (Already shared among column families.)
* Made DB::Close attempt to close all its open FSDirectory objects even
if there is a failure in closing one. Also code clean-up around this
logic.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/10460

Test Plan:
add an assert to check for use-after-Close. With that
existing tests can detect the misuse. With fix, tests pass (except noted
relaxing of unit test for https://github.com/facebook/rocksdb/issues/10049)

Reviewed By: ajkr

Differential Revision: D38357922

Pulled By: pdillinger

fbshipit-source-id: d42079cadbedf0a969f03389bf586b3b4e1f9137
2022-08-02 10:54:32 -07:00
..
agg_merge
backup Do not hold mutex when write keys if not necessary (#7516) 2022-07-21 13:35:36 -07:00
blob_db
cassandra
checkpoint Fix race condition with WAL tracking and FlushWAL(true /* sync */) (#10185) 2022-06-17 16:45:28 -07:00
compaction_filters
convenience
leveldb_options
memory
merge_operators
option_change_migration
options
persistent_cache Remove code that only compiles for Visual Studio versions older than 2015 (#10065) 2022-05-26 16:55:08 -07:00
simulator_cache Have Cache use Status::MemoryLimit (#10262) 2022-07-06 14:41:46 -07:00
table_properties_collectors
trace
transactions Remove Travis CI (#10407) 2022-07-22 20:16:45 -07:00
ttl
write_batch_with_index Add WriteOptions::protection_bytes_per_key (#10037) 2022-06-16 23:10:07 -07:00
cache_dump_load.cc
cache_dump_load_impl.cc Remove deprecated block-based filter (#10184) 2022-06-16 15:51:33 -07:00
cache_dump_load_impl.h Remove deprecated block-based filter (#10184) 2022-06-16 15:51:33 -07:00
compaction_filters.cc
counted_fs.cc Fix serious FSDirectory use-after-Close bug (missing fsync) (#10460) 2022-08-02 10:54:32 -07:00
counted_fs.h Explicitly closing all directory file descriptors (#10049) 2022-06-01 18:03:34 -07:00
debug.cc Add helper function to get debug type name (#10243) 2022-07-15 14:42:00 -07:00
env_mirror.cc
env_mirror_test.cc
env_timed.cc
env_timed.h
env_timed_test.cc
fault_injection_env.cc Explicitly closing all directory file descriptors (#10049) 2022-06-01 18:03:34 -07:00
fault_injection_env.h Explicitly closing all directory file descriptors (#10049) 2022-06-01 18:03:34 -07:00
fault_injection_fs.cc Explicitly closing all directory file descriptors (#10049) 2022-06-01 18:03:34 -07:00
fault_injection_fs.h Explicitly closing all directory file descriptors (#10049) 2022-06-01 18:03:34 -07:00
fault_injection_secondary_cache.cc
fault_injection_secondary_cache.h
memory_allocators.h
merge_operators.cc
merge_operators.h
object_registry.cc
object_registry_test.cc
util_merge_operators_test.cc
wal_filter.cc