rocksdb/env
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
..
composite_env.cc Explicitly closing all directory file descriptors (#10049) 2022-06-01 18:03:34 -07:00
composite_env_wrapper.h Support reservation in thread pool (#10278) 2022-07-08 19:48:09 -07:00
emulated_clock.h Make SystemClock into a Customizable Class (#8636) 2021-09-21 09:23:48 -07:00
env.cc Explicitly closing all directory file descriptors (#10049) 2022-06-01 18:03:34 -07:00
env_basic_test.cc Make SystemClock into a Customizable Class (#8636) 2021-09-21 09:23:48 -07:00
env_chroot.cc Make FileSystem a Customizable Class (#8649) 2021-11-02 09:07:11 -07:00
env_chroot.h Make FileSystem a Customizable Class (#8649) 2021-11-02 09:07:11 -07:00
env_encryption.cc Added GetFactoryCount/Names/Types to ObjectRegistry (#9358) 2022-05-16 09:44:43 -07:00
env_encryption_ctr.h Added GetFactoryCount/Names/Types to ObjectRegistry (#9358) 2022-05-16 09:44:43 -07:00
env_posix.cc Use EnvLogger instead of PosixLogger (#10436) 2022-08-01 14:37:18 -07:00
env_test.cc Remove Travis CI (#10407) 2022-07-22 20:16:45 -07:00
file_system.cc Use EnvLogger instead of PosixLogger (#10436) 2022-08-01 14:37:18 -07:00
file_system_tracer.cc Provide support for IOTracing for ReadAsync API (#9833) 2022-05-25 19:47:03 -07:00
file_system_tracer.h Provide support for IOTracing for ReadAsync API (#9833) 2022-05-25 19:47:03 -07:00
fs_posix.cc Use EnvLogger instead of PosixLogger (#10436) 2022-08-01 14:37:18 -07:00
fs_readonly.h Make FileSystem a Customizable Class (#8649) 2021-11-02 09:07:11 -07:00
fs_remap.cc Continue to deflake BackupEngineTest.Concurrency (#10228) 2022-06-22 08:50:05 -07:00
fs_remap.h Make FileSystem a Customizable Class (#8649) 2021-11-02 09:07:11 -07:00
io_posix.cc Fix serious FSDirectory use-after-Close bug (missing fsync) (#10460) 2022-08-02 10:54:32 -07:00
io_posix.h Fix clang error implicit conversion loses integer precision (#10323) 2022-07-07 11:35:15 -07:00
io_posix_test.cc Status check enforcement for io_posix_test and options_settable_test (#6857) 2020-05-19 19:22:28 -07:00
mock_env.cc Explicitly closing all directory file descriptors (#10049) 2022-06-01 18:03:34 -07:00
mock_env.h Make the Env class Customizable (#9293) 2022-01-04 16:45:49 -08:00
mock_env_test.cc Make SystemClock into a Customizable Class (#8636) 2021-09-21 09:23:48 -07:00
unique_id_gen.cc New stable, fixed-length cache keys (#9126) 2021-12-16 17:15:13 -08:00
unique_id_gen.h New stable, fixed-length cache keys (#9126) 2021-12-16 17:15:13 -08:00