Remove the structure ctdb_control_tcp_vnn since this is identical to the structure...
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Wed, 18 Aug 2010 02:36:03 +0000 (12:36 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Wed, 18 Aug 2010 02:36:03 +0000 (12:36 +1000)
Add a new "ctdb deltickle" command to delete tickles from the database.
This can ONLY be used for tickles created by "ctdb addtickle".

Push any "addtickle/deltickle" updates to other nodes every TickleUpdateInterval seconds'

include/ctdb_private.h
include/ctdb_protocol.h
server/ctdb_control.c
server/ctdb_takeover.c
tools/ctdb.c

index af271f4bfb5c839ae64bc539f22a33d115b90fad..8166e1515c8a3fcb1c508e6d2c2ce13c91c63791 100644 (file)
@@ -46,6 +46,7 @@ extern pid_t ctdbd_pid;
 
 /*
   a tcp connection description
+  also used by tcp_add and tcp_remove controls
  */
 struct ctdb_tcp_connection {
        ctdb_sock_addr src_addr;
@@ -541,14 +542,6 @@ struct ctdb_control_gratious_arp {
        char iface[1];
 };
 
-/*
-  struct for tcp_add and tcp_remove controls
- */
-struct ctdb_control_tcp_vnn {
-       ctdb_sock_addr src;
-       ctdb_sock_addr dest;
-};
-
 /*
   persistent store control - update this record on all other nodes
  */
@@ -1120,7 +1113,7 @@ int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map *nodemap);
 
 int32_t ctdb_control_tcp_client(struct ctdb_context *ctdb, uint32_t client_id, 
                                TDB_DATA indata);
-int32_t ctdb_control_tcp_add(struct ctdb_context *ctdb, TDB_DATA indata);
+int32_t ctdb_control_tcp_add(struct ctdb_context *ctdb, TDB_DATA indata, bool tcp_update_needed);
 int32_t ctdb_control_tcp_remove(struct ctdb_context *ctdb, TDB_DATA indata);
 int32_t ctdb_control_startup(struct ctdb_context *ctdb, uint32_t vnn);
 int32_t ctdb_control_kill_tcp(struct ctdb_context *ctdb, TDB_DATA indata);
index 7a5d32de159d6b052dce478a19289672a7daa402..99765d40937855ab26670646ff9898fef306195c 100644 (file)
@@ -329,6 +329,7 @@ enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS          = 0,
                    CTDB_CONTROL_GET_PUBLIC_IP_INFO      = 123,
                    CTDB_CONTROL_GET_IFACES              = 124,
                    CTDB_CONTROL_SET_IFACE_LINK_STATE    = 125,
+                   CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE  = 126,
 };
 
 /*
index cbacd17bedd04eee24f58c9aec3164271fbd9633..bfb7bd1c29e6c7620b7b8b096d203b8f93256d97 100644 (file)
@@ -334,8 +334,16 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                return ctdb_control_startup(ctdb, srcnode);
 
        case CTDB_CONTROL_TCP_ADD: 
-               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_control_tcp_vnn));
-               return ctdb_control_tcp_add(ctdb, indata);
+               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_tcp_connection));
+               return ctdb_control_tcp_add(ctdb, indata, false);
+
+       case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE: 
+               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_tcp_connection));
+               return ctdb_control_tcp_add(ctdb, indata, true);
+
+       case CTDB_CONTROL_TCP_REMOVE: 
+               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_tcp_connection));
+               return ctdb_control_tcp_remove(ctdb, indata);
 
        case CTDB_CONTROL_SET_TUNABLE:
                return ctdb_control_set_tunable(ctdb, indata);
index 89e9cef221b2d9aa1677c3c784ee69b7d8a8fcf9..cc801b1f492470c709ed8642c85468d7adb392a6 100644 (file)
@@ -1562,7 +1562,7 @@ int32_t ctdb_control_tcp_client(struct ctdb_context *ctdb, uint32_t client_id,
        struct ctdb_control_tcp_addr new_addr;
        struct ctdb_control_tcp_addr *tcp_sock = NULL;
        struct ctdb_tcp_list *tcp;
-       struct ctdb_control_tcp_vnn t;
+       struct ctdb_tcp_connection t;
        int ret;
        TDB_DATA data;
        struct ctdb_client_ip *ip;
@@ -1642,8 +1642,8 @@ int32_t ctdb_control_tcp_client(struct ctdb_context *ctdb, uint32_t client_id,
 
        DLIST_ADD(client->tcp_list, tcp);
 
-       t.src  = tcp_sock->src;
-       t.dest = tcp_sock->dest;
+       t.src_addr = tcp_sock->src;
+       t.dst_addr = tcp_sock->dest;
 
        data.dptr = (uint8_t *)&t;
        data.dsize = sizeof(t);
@@ -1699,22 +1699,24 @@ static struct ctdb_tcp_connection *ctdb_tcp_find(struct ctdb_tcp_array *array,
        return NULL;
 }
 
+
+
 /*
   called by a daemon to inform us of a TCP connection that one of its
   clients managing that should tickled with an ACK when IP takeover is
   done
  */
