return a more detailed error code from a trans2 commit error
authorAndrew Tridgell <tridge@samba.org>
Thu, 7 Aug 2008 23:58:49 +0000 (09:58 +1000)
committerAndrew Tridgell <tridge@samba.org>
Thu, 7 Aug 2008 23:58:49 +0000 (09:58 +1000)
include/ctdb_private.h
server/ctdb_persistent.c

index ff4d271794be4ff9487c8609139464d8748a5bce..6cc1dc9f9c26439c2b853240bae5dfe0955e1ef5 100644 (file)
@@ -789,6 +789,16 @@ struct ctdb_req_keepalive {
        struct ctdb_req_header hdr;
 };
 
+
+/* types of failures possible from TRANS2_COMMIT */
+enum ctdb_trans2_commit_error {
+       CTDB_TRANS2_COMMIT_SUCCESS=0, /* all nodes committed successfully */
+       CTDB_TRANS2_COMMIT_TIMEOUT=1, /* at least one node timed out */
+       CTDB_TRANS2_COMMIT_ALLFAIL=2, /* all nodes failed the commit */
+       CTDB_TRANS2_COMMIT_SOMEFAIL=3 /* some nodes failed the commit, some allowed it */
+};
+
+
 /* internal prototypes */
 void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
 void ctdb_fatal(struct ctdb_context *ctdb, const char *msg);
index 5b88b4bbed97ae9079931b28b14d69c25ba91a31..faa6e83029b39e507cdb2e4ead8aaad16679ce82 100644 (file)
@@ -32,8 +32,16 @@ struct ctdb_persistent_state {
        const char *errormsg;
        uint32_t num_pending;
        int32_t status;
+       uint32_t num_failed, num_sent;
 };
 
+/*
+  1) all nodes fail, and all nodes reply
+  2) some nodes fail, all nodes reply
+  3) some nodes timeout
+  4) all nodes succeed
+ */
+
 /*
   called when a node has acknowledged a ctdb_control_update_record call
  */
@@ -50,10 +58,19 @@ static void ctdb_persistent_callback(struct ctdb_context *ctdb,
                         status, errormsg));
                state->status = status;
                state->errormsg = errormsg;
+               state->num_failed++;
        }
        state->num_pending--;
        if (state->num_pending == 0) {
-               ctdb_request_control_reply(state->ctdb, state->c, NULL, state->status, state->errormsg);
+               enum ctdb_trans2_commit_error etype;
+               if (state->num_failed == state->num_sent) {
+                       etype = CTDB_TRANS2_COMMIT_ALLFAIL;
+               } else if (state->num_failed != 0) {
+                       etype = CTDB_TRANS2_COMMIT_SOMEFAIL;
+               } else {
+                       etype = CTDB_TRANS2_COMMIT_SUCCESS;
+               }
+               ctdb_request_control_reply(state->ctdb, state->c, NULL, etype, state->errormsg);
                talloc_free(state);
        }
 }
@@ -66,7 +83,8 @@ static void ctdb_persistent_store_timeout(struct event_context *ev, struct timed
 {
        struct ctdb_persistent_state *state = talloc_get_type(private_data, struct ctdb_persistent_state);
        
-       ctdb_request_control_reply(state->ctdb, state->c, NULL, -1, "timeout in ctdb_persistent_state");
+       ctdb_request_control_reply(state->ctdb, state->c, NULL, CTDB_TRANS2_COMMIT_TIMEOUT, 
+                                  "timeout in ctdb_persistent_state");
 
        talloc_free(state);
 }
@@ -141,6 +159,7 @@ int32_t ctdb_control_trans2_commit(struct ctdb_context *ctdb,
                }
 
                state->num_pending++;
+               state->num_sent++;
        }
 
        if (state->num_pending == 0) {