-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add F_BARRIERFSYNC for Sync operations on MacOS #319
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,47 @@ int Madvise(void* addr, size_t len, int advice) { | |
} | ||
|
||
namespace { | ||
IOStatus PosixSync(int fd, const std::string& file_name, | ||
const char* file_type) { | ||
#if defined(HAVE_BARRIERFSYNC) | ||
if (::fcntl(fd, F_BARRIERFSYNC) < 0) { | ||
std::string message = "while fcntl(F_BARRIERFSYNC) "; | ||
return IOError(message + file_type, file_name, errno); | ||
} | ||
#elif defined(HAVE_FULLFSYNC) | ||
if (::fcntl(fd, F_FULLFSYNC) < 0) { | ||
std::string message = "while fcntl(F_FULLFSYNC) "; | ||
return IOError(message + file_type, file_name, errno); | ||
} | ||
#else // HAVE_FULLFSYNC | ||
if (fdatasync(fd) < 0) { | ||
std::string message = "While fdatasync "; | ||
return IOError(message + file_type, file_name, errno); | ||
} | ||
#endif // HAVE_FULLFSYNC | ||
return IOStatus::OK(); | ||
} | ||
|
||
IOStatus PosixFSync(int fd, const std::string& file_name, | ||
const char* file_type) { | ||
#if defined(HAVE_FULLFSYNC) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the same code as above |
||
if (::fcntl(fd, F_FULLFSYNC) < 0) { | ||
std::string message = "while fcntl(F_FULLSYNC) "; | ||
return IOError(message + file_type, file_name, errno); | ||
} | ||
#elif defined(HAVE_BARRIERFSYNC) | ||
if (::fcntl(fd, F_BARRIERFSYNC) < 0) { | ||
std::string message = "while fcntl(F_BARRIERFSYNC) "; | ||
return IOError(message + file_type, file_name, errno); | ||
} | ||
#else // HAVE_FULLFSYNC | ||
if (fsync(fd) < 0) { | ||
std::string message = "While fsync "; | ||
return IOError(message + file_type, file_name, errno); | ||
} | ||
#endif // HAVE_FULLFSYNC | ||
return IOStatus::OK(); | ||
} | ||
|
||
// On MacOS (and probably *BSD), the posix write and pwrite calls do not support | ||
// buffers larger than 2^31-1 bytes. These two wrappers fix this issue by | ||
|
@@ -1182,35 +1223,25 @@ IOStatus PosixMmapFile::Flush(const IOOptions& /*opts*/, | |
|
||
IOStatus PosixMmapFile::Sync(const IOOptions& /*opts*/, | ||
IODebugContext* /*dbg*/) { | ||
#ifdef HAVE_FULLFSYNC | ||
if (::fcntl(fd_, F_FULLFSYNC) < 0) { | ||
return IOError("while fcntl(F_FULLSYNC) mmapped file", filename_, errno); | ||
} | ||
#else // HAVE_FULLFSYNC | ||
if (fdatasync(fd_) < 0) { | ||
return IOError("While fdatasync mmapped file", filename_, errno); | ||
IOStatus s = PosixSync(fd_, filename_, "mmapped file"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to call generic PosixSync with fsync false |
||
if (!s.ok()) { | ||
return s; | ||
} else { | ||
return Msync(); | ||
} | ||
#endif // HAVE_FULLFSYNC | ||
|
||
return Msync(); | ||
} | ||
|
||
/** | ||
* Flush data as well as metadata to stable storage. | ||
*/ | ||
IOStatus PosixMmapFile::Fsync(const IOOptions& /*opts*/, | ||
IODebugContext* /*dbg*/) { | ||
#ifdef HAVE_FULLFSYNC | ||
if (::fcntl(fd_, F_FULLFSYNC) < 0) { | ||
return IOError("While fcntl(F_FULLSYNC) on mmaped file", filename_, errno); | ||
} | ||
#else // HAVE_FULLFSYNC | ||
if (fsync(fd_) < 0) { | ||
return IOError("While fsync mmaped file", filename_, errno); | ||
auto s = PosixFSync(fd_, filename_, "mmapped file"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to call generic PosixSync with fsync true |
||
if (!s.ok()) { | ||
return s; | ||
} else { | ||
return Msync(); | ||
} | ||
#endif // HAVE_FULLFSYNC | ||
|
||
return Msync(); | ||
} | ||
|
||
/** | ||
|
@@ -1400,30 +1431,12 @@ IOStatus PosixWritableFile::Flush(const IOOptions& /*opts*/, | |
|
||
IOStatus PosixWritableFile::Sync(const IOOptions& /*opts*/, | ||
IODebugContext* /*dbg*/) { | ||
#ifdef HAVE_FULLFSYNC | ||
if (::fcntl(fd_, F_FULLFSYNC) < 0) { | ||
return IOError("while fcntl(F_FULLFSYNC)", filename_, errno); | ||
} | ||
#else // HAVE_FULLFSYNC | ||
if (fdatasync(fd_) < 0) { | ||
return IOError("While fdatasync", filename_, errno); | ||
} | ||
#endif // HAVE_FULLFSYNC | ||
return IOStatus::OK(); | ||
return PosixSync(fd_, filename_, ""); | ||
} | ||
|
||
IOStatus PosixWritableFile::Fsync(const IOOptions& /*opts*/, | ||
IODebugContext* /*dbg*/) { | ||
#ifdef HAVE_FULLFSYNC | ||
if (::fcntl(fd_, F_FULLFSYNC) < 0) { | ||
return IOError("while fcntl(F_FULLFSYNC)", filename_, errno); | ||
} | ||
#else // HAVE_FULLFSYNC | ||
if (fsync(fd_) < 0) { | ||
return IOError("While fsync", filename_, errno); | ||
} | ||
#endif // HAVE_FULLFSYNC | ||
return IOStatus::OK(); | ||
return PosixFSync(fd_, filename_, ""); | ||
} | ||
|
||
bool PosixWritableFile::IsSyncThreadSafe() const { return true; } | ||
|
@@ -1595,30 +1608,12 @@ IOStatus PosixRandomRWFile::Flush(const IOOptions& /*opts*/, | |
|
||
IOStatus PosixRandomRWFile::Sync(const IOOptions& /*opts*/, | ||
IODebugContext* /*dbg*/) { | ||
#ifdef HAVE_FULLFSYNC | ||
if (::fcntl(fd_, F_FULLFSYNC) < 0) { | ||
return IOError("while fcntl(F_FULLFSYNC) random rw file", filename_, errno); | ||
} | ||
#else // HAVE_FULLFSYNC | ||
if (fdatasync(fd_) < 0) { | ||
return IOError("While fdatasync random read/write file", filename_, errno); | ||
} | ||
#endif // HAVE_FULLFSYNC | ||
return IOStatus::OK(); | ||
return PosixSync(fd_, filename_, "random read/write file"); | ||
} | ||
|
||
IOStatus PosixRandomRWFile::Fsync(const IOOptions& /*opts*/, | ||
IODebugContext* /*dbg*/) { | ||
#ifdef HAVE_FULLFSYNC | ||
if (::fcntl(fd_, F_FULLFSYNC) < 0) { | ||
return IOError("While fcntl(F_FULLSYNC) random rw file", filename_, errno); | ||
} | ||
#else // HAVE_FULLFSYNC | ||
if (fsync(fd_) < 0) { | ||
return IOError("While fsync random read/write file", filename_, errno); | ||
} | ||
#endif // HAVE_FULLFSYNC | ||
return IOStatus::OK(); | ||
return PosixFSync(fd_, filename_, "random read/write file"); | ||
} | ||
|
||
IOStatus PosixRandomRWFile::Close(const IOOptions& /*opts*/, | ||
|
@@ -1713,18 +1708,9 @@ IOStatus PosixDirectory::FsyncWithDirOptions( | |
// skip fsync/fcntl when fd_ == -1 since this file descriptor has been closed | ||
// in either the de-construction or the close function, data must have been | ||
// fsync-ed before de-construction and close is called | ||
#ifdef HAVE_FULLFSYNC | ||
// btrfs is a Linux file system, while currently F_FULLFSYNC is available on | ||
// Mac OS. | ||
assert(!is_btrfs_); | ||
if (fd_ != -1 && ::fcntl(fd_, F_FULLFSYNC) < 0) { | ||
return IOError("while fcntl(F_FULLFSYNC)", "a directory", errno); | ||
if (fd_ != -1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as my comment above |
||
s = PosixFSync(fd_, "", "a directory"); | ||
} | ||
#else // HAVE_FULLFSYNC | ||
if (fd_ != -1 && fsync(fd_) == -1) { | ||
s = IOError("While fsync", "a directory", errno); | ||
} | ||
#endif // HAVE_FULLFSYNC | ||
#endif // OS_AIX | ||
return s; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is code is the same as in the PosixFSync. do a function PosixSync that as parameter you pass if it is fsync or not and then split to the different code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about making one routine for sync/fsync, passing in an argument. But the code is NOT the same:
I thought about merging them, but the code actually ends up more complicated. If you have a code layout that is simpler, I will take it but I could not come up with one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forget. its not worth the complications. go ahead