Test suite: ctdb_persistent.c needs to use transactions.
authorMartin Schwenke <martin@meltin.net>
Fri, 14 Aug 2009 10:47:38 +0000 (20:47 +1000)
committerMartin Schwenke <martin@meltin.net>
Fri, 14 Aug 2009 10:47:38 +0000 (20:47 +1000)
Signed-off-by: Martin Schwenke <martin@meltin.net>
tests/src/ctdb_persistent.c

index 2401255ff832f283eb3c861b31fd5a679ba83d61..8110ce12832c08f01bf3bb1abed598f6703d00e0 100644 (file)
@@ -116,21 +116,27 @@ static void test_store_records(struct ctdb_context *ctdb, struct event_context *
        while (end_timer() < timelimit) {
                TDB_DATA data;
                TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
-               struct ctdb_record_handle *h;
+               struct ctdb_transaction_handle *h;
                int ret;
                uint32_t *counters;
 
-               h = ctdb_fetch_lock(ctdb_db, tmp_ctx, key, &data);
+               h = ctdb_transaction_start(ctdb_db, tmp_ctx);
                if (h == NULL) {
-                       printf("Failed to fetch record '%s' on node %d\n", 
-                              (const char *)key.dptr, ctdb_get_pnn(ctdb));
+                       printf("Failed to start transaction on node %d\n",
+                              ctdb_get_pnn(ctdb));
                        talloc_free(tmp_ctx);
                        return;
                }
 
+               ret = ctdb_transaction_fetch(h, tmp_ctx, key, &data);
+               if (ret != 0) {
+                       DEBUG(DEBUG_ERR,("Failed to fetch record\n"));
+                       exit(1);
+               }
+
                if (data.dsize < sizeof(uint32_t) * (pnn+1)) {
                        unsigned char *ptr = data.dptr;
-
+                       
                        data.dptr = talloc_zero_size(tmp_ctx, sizeof(uint32_t) * (pnn+1));
                        memcpy(data.dptr, ptr, data.dsize);
                        talloc_free(ptr);
@@ -149,18 +155,23 @@ static void test_store_records(struct ctdb_context *ctdb, struct event_context *
                /* bump our counter */
                counters[pnn]++;
 
-               ret = ctdb_record_store(h, data);
+               ret = ctdb_transaction_store(h, key, data);
                if (ret != 0) {
                        DEBUG(DEBUG_ERR,("Failed to store record\n"));
                        exit(1);
                }
 
+               ret = ctdb_transaction_commit(h);
+               if (ret != 0) {
+                       DEBUG(DEBUG_ERR,("Failed to commit transaction\n"));
+                       exit(1);
+               }
+
                /* store the counters and verify that they are sane */
                if (pnn == 0) {
                        check_counters(ctdb, data);
                }
 
-               talloc_free(h);
                talloc_free(tmp_ctx);
        }