-int32_t ctdb_control_tcp_add(struct ctdb_context *ctdb, TDB_DATA indata)
+int32_t ctdb_control_tcp_add(struct ctdb_context *ctdb, TDB_DATA indata, bool tcp_update_needed)
 {
-       struct ctdb_control_tcp_vnn *p = (struct ctdb_control_tcp_vnn *)indata.dptr;
+       struct ctdb_tcp_connection *p = (struct ctdb_tcp_connection *)indata.dptr;
        struct ctdb_tcp_array *tcparray;
        struct ctdb_tcp_connection tcp;
        struct ctdb_vnn *vnn;
 
-       vnn = find_public_ip_vnn(ctdb, &p->dest);
+       vnn = find_public_ip_vnn(ctdb, &p->dst_addr);
        if (vnn == NULL) {
                DEBUG(DEBUG_INFO,(__location__ " got TCP_ADD control for an address which is not a public address '%s'\n",
-                       ctdb_addr_to_str(&p->dest)));
+                       ctdb_addr_to_str(&p->dst_addr)));
 
                return -1;
        }
@@ -1734,16 +1736,20 @@ int32_t ctdb_control_tcp_add(struct ctdb_context *ctdb, TDB_DATA indata)
                tcparray->connections = talloc_size(tcparray, sizeof(struct ctdb_tcp_connection));
                CTDB_NO_MEMORY(ctdb, tcparray->connections);
 
-               tcparray->connections[tcparray->num].src_addr = p->src;
-               tcparray->connections[tcparray->num].dst_addr = p->dest;
+               tcparray->connections[tcparray->num].src_addr = p->src_addr;
+               tcparray->connections[tcparray->num].dst_addr = p->dst_addr;
                tcparray->num++;
+
+               if (tcp_update_needed) {
+                       vnn->tcp_update_needed = true;
+               }
                return 0;
        }
 
 
        /* Do we already have this tickle ?*/
