add a special VNN that means "all" nodes so that a message can be
authorRonnie Sahlberg <sahlberg@ronnie>
Fri, 27 Apr 2007 13:16:17 +0000 (23:16 +1000)
committerRonnie Sahlberg <sahlberg@ronnie>
Fri, 27 Apr 2007 13:16:17 +0000 (23:16 +1000)
broadcasted to all daemons in the cluster

change the message dispatch routine for sending messages so that it
allows several clients to use the same srvid
messages are then passed on to all clients that have that srvid

common/ctdb_daemon.c
common/ctdb_message.c
include/ctdb_private.h

index 0e810a0b2ebfc63de6d285599170b69209689141..00baa4dd91542c66434663fe4d097a7142eacca9 100644 (file)
@@ -266,7 +266,7 @@ static void daemon_request_message_from_client(struct ctdb_client *client,
                ctdb_request_message(client->ctdb, (struct ctdb_req_header *)c);
                return;
        }
-       
+
        /* its for a remote node */
        data.dptr = &c->data[0];
        data.dsize = c->datalen;
index 70fcf00c4dde15c37de950fd378021c3d2b60f9b..95df3c2c8de7ade9ae8ae8bd7f2117f32e289cd0 100644 (file)
@@ -39,16 +39,11 @@ static int ctdb_dispatch_message(struct ctdb_context *ctdb, uint32_t srvid, TDB_
        /* XXX we need a must faster way of finding the matching srvid
           - maybe a tree? */
        for (ml=ctdb->message_list;ml;ml=ml->next) {
-               if (ml->srvid == srvid || ml->srvid == CTDB_SRVID_ALL) break;
-       }
-       if (ml == NULL) {
-               DEBUG(1,(__location__ " daemon vnn:%d  no msg handler for srvid=%u\n", 
-                        ctdb_get_vnn(ctdb), srvid));
-               /* no registered message handler */
-               return -1;
+               if (ml->srvid == srvid || ml->srvid == CTDB_SRVID_ALL) {
+                       ml->message_handler(ctdb, srvid, data, ml->message_private);
+               }
        }
 
-       ml->message_handler(ctdb, srvid, data, ml->message_private);
        return 0;
 }
 
@@ -141,8 +136,28 @@ int ctdb_daemon_send_message(struct ctdb_context *ctdb, uint32_t vnn,
        r->srvid         = srvid;
        r->datalen       = data.dsize;
        memcpy(&r->data[0], data.dptr, data.dsize);
-       
-       ctdb_queue_packet(ctdb, &r->hdr);
+
+       if (vnn != CTDB_BROADCAST_VNN) {
+               ctdb_queue_packet(ctdb, &r->hdr);
+       } else {
+               struct ctdb_node *node;
+               int i;
+
+               /* this was a broadcast message
+                  loop over all other nodes and send them each a copy
+               */
+               for (i=0; i<ctdb_get_num_nodes(ctdb); i++) {
+                       node=ctdb->nodes[i];
+
+                       /* we do not send the message to ourself */
+                       if (node && node->vnn!=ctdb->vnn) {
+                               r->hdr.destnode = node->vnn;
+                               ctdb_queue_packet(ctdb, &r->hdr);
+                       }
+               }
+               /* also make sure to dispatch the message locally */
+               ctdb_dispatch_message(ctdb, srvid, data);
+       }
 
        talloc_free(r);
        return 0;
index dfa642ae9f5f0ad380d85d61972217f0afe8cab0..612290805c797c48066ac2578460134bcd8495e4 100644 (file)
 #define CTDB_DS_ALIGNMENT 8
 
 
-#define CTDB_NULL_FUNC 0xf0000001
-#define CTDB_CURRENT_NODE 0xF0000001
+#define CTDB_NULL_FUNC     0xF0000001
 
+#define CTDB_CURRENT_NODE  0xF0000001
+#define CTDB_BROADCAST_VNN 0xF0000002
 /*
   an installed ctdb remote call
 */