[SCM] SAMBA-CTDB repository - branch v3-0-ctdb updated - 3a7a26d582995abc3f18ab322046368006acae7e

Andrew Tridgell tridge at samba.org
Thu Apr 10 05:25:10 GMT 2008


The branch, v3-0-ctdb has been updated
       via  3a7a26d582995abc3f18ab322046368006acae7e (commit)
      from  e49f292a35298716976a479108968c1e4fd94547 (commit)

http://gitweb.samba.org/?p=tridge/samba-ctdb.git;a=shortlog;h=v3-0-ctdb


- Log -----------------------------------------------------------------
commit 3a7a26d582995abc3f18ab322046368006acae7e
Author: Andrew Tridgell <tridge at samba.org>
Date:   Thu Apr 10 15:22:54 2008 +1000

    - For persistent ctdb databases, use a transaction wrapper around all
      deletes and stores. This makes Samba crash safe for persistent
      databases, which the the critical databases that must not be
      corrupted by a system crash
    
    - pass the tdb flags across the CTDB attach control. This means that
      TDB_NOSYNC will be honoured, so that persistent databases that are
      performance sensitive won't pay a high cost for the crash safety
      (for example the winbindd cache database)

-----------------------------------------------------------------------

Summary of changes:
 source/lib/dbwrap_ctdb.c |   42 +++++++++++++++++++++++++-----------------
 source/lib/messages.c    |    5 +++--
 2 files changed, 28 insertions(+), 19 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/lib/dbwrap_ctdb.c b/source/lib/dbwrap_ctdb.c
index b420241..cd18fd9 100644
--- a/source/lib/dbwrap_ctdb.c
+++ b/source/lib/dbwrap_ctdb.c
@@ -77,7 +77,20 @@ 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);
 
+	/* we need to use a transaction to make persistent databases crash safe */
+	ret = tdb_transaction_start(crec->ctdb_ctx->wtdb->tdb);
+	if (ret != 0) {
+		goto failed;
+	}
 	ret = tdb_store(crec->ctdb_ctx->wtdb->tdb, rec->key, cdata, TDB_REPLACE);
+	if (ret != 0) {
+		tdb_transaction_cancel(crec->ctdb_ctx->wtdb->tdb);
+		goto failed;
+	}
+
+	ret = tdb_transaction_commit(crec->ctdb_ctx->wtdb->tdb);
+
+failed:
 	status = (ret == 0) ? NT_STATUS_OK : NT_STATUS_INTERNAL_DB_CORRUPTION;
 	
 	/* now tell ctdbd to update this record on all other nodes */
@@ -90,24 +103,18 @@ static NTSTATUS db_ctdb_store_persistent(struct db_record *rec, TDB_DATA data, i
 	return status;
 }
 
-static NTSTATUS db_ctdb_delete(struct db_record *rec)
+/* 
+   persistent delete needs to push the change to other nodes
+ */
+static NTSTATUS db_ctdb_delete_persistent(struct db_record *rec)
 {
-	struct db_ctdb_rec *crec = talloc_get_type_abort(
-		rec->private_data, struct db_ctdb_rec);
-	TDB_DATA data;
-	int ret;
-
-	/*
-	 * We have to store the header with empty data. TODO: Fix the
-	 * tdb-level cleanup
-	 */
-
-	data.dptr = (uint8 *)&crec->header;
-	data.dsize = sizeof(crec->header);
+	return db_ctdb_store_persistent(rec, tdb_null, TDB_REPLACE);
+}
 
-	ret = tdb_store(crec->ctdb_ctx->wtdb->tdb, rec->key, data, TDB_REPLACE);
 
-	return (ret == 0) ? NT_STATUS_OK : NT_STATUS_INTERNAL_DB_CORRUPTION;
+static NTSTATUS db_ctdb_delete(struct db_record *rec)
+{
+	return db_ctdb_store(rec, tdb_null, TDB_REPLACE);
 }
 
 static int db_ctdb_record_destr(struct db_record* data)
@@ -178,10 +185,11 @@ again:
 
 	if (db->persistent) {
 		result->store = db_ctdb_store_persistent;
+		result->delete_rec = db_ctdb_delete_persistent;
 	} else {
 		result->store = db_ctdb_store;
+		result->delete_rec = db_ctdb_delete;
 	}
-	result->delete_rec = db_ctdb_delete;
 	talloc_set_destructor(result, db_ctdb_record_destr);
 
 	ctdb_data = tdb_fetch(ctx->wtdb->tdb, key);
@@ -469,7 +477,7 @@ struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
 	result->persistent = ((tdb_flags & TDB_CLEAR_IF_FIRST) == 0);
 
 	/* only pass through specific flags */
-	tdb_flags &= TDB_SEQNUM;
+	tdb_flags &= TDB_SEQNUM | TDB_NOSYNC;
 
 	db_ctdb->wtdb = tdb_wrap_open(db_ctdb, db_path, hash_size, tdb_flags, O_RDWR, 0);
 	if (db_ctdb->wtdb == NULL) {
diff --git a/source/lib/messages.c b/source/lib/messages.c
index 26d2f19..2e45a4b 100644
--- a/source/lib/messages.c
+++ b/source/lib/messages.c
@@ -1865,7 +1865,7 @@ BOOL ctdbd_db_attach(const char *name, uint32_t *db_id, int tdb_flags)
 
 	status = ctdbd_control(ctdbd_ctx, CTDB_CURRENT_NODE, 
 			       persistent?CTDB_CONTROL_DB_ATTACH_PERSISTENT:CTDB_CONTROL_DB_ATTACH, 
-			       0, data, 
+			       tdb_flags, data, 
 			       NULL, &data, &cstatus);
 	if (!NT_STATUS_IS_OK(status)
 	    || cstatus != 0
@@ -1884,7 +1884,8 @@ BOOL ctdbd_db_attach(const char *name, uint32_t *db_id, int tdb_flags)
 	data.dptr = (uint8_t *)db_id;
 	data.dsize = sizeof(*db_id);
 
-	status = ctdbd_control(ctdbd_ctx, CTDB_CURRENT_NODE, CTDB_CONTROL_ENABLE_SEQNUM, 0, data, 
+	status = ctdbd_control(ctdbd_ctx, CTDB_CURRENT_NODE, CTDB_CONTROL_ENABLE_SEQNUM, 
+			       tdb_flags, data, 
 			       NULL, NULL, &cstatus);
 	if (!NT_STATUS_IS_OK(status) || cstatus != 0) {
 		DEBUG(0,(__location__ " ctdb_control for enable seqnum failed\n"));


-- 
SAMBA-CTDB repository


More information about the samba-cvs mailing list