diff options
author | Simo Sorce <idra@samba.org> | 2011-04-09 22:21:35 -0400 |
---|---|---|
committer | Simo Sorce <idra@samba.org> | 2011-04-19 23:34:37 +0200 |
commit | 1804d9a64662d37f6c7c50bdd7b8edd80f42192b (patch) | |
tree | d679679ad0c806f0ae1f4dae0624aaacf2cb2a0c /lib/tdb/tools | |
parent | 9bf3dc3ca796f2b90acf7e21b0eefdce444147e1 (diff) | |
download | samba-1804d9a64662d37f6c7c50bdd7b8edd80f42192b.tar.gz samba-1804d9a64662d37f6c7c50bdd7b8edd80f42192b.tar.bz2 samba-1804d9a64662d37f6c7c50bdd7b8edd80f42192b.zip |
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 <idra@samba.org>
Autobuild-Date: Tue Apr 19 23:34:37 CEST 2011 on sn-devel-104
Diffstat (limited to 'lib/tdb/tools')
-rw-r--r-- | lib/tdb/tools/tdbbackup.c | 21 |
1 files changed, 13 insertions, 8 deletions
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 */ |