1. add macosx fix

This commit is contained in:
zhanglistar 2021-11-12 15:49:21 +08:00
parent 572aec481a
commit 4e7823ade7
5 changed files with 26 additions and 6 deletions

View File

@ -542,8 +542,13 @@ public:
file_path,
std::to_string(bytes_written));
if (::fdatasync(file.fd) < 0)
throwFromErrnoWithPath("Cannot fsync " + file_path, file_path, ErrorCodes::CANNOT_FSYNC);
#if defined(OS_DARWIN)
if (::fsync(file.fd) < 0)
throwFromErrnoWithPath("Cannot fsync " + file_path, file_path, ErrorCodes::CANNOT_FSYNC);
#else
if (::fdatasync(file.fd) < 0)
throwFromErrnoWithPath("Cannot fdatasync " + file_path, file_path, ErrorCodes::CANNOT_FSYNC);
#endif
current_block_index += buffer_size_in_blocks;

View File

@ -34,10 +34,10 @@ LocalDirectorySyncGuard::~LocalDirectorySyncGuard()
#if defined(OS_DARWIN)
if (fcntl(fd, F_FULLFSYNC, 0))
throwFromErrno("Cannot fcntl(F_FULLFSYNC)", ErrorCodes::CANNOT_FSYNC);
#endif
#else
if (-1 == ::fdatasync(fd))
throw Exception("Cannot fsync", ErrorCodes::CANNOT_FSYNC);
throw Exception("Cannot fdatasync", ErrorCodes::CANNOT_FSYNC);
#endif
if (-1 == ::close(fd))
throw Exception("Cannot close file", ErrorCodes::CANNOT_CLOSE_FILE);
}

View File

@ -114,7 +114,11 @@ void WriteBufferFromFileDescriptor::sync()
next();
/// Request OS to sync data with storage medium.
#if defined(OS_DARWIN)
int res = ::fsync(fd);
#else
int res = ::fdatasync(fd);
#endif
if (-1 == res)
throwFromErrnoWithPath("Cannot fsync " + getFileName(), getFileName(), ErrorCodes::CANNOT_FSYNC);
}

View File

@ -156,7 +156,11 @@ int mainImpl(int argc, char ** argv)
pool.scheduleOrThrowOnError([=]{ thread(fd, mode, min_offset, max_offset, block_size, count); });
pool.wait();
fdatasync(fd);
#if defined(OS_DARWIN)
fsync(fd);
#else
fdatasync(fd);
#endif
watch.stop();

View File

@ -136,6 +136,13 @@ int mainImpl(int argc, char ** argv)
for (size_t i = 0; i < descriptors; ++i)
{
#if defined(OS_DARWIN)
if (fsync(fds[i]))
throwFromErrno("Cannot fsync", ErrorCodes::CANNOT_FSYNC);
#else
if (fdatasync(fds[i]))
throwFromErrno("Cannot fdatasync", ErrorCodes::CANNOT_FSYNC);
#endif
if (fdatasync(fds[i]))
throwFromErrno("Cannot fsync", ErrorCodes::CANNOT_FSYNC);
}