[Csync2] tempdir patch

Lars Ellenberg lars.ellenberg at linbit.com
Sat Oct 25 22:37:11 CEST 2008


On Wed, Oct 22, 2008 at 05:39:47PM +0200, Lars Ellenberg wrote:
> On Wed, Oct 22, 2008 at 05:15:39PM +0200, Art -kwaak- van Breemen wrote:
> > I've added a config option called tempdir, which allows to set a
> > default tempdir.
> > Furthermore, the tmpfile code is rewritten to use tempnam, which
> > means it will adhere to the TMPDIR= convention.
> 
> while at it, maybe we can get rid of the additional copy after
> successful transfer, and try to do "the same" as rsync, namely
> defaulting to a temp file in the same directory.
> 
> then after successful transfer, try to rename, fall back to copy,
> fall back to create/truncate/read from tmpfile write into new file.
> 
> see rsync code for what I mean.

to be more precise,
in csync2/rsync.c: int csync_rs_patch(const char *filename)

once all necessary data was transfered and the new (temporary) file is
created and filled with the new data, this code follows:

        basis_file = fopen(prefixsubst(filename), "wb");
        if ( !basis_file ) { errstr="opening data file for writing"; goto io_error; }

        while ( (rc = fread(buffer, 1, 512, new_file)) > 0 )
                fwrite(buffer, rc, 1, basis_file);

        csync_debug(3, "File has been patched successfully.\n");

which means:
the basis file is truncated, then filled successively from the tempfile.

this may be a serious problem when csync2 or the node it runs on
crashes during this copy, as there will be a half-written file in place
of the original. less unlikely for larger files, especially annoying if
you use csync2 to deploy applications/libraries/other critical data.

the way to go would be to atomically rename the tempfile to replace the
original.  which only works reliably if the tempfile is created in the
same directory. rsync does this, with two stages of fallback paranoia.

any volunteers to adapt that to csync2?

-- 
: Lars Ellenberg                
: LINBIT | Your Way to High Availability
: DRBD/HA support and consulting http://www.linbit.com

DRBD® and LINBIT® are registered trademarks of LINBIT, Austria.


More information about the Csync2 mailing list