MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / my_sync

Function my_sync

mysys/my_sync.c:53–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51*/
52
53int my_sync(File fd, myf my_flags)
54{
55 int res;
56 DBUG_ENTER("my_sync");
57 DBUG_PRINT("my",("Fd: %d my_flags: %d", fd, my_flags));
58
59 if (before_sync_wait)
60 (*before_sync_wait)();
61 do
62 {
63#if defined(F_FULLFSYNC)
64 /*
65 In Mac OS X >= 10.3 this call is safer than fsync() (it forces the
66 disk's cache and guarantees ordered writes).
67 */
68 if (!(res= fcntl(fd, F_FULLFSYNC, 0)))
69 break; /* ok */
70 /* Some file systems don't support F_FULLFSYNC and fail above: */
71 DBUG_PRINT("info",("fcntl(F_FULLFSYNC) failed, falling back"));
72#endif
73#if defined(HAVE_FDATASYNC) && HAVE_DECL_FDATASYNC
74 res= fdatasync(fd);
75#elif defined(HAVE_FSYNC)
76 res= fsync(fd);
77#elif defined(_WIN32)
78 res= my_win_fsync(fd);
79#else
80#error Cannot find a way to sync a file, durability in danger
81 res= 0; /* No sync (strange OS) */
82#endif
83 } while (res == -1 && errno == EINTR);
84
85 if (res)
86 {
87 int er= errno;
88 if (!(my_errno= er))
89 my_errno= -1; /* Unknown error */
90 if (after_sync_wait)
91 (*after_sync_wait)();
92 if ((my_flags & MY_IGNORE_BADFD) &&
93 (er == EBADF || er == EINVAL || er == EROFS
94#ifdef __APPLE__
95 || er == ENOTSUP
96#endif
97 ))
98 {
99 DBUG_PRINT("info", ("ignoring errno %d", er));
100 res= 0;
101 }
102 else if (my_flags & MY_WME)
103 {
104 char errbuf[MYSYS_STRERROR_SIZE];
105 my_error(EE_SYNC, MYF(ME_BELL+ME_WAITTANG), my_filename(fd),
106 my_errno, my_strerror(errbuf, sizeof(errbuf), my_errno));
107 }
108 }
109 else
110 {

Callers 4

my_sync_dirFunction · 0.85
my_msyncFunction · 0.85
my_copyFunction · 0.85
inline_mysql_file_syncFunction · 0.85

Calls 4

my_win_fsyncFunction · 0.85
my_errorFunction · 0.85
my_filenameFunction · 0.85
my_strerrorFunction · 0.85

Tested by

no test coverage detected