make sure we find out about new nodes as fast as possible
authorAndrew Tridgell <tridge@samba.org>
Fri, 25 May 2007 12:07:45 +0000 (22:07 +1000)
committerAndrew Tridgell <tridge@samba.org>
Fri, 25 May 2007 12:07:45 +0000 (22:07 +1000)
tcp/ctdb_tcp.h
tcp/tcp_connect.c

index a34cd9736da4a16e73f1fa9b2a078d70fa8ceedb..cb314f3a6f775174196c3451b8836b2b4dd6f467 100644 (file)
@@ -39,6 +39,8 @@ struct ctdb_incoming {
 struct ctdb_tcp_node {
        int fd;
        struct ctdb_queue *queue;
+       struct fd_event *connect_fde;
+       struct timed_event *connect_te;
 };
 
 
index 8a2f70c7b1f4d9385e0c125f796e395e9dce5178..fa249d5fba039821e19b425e51ed6dacb13cb899 100644 (file)
@@ -50,6 +50,7 @@ void ctdb_tcp_tnode_cb(uint8_t *data, size_t cnt, void *private_data)
        /* start a new connect cycle to try to re-establish the
           link */
        ctdb_queue_set_fd(tnode->queue, -1);
+       tnode->fd = -1;
        event_add_timed(node->ctdb->ev, node, timeval_zero(), 
                        ctdb_tcp_node_connect, node);
 }
@@ -69,6 +70,9 @@ static void ctdb_node_connect_write(struct event_context *ev, struct fd_event *f
        socklen_t len = sizeof(error);
        int one = 1;
 
+       talloc_free(tnode->connect_te);
+       tnode->connect_te = NULL;
+
        if (getsockopt(tnode->fd, SOL_SOCKET, SO_ERROR, &error, &len) != 0 ||
            error != 0) {
                talloc_free(fde);
@@ -120,6 +124,13 @@ void ctdb_tcp_node_connect(struct event_context *ev, struct timed_event *te,
         struct sockaddr_in sock_in;
         struct sockaddr_in sock_out;
 
+       if (tnode->fd != -1) {
+               talloc_free(tnode->connect_fde);
+               tnode->connect_fde = NULL;
+               close(tnode->fd);
+               tnode->fd = -1;
+       }
+
        tnode->fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
 
        set_nonblocking(tnode->fd);
@@ -163,8 +174,15 @@ void ctdb_tcp_node_connect(struct event_context *ev, struct timed_event *te,
        }
 
        /* non-blocking connect - wait for write event */
-       event_add_fd(node->ctdb->ev, node, tnode->fd, EVENT_FD_WRITE|EVENT_FD_READ, 
-                    ctdb_node_connect_write, node);
+       tnode->connect_fde = event_add_fd(node->ctdb->ev, node, tnode->fd, 
+                                         EVENT_FD_WRITE|EVENT_FD_READ, 
+                                         ctdb_node_connect_write, node);
+
+       /* don't give it long to connect - retry in one second. This ensures
+          that we find a node is up quickly (tcp normally backs off a syn reply
+          delay by quite a lot) */
+       tnode->connect_te = event_add_timed(ctdb->ev, node, timeval_current_ofs(1, 0), 
+                                           ctdb_tcp_node_connect, node);
 }
 
 /*