Skip to content

Commit b7cd1fd

Browse files
Xingbo Wangfacebook-github-bot
authored andcommitted
Track FSRandomRWFile open/close in Fault injection fs (facebook#13771)
Summary: The Stress test was broken due to a change in switching from ReopenWritableFile to FSRandomRWFile for sync linked file in external Sst ingestion job. The Stress test is using FaultInjectionFs, which tracks the opening of ReopenWritableFile properly, but does not track FSRandomRWFile properly. This change fixes the tracking of FSRandomRWFile in FaultInjectionFs. Pull Request resolved: facebook#13771 Test Plan: unit test, stress test Reviewed By: mszeszko-meta Differential Revision: D78282719 Pulled By: xingbowang fbshipit-source-id: f8f2ed8a5b28a76836f75effbdfa2c3bb172dc51
1 parent 6c267a3 commit b7cd1fd

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

utilities/fault_injection_fs.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,10 @@ IOStatus TestFSWritableFile::RangeSync(uint64_t offset, uint64_t nbytes,
399399
return io_s;
400400
}
401401

402-
TestFSRandomRWFile::TestFSRandomRWFile(const std::string& /*fname*/,
402+
TestFSRandomRWFile::TestFSRandomRWFile(const std::string& fname,
403403
std::unique_ptr<FSRandomRWFile>&& f,
404404
FaultInjectionTestFS* fs)
405-
: target_(std::move(f)), file_opened_(true), fs_(fs) {
405+
: fname_(fname), target_(std::move(f)), file_opened_(true), fs_(fs) {
406406
assert(target_ != nullptr);
407407
}
408408

@@ -433,6 +433,7 @@ IOStatus TestFSRandomRWFile::Read(uint64_t offset, size_t n,
433433

434434
IOStatus TestFSRandomRWFile::Close(const IOOptions& options,
435435
IODebugContext* dbg) {
436+
fs_->RandomRWFileClosed(fname_);
436437
if (!fs_->IsFilesystemActive()) {
437438
return fs_->GetError();
438439
}
@@ -1273,6 +1274,13 @@ IOStatus FaultInjectionTestFS::AbortIO(std::vector<void*>& io_handles) {
12731274
return target()->AbortIO(io_handles);
12741275
}
12751276

1277+
void FaultInjectionTestFS::RandomRWFileClosed(const std::string& fname) {
1278+
MutexLock l(&mutex_);
1279+
if (open_managed_files_.find(fname) != open_managed_files_.end()) {
1280+
open_managed_files_.erase(fname);
1281+
}
1282+
}
1283+
12761284
void FaultInjectionTestFS::WritableFileClosed(const FSFileState& state) {
12771285
MutexLock l(&mutex_);
12781286
if (open_managed_files_.find(state.filename_) != open_managed_files_.end()) {

utilities/fault_injection_fs.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ class TestFSWritableFile : public FSWritableFile {
106106
const bool unsync_data_loss_;
107107
};
108108

109-
// A wrapper around WritableFileWriter* file
110-
// is written to or sync'ed.
109+
// A wrapper around FSRandomRWFile* file
110+
// is read from/write to or sync'ed.
111111
class TestFSRandomRWFile : public FSRandomRWFile {
112112
public:
113113
explicit TestFSRandomRWFile(const std::string& fname,
@@ -128,6 +128,9 @@ class TestFSRandomRWFile : public FSRandomRWFile {
128128
bool use_direct_io() const override { return target_->use_direct_io(); }
129129

130130
private:
131+
// keep a copy of file name, so we can untrack it in File system, when it is
132+
// closed
133+
std::string fname_;
131134
std::unique_ptr<FSRandomRWFile> target_;
132135
bool file_opened_;
133136
FaultInjectionTestFS* fs_;
@@ -341,6 +344,8 @@ class FaultInjectionTestFS : public FileSystemWrapper {
341344

342345
void WritableFileAppended(const FSFileState& state);
343346

347+
void RandomRWFileClosed(const std::string& fname);
348+
344349
IOStatus DropUnsyncedFileData();
345350

346351
IOStatus DropRandomUnsyncedFileData(Random* rnd);

0 commit comments

Comments
 (0)