diff --git a/port/win/env_win.cc b/port/win/env_win.cc index 87b4eb159..5073944f5 100644 --- a/port/win/env_win.cc +++ b/port/win/env_win.cc @@ -253,7 +253,7 @@ Status WinEnvIO::OpenWritableFile(const std::string& fname, DWORD fileFlags = FILE_ATTRIBUTE_NORMAL; if (local_options.use_direct_writes && !local_options.use_mmap_writes) { - fileFlags = FILE_FLAG_NO_BUFFERING; + fileFlags = FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH; } // Desired access. We are want to write only here but if we want to memory diff --git a/port/win/io_win.cc b/port/win/io_win.cc index 9403c829d..8cdd456d6 100644 --- a/port/win/io_win.cc +++ b/port/win/io_win.cc @@ -880,7 +880,7 @@ inline Status WinWritableImpl::SyncImpl() { Status s; // Calls flush buffers - if (fsync(file_data_->GetFileHandle()) < 0) { + if (!file_data_->use_direct_io() && fsync(file_data_->GetFileHandle()) < 0) { auto lastError = GetLastError(); s = IOErrorFromWindowsError( "fsync failed at Sync() for: " + file_data_->GetName(), lastError); @@ -961,7 +961,11 @@ Status WinWritableFile::Sync() { return SyncImpl(); } -Status WinWritableFile::Fsync() { return SyncImpl(); } +Status WinWritableFile::Fsync() { + return SyncImpl(); +} + +bool WinWritableFile::IsSyncThreadSafe() const { return true; } uint64_t WinWritableFile::GetFileSize() { return GetFileNextWriteOffset(); diff --git a/port/win/io_win.h b/port/win/io_win.h index 2c1d5a1ea..74a99ec93 100644 --- a/port/win/io_win.h +++ b/port/win/io_win.h @@ -368,6 +368,8 @@ class WinWritableFile : private WinFileData, virtual Status Fsync() override; + virtual bool IsSyncThreadSafe() const override; + // Indicates if the class makes use of direct I/O // Use PositionedAppend virtual bool use_direct_io() const override;