[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

RFC: svn_io_file_flush_to_disk

From: Josh Pieper <jpieper_at_andrew.cmu.edu>
Date: 2004-05-01 14:36:54 CEST

In order to improve the data handling properties of FSFS, there are
times when the permanent rev file and 'current' file need to have
their data flushed to disk. Currently, there is no method in APR or
Subversion itself to accomplish this. I am proposing we add a new
function to libsvn_subr, svn_io_file_flush_to_disk, which performs
this function.

Should this go into APR instead? If so, what is the proper process to
get it there, post on the APR dev list and wait?

In the meantime, attached is a potential patch which implements this
function and uses it for FSFS.

-Josh

-----------------------------

Add a new function in svn_io, svn_io_file_flush_to_disk, which flushes
all data written to a file to disk. On Unix like systems, this
equates to fsync, for Win32, FlushFileBuffers is used.

* subversion/include/svn_io.h
* subversion/libsvn_subr/io.h
  (svn_io_file_flush_to_disk): New, flushes all data written to a file
    to disk.

* subversion/libsvn_fs_fs/fs_fs.c
  (write_final_current): Flush the 'current' file to disk before
    closing it.
  (svn_fs_fs__commit): Flush the new permanent rev-file to disk before
    closing it.

Index: subversion/include/svn_io.h
===================================================================
--- subversion/include/svn_io.h (revision 9587)
+++ subversion/include/svn_io.h (working copy)
@@ -324,6 +324,12 @@
                                svn_boolean_t exclusive,
                                apr_pool_t *pool);
 
+/** Flush any unwritten data from @a file to disk. Use @a pool for
+ * memory allocations.
+ */
+svn_error_t *svn_io_file_flush_to_disk (apr_file_t *file,
+ apr_pool_t *pool);
+
 /** Copy file @a file from location @a src_path to location @a dest_path.
  * Use @a pool for memory allocations.
  */
Index: subversion/libsvn_subr/io.c
===================================================================
--- subversion/libsvn_subr/io.c (revision 9587)
+++ subversion/libsvn_subr/io.c (working copy)
@@ -968,6 +968,50 @@
 
 
 
+/* Data consistency/coherency operations. */
+
+svn_error_t *svn_io_file_flush_to_disk (apr_file_t *file,
+ apr_pool_t *pool)
+{
+ /* First make sure that any user-space buffered data is flushed. */
+ apr_status_t apr_err;
+
+ apr_err = apr_file_flush (file);
+
+ if (apr_err)
+ return svn_error_wrap_apr
+ (apr_err, "Can't flush file '%s' to disk.", file);
+
+ /* Call the operating system specific function to actually force the
+ data to disk. */
+ {
+#ifdef WIN32
+ HANDLE filehand;
+
+ apr_os_file_get (&filehand, file);
+ FlushFileBuffers (filehand);
+
+ return APR_SUCCESS;
+#else
+ int filehand;
+ apr_size_t rv;
+
+ apr_os_file_get (&filehand, file);
+ do {
+ rv = fsync (filehand);
+ } while (rv == (apr_size_t)-1 && (errno == EAGAIN || errno == EINTR));
+
+ if (rv == (apr_size_t)-1)
+ return svn_error_wrap_apr
+ (errno, "Can't flush file '%s' to disk.", file);
+
+ return APR_SUCCESS;
+#endif
+ }
+}
+
+
+
 /* TODO write test for these two functions, then refactor. */
 
 svn_error_t *
Index: subversion/libsvn_fs_fs/fs_fs.c
===================================================================
--- subversion/libsvn_fs_fs/fs_fs.c (revision 9588)
+++ subversion/libsvn_fs_fs/fs_fs.c (working copy)
@@ -3484,6 +3484,8 @@
 
   SVN_ERR (svn_io_file_write_full (file, buf, strlen (buf), NULL, pool));
 
+ SVN_ERR (svn_io_file_flush_to_disk (file, pool));
+
   SVN_ERR (svn_io_file_close (file, pool));
 
   SVN_ERR (move_into_place (tmp_name, name, name, pool));
@@ -3596,6 +3598,8 @@
                      changed_path_offset);
   SVN_ERR (svn_io_file_write_full (rev_file, buf, strlen (buf), NULL,
                                    subpool));
+
+ SVN_ERR (svn_io_file_flush_to_disk (rev_file, subpool));
   
   SVN_ERR (svn_io_file_close (rev_file, subpool));
 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat May 1 14:37:09 2004

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.