From fb97047a840037c2c7237b9de681e386eeedffae Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Fri, 18 Jul 2008 18:50:16 +1000 Subject: Use transaction start/cancel for persistent writes to avoid leaving the database in an inconsistent state if we crash during the operation Signed-off-by: Ronnie Sahlberg (This used to be commit 09329f1f9114af44fc4e5e4f29a7315912313125) --- source3/lib/dbwrap_ctdb.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'source3/lib/dbwrap_ctdb.c') diff --git a/source3/lib/dbwrap_ctdb.c b/source3/lib/dbwrap_ctdb.c index cb4c573eb0..aa2f9d371c 100644 --- a/source3/lib/dbwrap_ctdb.c +++ b/source3/lib/dbwrap_ctdb.c @@ -79,12 +79,19 @@ static NTSTATUS db_ctdb_store_persistent(struct db_record *rec, TDB_DATA data, i memcpy(cdata.dptr, &crec->header, sizeof(crec->header)); memcpy(cdata.dptr + sizeof(crec->header), data.dptr, data.dsize); - ret = tdb_store(crec->ctdb_ctx->wtdb->tdb, rec->key, cdata, TDB_REPLACE); - status = (ret == 0) ? NT_STATUS_OK : NT_STATUS_INTERNAL_DB_CORRUPTION; + status = ctdbd_start_persistent_update(messaging_ctdbd_connection(), crec->ctdb_ctx->db_id, rec->key, cdata); + /* now tell ctdbd to update this record on all other nodes */ + if (NT_STATUS_IS_OK(status)) { + ret = tdb_store(crec->ctdb_ctx->wtdb->tdb, rec->key, cdata, TDB_REPLACE); + status = (ret == 0) ? NT_STATUS_OK : NT_STATUS_INTERNAL_DB_CORRUPTION; + } + /* now tell ctdbd to update this record on all other nodes */ if (NT_STATUS_IS_OK(status)) { status = ctdbd_persistent_store(messaging_ctdbd_connection(), crec->ctdb_ctx->db_id, rec->key, cdata); + } else { + ctdbd_cancel_persistent_update(messaging_ctdbd_connection(), crec->ctdb_ctx->db_id, rec->key, cdata); } SAFE_FREE(cdata.dptr); -- cgit