]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
- Changed algorithm for determining alive/dead state of peers.
authorwessels <>
Mon, 5 Jan 1998 07:45:43 +0000 (07:45 +0000)
committerwessels <>
Mon, 5 Jan 1998 07:45:43 +0000 (07:45 +0000)
  Instead of using a fixed number of unacknowledged ICP replies,
  it is now based on timeouts.  If there are no ICP replies
  received from a peer within 'dead_peer_timeout' seconds, then
  we call it dead.
- Added calls to getCurrentTime() in comm_{select,poll}_incoming().
- Fixed shutdown bug when the incoming and outgoing ICP socket is
  the same file descriptor.

src/cache_cf.cc
src/cf.data.pre
src/comm.cc
src/defines.h
src/main.cc
src/neighbors.cc
src/stat.cc
src/structs.h

index 077c85a40b36a3934fc9df93a377d1e77b1f5273..9b80ee6330d9f6db590bf48cb12373dc8f8a8dba 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: cache_cf.cc,v 1.240 1998/01/02 19:55:28 wessels Exp $
+ * $Id: cache_cf.cc,v 1.241 1998/01/05 00:45:43 wessels Exp $
  *
  * DEBUG: section 3     Configuration File Parsing
  * AUTHOR: Harvest Derived
@@ -595,6 +595,7 @@ parse_peer(peer ** head)
     p->http_port = CACHE_HTTP_PORT;
     p->icp_port = CACHE_ICP_PORT;
     p->weight = 1;
+    p->stats.logged_state = PEER_ALIVE;
     if ((token = strtok(NULL, w_space)) == NULL)
        self_destruct();
     p->host = xstrdup(token);
index 7f7d2120bca410a6bc357d3e502f0a75eb46b1b8..c96c3091a4588b38c5a7968c8f7b5206a84befba 100644 (file)
@@ -328,6 +328,22 @@ DOC_START
 neighbor_timeout 2 seconds
 DOC_END
 
+NAME: dead_peer_timeout
+COMMENT: (seconds)
+DEFAULT: 10 seconds
+TYPE: time_t
+LOC: Config.Timeout.deadPeer
+DOC_START
+       This controls how long Squid waits to declare a peer cache
+       as "dead."  If there are no ICP replies received in this
+       amount of time, Squid will declare the peer dead and not
+       expect to receive any further ICP replies.  However, it
+       continues to send ICP queries, and will mark the peer as
+       alive upon receipt of the first subsequent ICP reply.
+
+dead_peer_timeout 10 seconds
+DOC_END
+
 
 NAME: hierarchy_stoplist
 TYPE: wordlist
index dfd7f01d8bac1ba1a58a4db89d3672aacb88d040..9e32cf14bf05a6dd126fdf258b9aa825021d93cd 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: comm.cc,v 1.218 1998/01/02 16:30:14 wessels Exp $
+ * $Id: comm.cc,v 1.219 1998/01/05 00:45:45 wessels Exp $
  *
  * DEBUG: section 5     Socket Functions
  * AUTHOR: Harvest Derived
@@ -722,6 +722,9 @@ comm_poll_incoming(void)
     }
     if (!nfds)
        return;
+#if !ALARM_UPDATES_TIME
+    getCurrentTime();
+#endif
     polledinc = poll(pfds, nfds, 0);
     if (polledinc < 1) {
        polledinc = 0;
@@ -789,6 +792,9 @@ comm_select_incoming(void)
     }
     if (maxfd++ == 0)
        return;