-       tcp.src_addr = p->src;
-       tcp.dst_addr = p->dest;
+       tcp.src_addr = p->src_addr;
+       tcp.dst_addr = p->dst_addr;
        if (ctdb_tcp_find(vnn->tcp_array, &tcp) != NULL) {
                DEBUG(DEBUG_DEBUG,("Already had tickle info for %s:%u for vnn:%u\n",
                        ctdb_addr_to_str(&tcp.dst_addr),
@@ -1759,8 +1765,8 @@ int32_t ctdb_control_tcp_add(struct ctdb_context *ctdb, TDB_DATA indata)
        CTDB_NO_MEMORY(ctdb, tcparray->connections);
 
        vnn->tcp_array = tcparray;
-       tcparray->connections[tcparray->num].src_addr = p->src;
-       tcparray->connections[tcparray->num].dst_addr = p->dest;
+       tcparray->connections[tcparray->num].src_addr = p->src_addr;
+       tcparray->connections[tcparray->num].dst_addr = p->dst_addr;
        tcparray->num++;
                                
        DEBUG(DEBUG_INFO,("Added tickle info for %s:%u from vnn %u\n",
@@ -1768,6 +1774,10 @@ int32_t ctdb_control_tcp_add(struct ctdb_context *ctdb, TDB_DATA indata)
                ntohs(tcp.dst_addr.ip.sin_port),
                vnn->pnn));
 
+       if (tcp_update_needed) {
+               vnn->tcp_update_needed = true;
+       }
+
        return 0;
 }
 
@@ -1835,6 +1845,20 @@ static void ctdb_remove_tcp_connection(struct ctdb_context *ctdb, struct ctdb_tc
 }
 
 
+/*
+  called by a daemon to inform us of a TCP connection that one of its
+  clients used are no longer needed in the tickle database
+ */
+int32_t ctdb_control_tcp_remove(struct ctdb_context *ctdb, TDB_DATA indata)
+{
+       struct ctdb_tcp_connection *conn = (struct ctdb_tcp_connection *)indata.dptr;
+
+       ctdb_remove_tcp_connection(ctdb, conn);
+
+       return 0;
+}
+
+
 /*
   called when a daemon restarts - send all tickes for all public addresses
   we are serving immediately to the new node.
index 4285ef53023686ce0f82a0c1e4a09c97f4d9148b..d509f171742dac0d39858df2ef3ed0b4ce707f4e 100644 (file)
@@ -981,11 +981,11 @@ static int control_recmaster(struct ctdb_context *ctdb, int argc, const char **a
 }
 
 /*
-  add a list of all tickle to a public address
+  add a tickle to a public address
  */
 static int control_add_tickle(struct ctdb_context *ctdb, int argc, const char **argv)
 {
-       struct ctdb_control_tcp_vnn t;
+       struct ctdb_tcp_connection t;
        TDB_DATA data;
        int ret;
 
@@ -993,11 +993,11 @@ static int control_add_tickle(struct ctdb_context *ctdb, int argc, const char **
                usage();
        }
 
-       if (parse_ip_port(argv[0], &t.src) == 0) {
+       if (parse_ip_port(argv[0], &t.src_addr) == 0) {
                DEBUG(DEBUG_ERR,("Wrongly formed ip address '%s'\n", argv[0]));
                return -1;
        }
-       if (parse_ip_port(argv[1], &t.dest) == 0) {
+       if (parse_ip_port(argv[1], &t.dst_addr) == 0) {
                DEBUG(DEBUG_ERR,("Wrongly formed ip address '%s'\n", argv[1]));
                return -1;
        }
@@ -1006,7 +1006,7 @@ static int control_add_tickle(struct ctdb_context *ctdb, int argc, const char **
        data.dsize = sizeof(t);
 
        /* tell all nodes about this tcp connection */
-       ret = ctdb_control(ctdb, options.pnn, 0, CTDB_CONTROL_TCP_ADD,
+       ret = ctdb_control(ctdb, options.pnn, 0, CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE,
                           0, data, ctdb, NULL, NULL, NULL, NULL);
        if (ret != 0) {
                DEBUG(DEBUG_ERR,("Failed to add tickle\n"));
@@ -1017,6 +1017,43 @@ static int control_add_tickle(struct ctdb_context *ctdb, int argc, const char **
 }
 
 
+/*
+  delete a tickle from a node
+ */
+static int control_del_tickle(struct ctdb_context *ctdb, int argc, const char **argv)
+{
+       struct ctdb_tcp_connection t;
+       TDB_DATA data;
+       int ret;
+
+       if (argc < 2) {
+               usage();
+       }
+
+       if (parse_ip_port(argv[0], &t.src_addr) == 0) {
+               DEBUG(DEBUG_ERR,("Wrongly formed ip address '%s'\n", argv[0]));
+               return -1;
+       }
+       if (parse_ip_port(argv[1], &t.dst_addr) == 0) {
+               DEBUG(DEBUG_ERR,("Wrongly formed ip address '%s'\n", argv[1]));
+               return -1;
+       }
+
+       data.dptr = (uint8_t *)&t;
+       data.dsize = sizeof(t);
+
+       /* tell all nodes about this tcp connection */
+       ret = ctdb_control(ctdb, options.pnn, 0, CTDB_CONTROL_TCP_REMOVE,
+                          0, data, ctdb, NULL, NULL, NULL, NULL);
+       if (ret != 0) {
+               DEBUG(DEBUG_ERR,("Failed to remove tickle\n"));
+               return -1;
+       }
+       
+       return 0;
+}
+
+
 /*
   get a list of all tickles for this pnn
  */
@@ -4425,6 +4462,8 @@ static const struct {
        { "gettickles",      control_get_tickles,       false,  false, "get the list of tickles registered for this ip", "<ip>" },
        { "addtickle",       control_add_tickle,        false,  false, "add a tickle for this ip", "<ip>:<port> <ip>:<port>" },
 
+       { "deltickle",       control_del_tickle,        false,  false, "delete a tickle from this ip", "<ip>:<port> <ip>:<port>" },
+
        { "regsrvid",        regsrvid,                  false,  false, "register a server id", "<pnn> <type> <id>" },
        { "unregsrvid",      unregsrvid,                false,  false, "unregister a server id", "<pnn> <type> <id>" },
        { "chksrvid",        chksrvid,                  false,  false, "check if a server id exists", "<pnn> <type> <id>" },