Bypass buffer in TestFSWritableFile if direct IO is enabled (#8490)
Summary: ```TestFSWritableFile``` buffers data in ```Append``` in order to simulate unsynced data loss on crash. This is only required for buffered IO and should be disabled for direct IO. Otherwise, it causes crash tests to assert on the buffer address alignment - ```db_stress: env/io_posix.cc:1194: virtual rocksdb::IOStatus rocksdb::PosixWritableFile::Append(const rocksdb::Slice&, const rocksdb::IOOptions&, rocksdb::IODebugContext*): Assertion `IsSectorAligned(data.data(), GetRequiredBufferAlignment())' failed.```. Pull Request resolved: https://github.com/facebook/rocksdb/pull/8490 Reviewed By: zhichao-cao Differential Revision: D29565080 Pulled By: anand1976 fbshipit-source-id: 682831fd66ed3b9597caa74fc453e22dfaf9b973
This commit is contained in:
parent
fcd8088333
commit
df4197ca6e
@ -124,15 +124,19 @@ TestFSWritableFile::~TestFSWritableFile() {
|
||||
}
|
||||
}
|
||||
|
||||
IOStatus TestFSWritableFile::Append(const Slice& data, const IOOptions&,
|
||||
IODebugContext*) {
|
||||
IOStatus TestFSWritableFile::Append(const Slice& data, const IOOptions& options,
|
||||
IODebugContext* dbg) {
|
||||
MutexLock l(&mutex_);
|
||||
if (!fs_->IsFilesystemActive()) {
|
||||
return fs_->GetError();
|
||||
}
|
||||
state_.buffer_.append(data.data(), data.size());
|
||||
state_.pos_ += data.size();
|
||||
fs_->WritableFileAppended(state_);
|
||||
if (target_->use_direct_io()) {
|
||||
target_->Append(data, options, dbg).PermitUncheckedError();
|
||||
} else {
|
||||
state_.buffer_.append(data.data(), data.size());
|
||||
state_.pos_ += data.size();
|
||||
fs_->WritableFileAppended(state_);
|
||||
}
|
||||
IOStatus io_s = fs_->InjectWriteError(state_.filename_);
|
||||
return io_s;
|
||||
}
|
||||
@ -212,7 +216,9 @@ IOStatus TestFSWritableFile::Close(const IOOptions& options,
|
||||
}
|
||||
writable_file_opened_ = false;
|
||||
IOStatus io_s;
|
||||
io_s = target_->Append(state_.buffer_, options, dbg);
|
||||
if (!target_->use_direct_io()) {
|
||||
io_s = target_->Append(state_.buffer_, options, dbg);
|
||||
}
|
||||
if (io_s.ok()) {
|
||||
state_.buffer_.resize(0);
|
||||
// Ignore sync errors
|
||||
@ -244,6 +250,11 @@ IOStatus TestFSWritableFile::Sync(const IOOptions& options,
|
||||
if (!fs_->IsFilesystemActive()) {
|
||||
return fs_->GetError();
|
||||
}
|
||||
if (target_->use_direct_io()) {
|
||||
// For Direct IO mode, we don't buffer anything in TestFSWritableFile.
|
||||
// So just return
|
||||
return IOStatus::OK();
|
||||
}
|
||||
IOStatus io_s = target_->Append(state_.buffer_, options, dbg);
|
||||
state_.buffer_.resize(0);
|
||||
// Ignore sync errors
|
||||
|
Loading…
Reference in New Issue
Block a user