+#if !ALARM_UPDATES_TIME
+    getCurrentTime();
+#endif
     polledinc = select(maxfd, &read_mask, &write_mask, NULL, &zero_tv);
     if (polledinc < 1) {
        polledinc = 0;
index 2cb866fcabdd17e35b9c6bf8a54f397fcbac2ef4..7ad048c6419deddd517a8588ca4612cde86d4d60 100644 (file)
 #define PEER_COUNTING           2
 #define ICP_AUTH_SIZE (2)      /* size of authenticator field */
 
+#define PEER_DEAD 0
+#define PEER_ALIVE 1
+
 #define ICON_MENU      "anthony-dir.gif"
 #define ICON_DIRUP     "anthony-dirup.gif"
 #define ICON_LINK      "anthony-link.gif"
index 370e3abd380f2d13eb59f1780c519b3366faca36..12378d613089bc0d5fd1e766804a10d674c6cdff 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: main.cc,v 1.200 1998/01/02 06:56:52 wessels Exp $
+ * $Id: main.cc,v 1.201 1998/01/05 00:45:46 wessels Exp $
  *
  * DEBUG: section 1     Startup and Main Loop
  * AUTHOR: Harvest Derived
@@ -331,8 +331,10 @@ serverConnectionsOpen(void)
 void
 serverConnectionsClose(void)
 {
-    /* NOTE, this function will be called repeatedly while shutdown
-     * is pending */
+    /*
+     * NOTE, this function will be called repeatedly while shutdown
+     * is pending
+     */
     int i;
     for (i = 0; i < NHttpSockets; i++) {
        if (HttpSockets[i] >= 0) {
@@ -343,28 +345,35 @@ serverConnectionsClose(void)
     }
     NHttpSockets = 0;
     if (theInIcpConnection > -1) {
-       /* NOTE, don't close outgoing ICP connection, we need to write to
-        * it during shutdown */
+       /*
+        * NOTE, don't close outgoing ICP connection, we need to write
+        * to it during shutdown.
+        */
        debug(1, 1) ("FD %d Closing ICP connection\n",
            theInIcpConnection);
-       if (theInIcpConnection != theOutIcpConnection)
+       if (theInIcpConnection != theOutIcpConnection) {
            comm_close(theInIcpConnection);
-       else
+           assert(theOutIcpConnection > -1);
+           /*
+            * Normally we only write to the outgoing ICP socket, but
+            * we also have a read handler there to catch messages sent
+            * to that specific interface.  During shutdown, we must
+            * disable reading on the outgoing socket.
+            */
+           commSetSelect(theOutIcpConnection,
+               COMM_SELECT_READ,
+               NULL,
+               NULL,
+               0);
+       } else {
            commSetSelect(theInIcpConnection,
                COMM_SELECT_READ,
                NULL,
                NULL,
                0);
+       }
        theInIcpConnection = -1;
     }
-    /*
-     * Normally we only write to the outgoing ICP socket, but we
-     * also have a read handler there to catch messages sent to that
-     * specific interface.  During shutdown, we must disable reading
-     * on the outgoing socket.
-     */
-    if (theOutIcpConnection > -1)
-       commSetSelect(theOutIcpConnection, COMM_SELECT_READ, NULL, NULL, 0);
     if (icmp_sock > -1)
        icmpClose();
 #ifdef SQUID_SNMP
index 8a5c0df197845892717db2751488a04f4ed5e870..2f0aabaa065a23279682ef60b8841f4094091504 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: neighbors.cc,v 1.170 1998/01/02 21:59:47 wessels Exp $
+ * $Id: neighbors.cc,v 1.171 1998/01/05 00:45:47 wessels Exp $
  *
  * DEBUG: section 15    Neighbor Routines
  * AUTHOR: Harvest Derived
@@ -462,12 +462,13 @@ neighborsUdpPing(request_t * request,
        }
        queries_sent++;
 
-       p->stats.ack_deficit++;
        p->stats.pings_sent++;
-       debug(15, 3) ("neighborsUdpPing: %s: ack_deficit = %d\n",
-           p->host, p->stats.ack_deficit);
        if (p->type == PEER_MULTICAST) {
-           p->stats.ack_deficit = 0;
+           /*
+            * set a bogus last_reply time so neighborUp() never
+            * says a multicast peer is dead.
+            */
+           p->stats.last_reply = squid_curtime;
            (*exprep) += p->mcast.n_replies_expected;
        } else if (neighborUp(p)) {
            /* its alive, expect a reply from it */
@@ -475,12 +476,14 @@ neighborsUdpPing(request_t * request,
        } else {
            /* Neighbor is dead; ping it anyway, but don't expect a reply */
            /* log it once at the threshold */
-           if ((p->stats.ack_deficit == HIER_MAX_DEFICIT)) {
+           if (p->stats.logged_state == PEER_ALIVE) {
                debug(15, 0) ("Detected DEAD %s: %s/%d/%d\n",
                    neighborTypeStr(p),
                    p->host, p->http_port, p->icp_port);
+               p->stats.logged_state = PEER_DEAD;
            }
        }
+       p->stats.last_query = squid_curtime;
     }
     if ((first_ping = first_ping->next) == NULL)
        first_ping = Config.peers;
@@ -523,13 +526,13 @@ neighborAlive(peer * p, const MemObject * mem, const icp_common_t * header)
 {
     int rtt;
     int n;
-    /* Neighbor is alive, reset the ack deficit */
-    if (p->stats.ack_deficit >= HIER_MAX_DEFICIT) {
+    if (p->stats.logged_state == PEER_DEAD) {
        debug(15, 0) ("Detected REVIVED %s: %s/%d/%d\n",
            neighborTypeStr(p),
            p->host, p->http_port, p->icp_port);
+       p->stats.logged_state = PEER_ALIVE;
     }
-    p->stats.ack_deficit = 0;
+    p->stats.last_reply = squid_curtime;
     n = ++p->stats.pings_acked;
     if ((icp_opcode) header->opcode <= ICP_END)
        p->stats.counts[header->opcode]++;
@@ -732,7 +735,9 @@ neighborUp(const peer * p)
 {
     if (!p->tcp_up)
        return 0;
-    if (p->stats.ack_deficit >= HIER_MAX_DEFICIT)
+    if (squid_curtime - p->stats.last_query > Config.Timeout.deadPeer)
+       return 1;
+    if (p->stats.last_query - p->stats.last_reply >= Config.Timeout.deadPeer)
        return 0;
     return 1;
 }
index 072faa57e20b9b8d2dfb98c2fb10a6db1f65efff..ee48f62590efae9393def98a8d3e3b2eadecba09 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: stat.cc,v 1.179 1997/12/03 01:31:40 wessels Exp $
+ * $Id: stat.cc,v 1.180 1998/01/05 00:45:48 wessels Exp $
  *
  * DEBUG: section 18    Cache Manager Statistics
  * AUTHOR: Harvest Derived
@@ -406,7 +406,10 @@ dump_peers(StoreEntry * sentry, peer * peers)
        storeAppendPrintf(sentry, "{Status     : %s}\n",
            neighborUp(e) ? "Up" : "Down");
        storeAppendPrintf(sentry, "{AVG RTT    : %d msec}\n", e->stats.rtt);
-       storeAppendPrintf(sentry, "{ACK DEFICIT: %8d}\n", e->stats.ack_deficit);
+       storeAppendPrintf(sentry, "{LAST QUERY : %8d seconds ago}\n",
+           (int) (squid_curtime - e->stats.last_query));
+       storeAppendPrintf(sentry, "{LAST REPLY : %8d seconds ago}\n",
+           (int) (squid_curtime - e->stats.last_reply));
        storeAppendPrintf(sentry, "{PINGS SENT : %8d}\n", e->stats.pings_sent);
        storeAppendPrintf(sentry, "{PINGS ACKED: %8d %3d%%}\n",
            e->stats.pings_acked,
index 34a838ef1fef8013dab154b009a30a0cbf499531..8c0d7f6fb82f918287574ee2a5cce1c0bb16e2d0 100644 (file)
@@ -172,6 +172,7 @@ struct _SquidConfig {
        time_t request;
        time_t pconn;
        time_t siteSelect;
+       time_t deadPeer;
     } Timeout;
     size_t maxRequestSize;
     struct {
@@ -629,13 +630,15 @@ struct _peer {
     struct {
        int pings_sent;
        int pings_acked;
-       int ack_deficit;
        int fetches;
        int rtt;
        int counts[ICP_END];
        int ignored_replies;
        int n_keepalives_sent;
        int n_keepalives_recv;
+       time_t last_query;
+       time_t last_reply;
+       int logged_state;       /* so we can print dead/revived msgs */
     } stats;
     u_short icp_port;
     u_short http_port;