]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
On unix, always use fdatasync() instead of fsync() when available, even if
authordrh <drh@noemail.net>
Sat, 21 Mar 2009 14:41:04 +0000 (14:41 +0000)
committerdrh <drh@noemail.net>
Sat, 21 Mar 2009 14:41:04 +0000 (14:41 +0000)
the file size changes, since (we are told) fdatasync() will automatically
flush the inode when the file size changes. (CVS 6367)

FossilOrigin-Name: 0d6b11bcf67f86e5554806869d32338e5831833e

manifest
manifest.uuid
src/os_unix.c

index c691926fa64f2d85747cd184f2356e2bb2565052..5e6e4735b3f9bc7625c46a730137f7d110d0fdc0 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\sa\stest\sto\stry\sto\shit\sthe\srace-condition\sfixed\sby\s(6363).\s(CVS\s6366)
-D 2009-03-20T15:16:06
+C On\sunix,\salways\suse\sfdatasync()\sinstead\sof\sfsync()\swhen\savailable,\seven\sif\nthe\sfile\ssize\schanges,\ssince\s(we\sare\stold)\sfdatasync()\swill\sautomatically\nflush\sthe\sinode\swhen\sthe\sfile\ssize\schanges.\s(CVS\s6367)
+D 2009-03-21T14:41:04
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in 583e87706abc3026960ed759aff6371faf84c211
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -141,7 +141,7 @@ F src/os.c ed93a6b46132a602c4fd7a58142e2981c829c79d
 F src/os.h fa3f4aa0119ff721a2da4b47ffd74406ac864c05
 F src/os_common.h 8c61457df58f1a4bd5f5adc3e90e01b37bf7afbc
 F src/os_os2.c bed77dc26e3a95ce4a204936b9a1ca6fe612fcc5
-F src/os_unix.c 52352674c19688026a72cd0e8620e6a29bacba4a
+F src/os_unix.c 8f6ffa95c8dc79b94565b517bc37abb426f09a23
 F src/os_win.c 40636702058ed4dcd35d68151bfab56d4997cdc1
 F src/pager.c 01e3facb2f7c5f307e36a0f4ed9343cf3761711a
 F src/pager.h 0c9f3520c00d8a3b8e792ca56c9a11b6b02b4b0f
@@ -709,7 +709,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P a08324d16d1e9a4e7c1b294bc71fc939d173f826
-R 87fff081bb6bfc825b1acb6eabea142e
-U danielk1977
-Z 5f0bd3312fbc59ec4534315ac49a7c31
+P 4310411f5027dba18e017023e21cb09982e26752
+R da4300d409cda801b0b75c2eee2c6174
+U drh
+Z 669efac6174bfcb881ee9f0e80879f8c
index 259c523a022359869365c078fd38a39647be1cc4..d343d63b425c243e4abd6dfba9822ea42b99f746 100644 (file)
@@ -1 +1 @@
-4310411f5027dba18e017023e21cb09982e26752
\ No newline at end of file
+0d6b11bcf67f86e5554806869d32338e5831833e
\ No newline at end of file
index e21a59b15c14c9b60faeb135b9567e5e4b3efd80..ec781a5568ca9e7ae8b629e005aa1bd53eeb9b14 100644 (file)
@@ -43,7 +43,7 @@
 **   *  Definitions of sqlite3_vfs objects for all locking methods
 **      plus implementations of sqlite3_os_init() and sqlite3_os_end().
 **
-** $Id: os_unix.c,v 1.242 2009/03/01 22:29:20 drh Exp $
+** $Id: os_unix.c,v 1.243 2009/03/21 14:41:04 drh Exp $
 */
 #include "sqliteInt.h"
 #if SQLITE_OS_UNIX              /* This file is used on unix only */
@@ -2853,6 +2853,19 @@ int sqlite3_fullsync_count = 0;
 ** You are strongly advised *not* to deploy with SQLITE_NO_SYNC
 ** enabled, however, since with SQLITE_NO_SYNC enabled, an OS crash
 ** or power failure will likely corrupt the database file.
+**
+** SQLite sets the dataOnly flag if the size of the file is unchanged.
+** The idea behind dataOnly is that it should only write the file content
+** to disk, not the inode.  We only set dataOnly if the file size is 
+** unchanged since the file size is part of the inode.  However, 
+** Ted Ts'o tells us that fdatasync() will also write the inode if the
+** file size has changed.  The only real difference between fdatasync()
+** and fsync(), Ted tells us, is that fdatasync() will not flush the
+** inode if the mtime or owner or other inode attributes have changed.
+** We only care about the file size, not the other file attributes, so
+** as far as SQLite is concerned, an fdatasync() is always adequate.
+** So, we always use fdatasync() if it is available, regardless of
+** the value of the dataOnly flag.
 */
 static int full_fsync(int fd, int fullSync, int dataOnly){
   int rc;
@@ -2869,6 +2882,7 @@ static int full_fsync(int fd, int fullSync, int dataOnly){
   UNUSED_PARAMETER(dataOnly);
 #else
   UNUSED_PARAMETER(fullSync);
+  UNUSED_PARAMETER(dataOnly);
 #endif
 
   /* Record the number of times that we do a normal fsync() and 
@@ -2902,16 +2916,12 @@ static int full_fsync(int fd, int fullSync, int dataOnly){
   if( rc ) rc = fsync(fd);
 
 #else 
-  if( dataOnly ){
-    rc = fdatasync(fd);
+  rc = fdatasync(fd);
 #if OS_VXWORKS
-    if( rc==-1 && errno==ENOTSUP ){
-      rc = fsync(fd);
-    }
-#endif
-  }else{
+  if( rc==-1 && errno==ENOTSUP ){
     rc = fsync(fd);
   }
+#endif /* OS_VXWORKS */
 #endif /* ifdef SQLITE_NO_SYNC elif HAVE_FULLFSYNC */
 
   if( OS_VXWORKS && rc!= -1 ){