ctdb-tests: Implement --interactive/-i option in transaction_loop
authorMartin Schwenke <martin@meltin.net>
Tue, 2 Aug 2016 05:00:54 +0000 (15:00 +1000)
committerMartin Schwenke <martins@samba.org>
Mon, 8 Aug 2016 06:17:33 +0000 (08:17 +0200)
Also add PNNs to output.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=12109

Pair-programmed-with: Amitay Isaacs <amitay@gmail.com>
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/tests/src/transaction_loop.c

index 660270c169907fdb93ae5ab7f9b7584d469a8acd..3b325fd384d31bedd432ad16fba8ba1795cc9707 100644 (file)
@@ -36,6 +36,7 @@ struct transaction_loop_state {
        struct ctdb_db_context *ctdb_db;
        int num_nodes;
        int timelimit;
+       int interactive;
        TDB_DATA key;
        uint32_t pnn;
        struct ctdb_transaction_handle *h;
@@ -55,7 +56,7 @@ static struct tevent_req *transaction_loop_send(
                                struct tevent_context *ev,
                                struct ctdb_client_context *client,
                                struct ctdb_db_context *ctdb_db,
-                               int num_nodes, int timelimit)
+                               int num_nodes, int timelimit, int interactive)
 {
        struct tevent_req *req, *subreq;
        struct transaction_loop_state *state;
@@ -71,6 +72,7 @@ static struct tevent_req *transaction_loop_send(
        state->ctdb_db = ctdb_db;
        state->num_nodes = num_nodes;
        state->timelimit = timelimit;
+       state->interactive = interactive;
        state->key.dptr = discard_const(TESTKEY);
        state->key.dsize = strlen(TESTKEY);
        state->pnn = ctdb_client_pnn(client);
@@ -248,11 +250,14 @@ static void transaction_loop_each_second(struct tevent_req *subreq)
                return;
        }
 
-       for (i=0; i<state->num_nodes; i++) {
-               printf("%6u ", state->counter[i]);
+       if (state->interactive == 1) {
+               printf("Transaction[%u]: ", ctdb_client_pnn(state->client));
+               for (i=0; i<state->num_nodes; i++) {
+                       printf("%6u ", state->counter[i]);
+               }
+               printf("\n");
+               fflush(stdout);
        }
-       printf("\n");
-       fflush(stdout);
 
        subreq = tevent_wakeup_send(state, state->ev,
                                    tevent_timeval_current_ofs(1, 0));
@@ -304,6 +309,7 @@ static void transaction_loop_finish(struct tevent_req *subreq)
                return;
        }
 
+       printf("Transaction[%u]: ", ctdb_client_pnn(state->client));
        for (i=0; i<state->num_nodes; i++) {
                printf("%6u ", state->counter[i]);
        }
@@ -373,7 +379,8 @@ int main(int argc, const char *argv[])
        }
 
        req = transaction_loop_send(mem_ctx, ev, client, ctdb_db,
-                                   opts->num_nodes, opts->timelimit);
+                                   opts->num_nodes, opts->timelimit,
+                                   opts->interactive);
        if (req == NULL) {
                fprintf(stderr, "Memory allocation error\n");
                exit(1);