manpagez: man pages & more
info gdbm
Home | html | info | man

File: gdbm.info,  Node: Enabling crash tolerance,  Next: Synchronizing the Database,  Prev: Filesystems supporting crash tolerance,  Up: Crash Tolerance

17.2 Enabling crash tolerance
=============================

Open a GNU dbm database with 'gdbm_open'.  Whenever possible, use the
extended 'GDBM' format (*note Numsync::).  Generally speaking, this
means using the 'GDBM_NUMSYNC' flag when creating the database.  Unless
you know what you are doing, do not specify the 'GDBM_SYNC' flag when
opening the database.  The reason is that you want your application to
explicitly control when 'gdbm_sync' is called; you don't want an
implicit sync on every database operation (*note Sync::).

   Request crash tolerance by invoking the following interface:

     int gdbm_failure_atomic (GDBM_FILE DBF, const char *EVEN,
                              const char *ODD);

   The EVEN and ODD arguments are the pathnames of two files that will
be created and filled with "snapshots" of the database file.  These two
files must not exist when 'gdbm_failure_atomic' is called and must
reside on the same reflink-capable filesystem as the database file.

   After you call 'gdbm_failure_atomic', every call to 'gdbm_sync' will
make an efficient reflink snapshot of the database file in either the
EVEN or the ODD snapshot file; consecutive 'gdbm_sync' calls alternate
between the two, hence the names.  The permission bits and 'mtime'
timestamps on the snapshot files determine which one contains the state
of the database file corresponding to the most recent successful
'gdbm_sync'.  *Note Crash recovery::, for discussion of crash recovery.

© manpagez.com 2000-2025
Individual documents may contain additional copyright information.