much simpler redirect logic
authorAndrew Tridgell <tridge@samba.org>
Sat, 28 Apr 2007 16:18:33 +0000 (18:18 +0200)
committerAndrew Tridgell <tridge@samba.org>
Sat, 28 Apr 2007 16:18:33 +0000 (18:18 +0200)
(This used to be ctdb commit 95db9afa7dd039e1700e2f3078782f6ac66e9f51)

ctdb/common/ctdb.c
ctdb/common/ctdb_call.c
ctdb/include/ctdb_private.h
ctdb/tests/run_tests.sh
ctdb/tools/ctdb_control.c

index 65b678fbcae736eb3168eebbc69345c700160c91..5c46cd2f65b9d522a6bee75424ee6193e6cb9b4e 100644 (file)
@@ -267,11 +267,6 @@ void ctdb_recv_pkt(struct ctdb_context *ctdb, uint8_t *data, uint32_t length)
                ctdb_reply_error(ctdb, hdr);
                break;
 
-       case CTDB_REPLY_REDIRECT:
-               ctdb->status.count.reply_redirect++;
-               ctdb_reply_redirect(ctdb, hdr);
-               break;
-
        case CTDB_REQ_DMASTER:
                ctdb->status.count.req_dmaster++;
                ctdb_request_dmaster(ctdb, hdr);
