From 1804d9a64662d37f6c7c50bdd7b8edd80f42192b Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 9 Apr 2011 22:21:35 -0400 Subject: tdb_backup: avoid transaction on backup file, use lockall Transactions have the side effect of generating bigger files. By removing the transaction files get as much as 30% smaller. Autobuild-User: Simo Sorce Autobuild-Date: Tue Apr 19 23:34:37 CEST 2011 on sn-devel-104 --- lib/tdb/tools/tdbbackup.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'lib/tdb') diff --git a/lib/tdb/tools/tdbbackup.c b/lib/tdb/tools/tdbbackup.c index 6aca8dd99c..11ecaa0290 100644 --- a/lib/tdb/tools/tdbbackup.c +++ b/lib/tdb/tools/tdbbackup.c @@ -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 */ -- cgit