s3:dbwrap_ctdb: exit early when nothing has been written in transaction_commit.
[amitay/samba.git] / source3 / lib / dbwrap_ctdb.c
index fb99e1d9cf52c5265d6856dd5bd682c02f279a4c..79c4c0ce420f0cdd28085999d99ba9ed2ba654d0 100644 (file)
@@ -381,7 +381,7 @@ static bool pull_newest_from_marshall_buffer(struct ctdb_marshall_buffer *buf,
 {
        struct ctdb_rec_data *rec = NULL;
        struct ctdb_ltdb_header h;
-       bool found;
+       bool found = false;
        TDB_DATA data;
        int i;
 
@@ -389,6 +389,9 @@ static bool pull_newest_from_marshall_buffer(struct ctdb_marshall_buffer *buf,
                return false;
        }
 
+       ZERO_STRUCT(h);
+       ZERO_STRUCT(data);
+
        /*
         * Walk the list of records written during this
         * transaction. If we want to read one we have already
@@ -400,8 +403,11 @@ static bool pull_newest_from_marshall_buffer(struct ctdb_marshall_buffer *buf,
        for (i=0; i<buf->count; i++) {
                TDB_DATA tkey, tdata;
                uint32_t reqid;
+               struct ctdb_ltdb_header hdr;
 
-               rec = db_ctdb_marshall_loop_next(buf, rec, &reqid, &h, &tkey,
+               ZERO_STRUCT(hdr);
+
+               rec = db_ctdb_marshall_loop_next(buf, rec, &reqid, &hdr, &tkey,
                                                 &tdata);
                if (rec == NULL) {
                        return false;
@@ -410,6 +416,7 @@ static bool pull_newest_from_marshall_buffer(struct ctdb_marshall_buffer *buf,
                if (tdb_data_equal(key, tkey)) {
                        found = true;
                        data = tdata;
+                       h = hdr;
                }
        }
 
@@ -685,10 +692,14 @@ static NTSTATUS db_ctdb_fetch_db_seqnum_from_db(struct db_ctdb_ctx *db,
        key.dsize = strlen(keyname) + 1;
 
        status = db_ctdb_ltdb_fetch(db, key, &header, mem_ctx, &data);
-       if (!NT_STATUS_IS_OK(status)) {
+       if (!NT_STATUS_IS_OK(status) &&
+           !NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND))
+       {
                goto done;
        }
 
+       status = NT_STATUS_OK;
+
        if (data.dsize != sizeof(uint64_t)) {
                *seqnum = 0;
                goto done;
@@ -752,6 +763,15 @@ static int db_ctdb_transaction_commit(struct db_context *db)
                return 0;
        }
 
+       if (h->m_write == NULL) {
+               /*
+                * No changes were made, so don't change the seqnum,
+                * don't push to other node, just exit with success.
+                */
+               ret = 0;
+               goto done;
+       }
+
        DEBUG(5,(__location__ " Commit transaction on db 0x%08x\n", ctx->db_id));
 
        /*
@@ -779,11 +799,6 @@ static int db_ctdb_transaction_commit(struct db_context *db)
        }
 
 again:
-       if (h->m_write == NULL) {
-               /* no changes were made, potentially after a retry */
-               goto done;
-       }
-
        /* tell ctdbd to commit to the other nodes */
        rets = ctdbd_control_local(messaging_ctdbd_connection(),
                                   CTDB_CONTROL_TRANS3_COMMIT,
@@ -829,7 +844,7 @@ again:
 done:
        h->ctx->transaction = NULL;
        talloc_free(h);
-       return 0;
+       return ret;
 }