index cfbea14863d1e36b2fab603463be9816df8fb9ca..a7fb253a377ee248914dcbcf8450688e87440fe1 100644 (file)
@@ -162,22 +162,18 @@ static void ctdb_send_error(struct ctdb_context *ctdb,
   send a redirect reply
 */
 static void ctdb_call_send_redirect(struct ctdb_context *ctdb, 
+                                   TDB_DATA key,
                                    struct ctdb_req_call *c, 
                                    struct ctdb_ltdb_header *header)
 {
-       struct ctdb_reply_redirect *r;
-
-       r = ctdb_transport_allocate(ctdb, ctdb, CTDB_REPLY_REDIRECT, sizeof(*r), 
-                                   struct ctdb_reply_redirect);
-       CTDB_NO_MEMORY_FATAL(ctdb, r);
-
-       r->hdr.destnode  = c->hdr.srcnode;
-       r->hdr.reqid     = c->hdr.reqid;
-       r->dmaster       = header->dmaster;
-
-       ctdb_queue_packet(ctdb, &r->hdr);
-
-       talloc_free(r);
+       
+       uint32_t lmaster = ctdb_lmaster(ctdb, &key);
+       if (ctdb->vnn == lmaster) {
+               c->hdr.destnode = header->dmaster;
+       } else {
+               c->hdr.destnode = lmaster;
+       }
+       ctdb_queue_packet(ctdb, &c->hdr);
 }
 
 
@@ -438,7 +434,7 @@ void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
        /* if we are not the dmaster, then send a redirect to the
           requesting node */
        if (header.dmaster != ctdb->vnn) {
-               ctdb_call_send_redirect(ctdb, c, &header);
+               ctdb_call_send_redirect(ctdb, call.key, c, &header);
                talloc_free(data.dptr);
                ctdb_ltdb_unlock(ctdb_db, call.key);
                return;
@@ -594,44 +590,6 @@ void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
 }
 
 
-/*
-  called when a CTDB_REPLY_REDIRECT packet comes in
-
-  This packet arrives when we have sent a CTDB_REQ_CALL request and
-  the node that received it is not the dmaster for the given key. We
-  are given a hint as to what node to try next.
-*/
-void ctdb_reply_redirect(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
-{
-       struct ctdb_reply_redirect *c = (struct ctdb_reply_redirect *)hdr;
-       struct ctdb_call_state *state;
-
-       state = ctdb_reqid_find(ctdb, hdr->reqid, struct ctdb_call_state);
-       if (state == NULL) {
-               return;
-       }
-
-       if (hdr->reqid != state->reqid) {
-               /* we found a record  but it was the wrong one */
-               DEBUG(0, ("Dropped orphaned dmaster reply with reqid:%d\n",hdr->reqid));
-               return;
-       }
-
-       /* don't allow for too many redirects */
-       if ((++state->redirect_count) % CTDB_MAX_REDIRECT == 0) {
-               c->dmaster = ctdb_lmaster(ctdb, &state->call.key);
-               if (state->redirect_count > ctdb->status.max_redirect_count) {
-                       ctdb->status.max_redirect_count = state->redirect_count;
-               }
-       }
-
-       /* send it off again */
-       state->node = ctdb->nodes[c->dmaster];
-       state->c->hdr.destnode = c->dmaster;
-
-       ctdb_queue_packet(ctdb, &state->c->hdr);
-}
-
 /*
   destroy a ctdb_call
 */
index a75f1d970b4925691864f5a2911d48f979c41b41..170e28d3621944fb865574cfd4a9341abc29ddb4 100644 (file)
@@ -135,7 +135,6 @@ struct ctdb_status {
        struct {
                uint32_t req_call;
                uint32_t reply_call;
-               uint32_t reply_redirect;
                uint32_t req_dmaster;
                uint32_t reply_dmaster;
                uint32_t reply_error;
@@ -158,7 +157,6 @@ struct ctdb_status {
        uint32_t lockwait_calls;
        uint32_t pending_lockwait_calls;
        uint32_t __last_counter; /* hack for control_status_all */
-       uint32_t max_redirect_count;
        double max_call_latency;
        double max_lockwait_latency;
 };
@@ -229,9 +227,6 @@ struct ctdb_db_context {
 /* arbitrary maximum timeout for ctdb operations */
 #define CTDB_REQ_TIMEOUT 0
 
-/* max number of redirects before we ask the lmaster */
-#define CTDB_MAX_REDIRECT 2
-
 /* number of consecutive calls from the same node before we give them
    the record */
 #define CTDB_DEFAULT_MAX_LACOUNT 7
@@ -271,7 +266,6 @@ struct ctdb_call_state {
        struct ctdb_node *node;
        const char *errmsg;
        struct ctdb_call call;
-       int redirect_count;
        struct ctdb_ltdb_header header;
        struct {
                void (*fn)(struct ctdb_call_state *);
@@ -293,21 +287,20 @@ struct ctdb_fetch_handle {
 */
 enum ctdb_operation {
        CTDB_REQ_CALL           = 0,
-       CTDB_REPLY_CALL         = 1,
-       CTDB_REPLY_REDIRECT     = 2,
-       CTDB_REQ_DMASTER        = 3,
-       CTDB_REPLY_DMASTER      = 4,
-       CTDB_REPLY_ERROR        = 5,
-       CTDB_REQ_MESSAGE        = 6,
-       CTDB_REQ_FINISHED       = 7,
-       CTDB_REQ_CONTROL        = 8,
-       CTDB_REPLY_CONTROL      = 9,
+       CTDB_REPLY_CALL,
+       CTDB_REQ_DMASTER,
+       CTDB_REPLY_DMASTER,
+       CTDB_REPLY_ERROR,
+       CTDB_REQ_MESSAGE,
+       CTDB_REQ_FINISHED,
+       CTDB_REQ_CONTROL,
+       CTDB_REPLY_CONTROL,
        
        /* only used on the domain socket */
        CTDB_REQ_REGISTER       = 1000,     
-       CTDB_REQ_CONNECT_WAIT   = 1001,
-       CTDB_REPLY_CONNECT_WAIT = 1002,
-       CTDB_REQ_SHUTDOWN       = 1003
+       CTDB_REQ_CONNECT_WAIT,
+       CTDB_REPLY_CONNECT_WAIT,
+       CTDB_REQ_SHUTDOWN
 };
 
 #define CTDB_MAGIC 0x43544442 /* CTDB */
@@ -351,11 +344,6 @@ struct ctdb_reply_error {
        uint8_t  msg[1];
 };
 
-struct ctdb_reply_redirect {
-       struct ctdb_req_header hdr;
-       uint32_t dmaster;
-};
-
 struct ctdb_req_dmaster {
        struct ctdb_req_header hdr;
        uint32_t db_id;
@@ -442,7 +430,6 @@ void ctdb_request_message(struct ctdb_context *ctdb, struct ctdb_req_header *hdr
 void ctdb_reply_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
 void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
 void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
-void ctdb_reply_redirect(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
 
 uint32_t ctdb_lmaster(struct ctdb_context *ctdb, const TDB_DATA *key);
 int ctdb_ltdb_fetch(struct ctdb_db_context *ctdb_db, 
index 983afa0adb71110b669f1cbf85c9b6cc8168aeb6..e628bad80035b53867ea3ad2dabc491907964148 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 
-tests/fetch.sh || exit 1
-tests/bench.sh || exit 1
+tests/fetch.sh || exit 1
+tests/bench.sh || exit 1
 tests/test.sh || exit 1
 
 echo "All OK"
index 45743b36c6a2f515061660ee6374135a861b4321..100215e5e5c922b1272efdae38cca0a275b9c9e2 100644 (file)
@@ -89,18 +89,15 @@ static void show_status(struct ctdb_status *s)
        printf(" node_packets_recv       %u\n", s->node_packets_recv);
        printf("   req_call              %u\n", s->count.req_call);
        printf("   reply_call            %u\n", s->count.reply_call);
-       printf("   reply_redirect        %u\n", s->count.reply_redirect);
        printf("   req_dmaster           %u\n", s->count.req_dmaster);
        printf("   reply_dmaster         %u\n", s->count.reply_dmaster);
        printf("   reply_error           %u\n", s->count.reply_error);
-       printf("   reply_redirect        %u\n", s->count.reply_redirect);
        printf("   req_message           %u\n", s->count.req_message);
        printf("   req_finished          %u\n", s->count.req_finished);
        printf(" total_calls             %u\n", s->total_calls);
        printf(" pending_calls           %u\n", s->pending_calls);
        printf(" lockwait_calls          %u\n", s->lockwait_calls);
        printf(" pending_lockwait_calls  %u\n", s->pending_lockwait_calls);
-       printf(" max_redirect_count      %u\n", s->max_redirect_count);
        printf(" max_call_latency        %.6f sec\n", s->max_call_latency);
        printf(" max_lockwait_latency    %.6f sec\n", s->max_lockwait_latency);
 }
@@ -135,8 +132,6 @@ static int control_status_all(struct ctdb_context *ctdb)
                for (j=0;j<num_ints;j++) {
                        v2[j] += v1[j];
                }
-               status.max_redirect_count = 
-                       MAX(status.max_redirect_count, s1.max_redirect_count);
                status.max_call_latency = 
                        MAX(status.max_call_latency, s1.max_call_latency);
                status.max_lockwait_latency =