mirror of
https://github.com/samba-team/samba.git
synced 2024-12-25 23:21:54 +03:00
make tdbbackup use transactions
tdbbackup was originally written before we had transactions, and it
attempted to use its own fsync() calls to make it safe. Now that we
have transactions we can do it in a much safer (and faster!) fashion
(cherry picked from samba commit 2e4247782b
)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
(This used to be ctdb commit cd23d36ada9631095ca68663516de0c8d8c3bbed)
This commit is contained in:
parent
6eaaa52a1d
commit
5b6b852691
@ -143,9 +143,17 @@ static int backup_tdb(const char *old_name, const char *new_name, int hash_size)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* lock the old tdb */
|
||||
if (tdb_lockall(tdb) != 0) {
|
||||
fprintf(stderr,"Failed to lock %s\n", old_name);
|
||||
if (tdb_transaction_start(tdb) != 0) {
|
||||
printf("Failed to start transaction on old tdb\n");
|
||||
tdb_close(tdb);
|
||||
tdb_close(tdb_new);
|
||||
unlink(tmp_name);
|
||||
free(tmp_name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (tdb_transaction_start(tdb_new) != 0) {
|
||||
printf("Failed to start transaction on new tdb\n");
|
||||
tdb_close(tdb);
|
||||
tdb_close(tdb_new);
|
||||
unlink(tmp_name);
|
||||
@ -169,6 +177,14 @@ 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;
|
||||
}
|
||||
|
||||
/* close the new tdb and re-open read-only */
|
||||
tdb_close(tdb_new);
|
||||
tdb_new = tdb_open_ex(tmp_name,
|
||||
@ -194,9 +210,6 @@ static int backup_tdb(const char *old_name, const char *new_name, int hash_size)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* make sure the new tdb has reached stable storage */
|
||||
fsync(tdb_fd(tdb_new));
|
||||
|
||||
/* close the new tdb and rename it to .bak */
|
||||
tdb_close(tdb_new);
|
||||
if (rename(tmp_name, new_name) != 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user