fdatasync only flushes data to disk the kernel knows about,
so we must tell the kernel about the data via fflush before
we fdatasync.
Using an Fflushsync wrapper function should make it easier to
avoid this mistake in the future when we use stdio but need
fdatasync.
---
IMHO, this makes the code easier to follow, too.
src/sync.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/sync.c b/src/sync.c
index 220399f..b8ae95f 100644
--- a/src/sync.c
+++ b/src/sync.c
@@ -39,10 +39,21 @@
const char *str_ms[] = { "master", "slave" }, *str_hl[] = { "push", "pull" };
+static int
+Fflushsync( FILE *f, int req_fsync_level )
+{
+ int r = fflush( f );
+
+ if (r == 0 && FSyncLevel >= req_fsync_level)
+ r = fdatasync( fileno( f ) );
+
+ return r;
+}
+
void
Fclose( FILE *f, int safe )
{
- if ((safe && (fflush( f ) || (FSyncLevel >= FSYNC_NORMAL && fdatasync(
fileno( f ) )))) || fclose( f ) == EOF) {
+ if ((safe && Fflushsync( f, FSYNC_NORMAL )) || fclose( f ) == EOF) {
sys_error( "Error: cannot close file. Disk full?" );
exit( 1 );
}
@@ -1203,8 +1214,7 @@ box_loaded( int sts, void *aux )
cv->srec = srec;
cv->msg = tmsg;
Fprintf( svars->jfp, "# %d %d
%." stringify(TUIDL) "s\n", srec->uid[M], srec->uid[S], srec->tuid );
- if (FSyncLevel >=
FSYNC_THOROUGH)
- fdatasync( fileno(
svars->jfp ) );
+ Fflushsync( svars->jfp,
FSYNC_THOROUGH );
debug( " -> %sing message,
TUID %." stringify(TUIDL) "s\n", str_hl[t], srec->tuid );
if (copy_msg( cv ))
return;
--
Eric Wong
------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
isync-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/isync-devel