tdb_backup: avoid transaction on backup file, use lockall
authorSimo Sorce <idra@samba.org>
Sun, 10 Apr 2011 02:21:35 +0000 (22:21 -0400)
committerKarolin Seeger <kseeger@samba.org>
Tue, 26 Apr 2011 18:08:53 +0000 (20:08 +0200)
Transactions have the side effect of generating bigger files.
By removing the transaction files get as much as 30% smaller.

Autobuild-User: Simo Sorce <idra@samba.org>
Autobuild-Date: Tue Apr 19 23:34:37 CEST 2011 on sn-devel-104
(cherry picked from commit 1804d9a64662d37f6c7c50bdd7b8edd80f42192b)
(cherry picked from commit 9953e698611defdd6919883a965bdfc12ce51bd5)

lib/tdb/tools/tdbbackup.c

index 6aca8dd99c50bfdcef1c26cd2bc4bd2e154fcaaa..11ecaa0290aee983048da5a454cf71f0176ea794 100644 (file)
@@ -152,8 +152,9 @@ static int backup_tdb(const char *old_name, const char *new_name, int hash_size)
                return 1;
        }
 
-       if (tdb_transaction_start(tdb_new) != 0) {
-               printf("Failed to start transaction on new tdb\n");
+       /* lock the backup tdb so that nobody else can change it */
+       if (tdb_lockall(tdb_new) != 0) {
+               printf("Failed to lock backup tdb\n");
                tdb_close(tdb);
                tdb_close(tdb_new);
                unlink(tmp_name);
@@ -177,12 +178,16 @@ static int backup_tdb(const char *old_name, const char *new_name, int hash_size)
        /* close the old tdb */
        tdb_close(tdb);
 
-       if (tdb_transaction_commit(tdb_new) != 0) {
-               fprintf(stderr, "Failed to commit new tdb\n");
-               tdb_close(tdb_new);
-               unlink(tmp_name);
-               free(tmp_name);         
-               return 1;
+       /* copy done, unlock the backup tdb */
+       tdb_unlockall(tdb_new);
+
+#ifdef HAVE_FDATASYNC
+       if (fdatasync(tdb_fd(tdb_new)) != 0) {
+#else
+       if (fsync(tdb_fd(tdb_new)) != 0) {
+#endif
+               /* not fatal */
+               fprintf(stderr, "failed to fsync backup file\n");
        }
 
        /* close the new tdb and re-open read-only */