From ff9970cc48d27a18cc5140eddfeb15e7348bd118 Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Fri, 8 May 2009 23:22:30 +1200 Subject: [PATCH] Author: Mark Nottingham Make PEER_TCP_MAGIC_COUNT configurable Squid will consider a peer dead when it has ten connect failures; this is hardcoded in as PEER_TCP_MAGIC_COUNT. The attached patch makes it a per-peer configuration option, defaulting to PEER_TCP_MAGIC_COUNT. --- doc/release-notes/release-3.1.sgml | 6 +++++- src/cache_cf.cc | 6 +++++- src/cf.data.pre | 5 +++++ src/neighbors.cc | 9 ++++++--- src/structs.h | 1 + 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/doc/release-notes/release-3.1.sgml b/doc/release-notes/release-3.1.sgml index 7508a7b6c2..2db731f905 100644 --- a/doc/release-notes/release-3.1.sgml +++ b/doc/release-notes/release-3.1.sgml @@ -835,7 +835,7 @@ NOCOMMENT_START cache_mem

Default size increased to 256MB. - cache_peer htcp-no-clr htcp-no-purge-clr htcp-only-clr htcp-forward-clr connection-auth[=on|off|auto] + cache_peer htcp-no-clr htcp-no-purge-clr htcp-only-clr htcp-forward-clr connection-auth[=on|off|auto] connect-fail-limit=N

New Options. use 'htcp-no-clr' to send HTCP to the neighbor but without @@ -857,6 +857,10 @@ NOCOMMENT_START and any such challenges received from there should be ignored. Default is 'auto' to automatically determine the status of the peer. + + use 'connect-fail-limit=nn' to specify how many times + connecting to a peer must fail before it is marked as + down. Default is 10. cache_store_log diff --git a/src/cache_cf.cc b/src/cache_cf.cc index debb829dcd..0d9c54226b 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -1777,8 +1777,9 @@ parse_peer(peer ** head) rfc1738_unescape(p->login); } else if (!strncasecmp(token, "connect-timeout=", 16)) { p->connect_timeout = xatoi(token + 16); + } else if (!strncasecmp(token, "connect-fail-limit=", 19)) { + p->connect_fail_limit = xatoi(token + 19); #if USE_CACHE_DIGESTS - } else if (!strncasecmp(token, "digest-url=", 11)) { p->digest_url = xstrdup(token + 11); #endif @@ -1861,6 +1862,9 @@ parse_peer(peer ** head) if (p->weight < 1) p->weight = 1; + if (p->connect_fail_limit < 1) + p->connect_fail_limit = 1; + p->icp.version = ICP_VERSION_CURRENT; p->test_fd = -1; diff --git a/src/cf.data.pre b/src/cf.data.pre index f60b902311..382f84dfee 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -1602,6 +1602,7 @@ DOC_START no-delay login=user:password | PASS | *:password connect-timeout=nn + connect-fail-limit=nn digest-url=url allow-miss max-conn=n @@ -1727,6 +1728,10 @@ DOC_START specific connect timeout (also see the peer_connect_timeout directive) + use 'connect-fail-limit=nn' to specify how many times + connecting to a peer must fail before it is marked as + down. Default is 10. + use 'digest-url=url' to tell Squid to fetch the cache digest (if digests are enabled) for this host from the specified URL rather than the Squid default diff --git a/src/neighbors.cc b/src/neighbors.cc index b40c53f840..3a190fbd9b 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -1255,7 +1255,7 @@ peerDNSConfigure(const ipcache_addrs * ia, void *data) return; } - p->tcp_up = PEER_TCP_MAGIC_COUNT; + p->tcp_up = p->connect_fail_limit; for (j = 0; j < (int) ia->count && j < PEER_MAX_ADDRESSES; j++) { p->addresses[j] = ia->in_addrs[j]; @@ -1330,12 +1330,12 @@ peerConnectSucceded(peer * p) { if (!p->tcp_up) { debugs(15, 2, "TCP connection to " << p->host << "/" << p->http_port << " succeded"); - p->tcp_up = PEER_TCP_MAGIC_COUNT; // NP: so peerAlive(p) works properly. + p->tcp_up = p->connect_fail_limit; // NP: so peerAlive(p) works properly. peerAlive(p); if (!p->n_addresses) ipcache_nbgethostbyname(p->host, peerDNSConfigure, p); } else - p->tcp_up = PEER_TCP_MAGIC_COUNT; + p->tcp_up = p->connect_fail_limit; } /// called by Comm when test_fd is closed while connect is in progress @@ -1611,6 +1611,9 @@ dump_peer_options(StoreEntry * sentry, peer * p) if (p->connect_timeout > 0) storeAppendPrintf(sentry, " connect-timeout=%d", (int) p->connect_timeout); + if (p->connect_fail_limit != PEER_TCP_MAGIC_COUNT) + storeAppendPrintf(sentry, " connect-fail-limit=%d", p->connect_fail_limit); + #if USE_CACHE_DIGESTS if (p->digest_url) diff --git a/src/structs.h b/src/structs.h index f28c9cca39..e679e8f72e 100644 --- a/src/structs.h +++ b/src/structs.h @@ -929,6 +929,7 @@ struct peer { char *login; /* Proxy authorization */ time_t connect_timeout; + int connect_fail_limit; int max_conn; char *domain; /* Forced domain */ #if USE_SSL -- 2.47.3