]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug #1058: balance_on_multiple_ip directive to make it possible to
authorhno <>
Mon, 18 Oct 2004 18:20:09 +0000 (18:20 +0000)
committerhno <>
Mon, 18 Oct 2004 18:20:09 +0000 (18:20 +0000)
turn of the automatic round-robin on sites with multiple IP addresses

optimized ipcache usage on reload when using the internal TTL aware
dns client.

src/cf.data.pre
src/client_side_reply.cc
src/comm.cc
src/ipcache.cc
src/protos.h
src/structs.h

index 5fbea85db1e4aac877529e76aae744833d782a11..4d429dfb3a75b566d3946a2bbac1a16830929874 100644 (file)
@@ -1,6 +1,6 @@
 
 #
-# $Id: cf.data.pre,v 1.359 2004/10/10 02:49:04 hno Exp $
+# $Id: cf.data.pre,v 1.360 2004/10/18 12:20:09 hno Exp $
 #
 #
 # SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -4250,6 +4250,19 @@ DOC_START
        disable persistent connections with clients and/or servers.
 DOC_END
 
+NAME: balance_on_multiple_ip
+TYPE: onoff
+LOC: Config.onoff.balance_on_multiple_ip
+DEFAULT: on
+DOC_START
+       Some load balancing servers based on round robin DNS have been 
+       found not to preserve user session state across requests
+       to different IP addresses.
+
+       By default Squid rotates IP's per request. By disabling
+       this directive only connection failure triggers rotation.
+DOC_END
+
 NAME: pipeline_prefetch
 TYPE: onoff
 LOC: Config.onoff.pipeline_prefetch
index 5c9fe54fcb4458f6b79f2e675352ac4efce93c54..2ce6e16ef711f0723293d1e2d7fe5a3b135958e7 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: client_side_reply.cc,v 1.73 2004/10/14 23:32:45 hno Exp $
+ * $Id: client_side_reply.cc,v 1.74 2004/10/18 12:20:09 hno Exp $
  *
  * DEBUG: section 88    Client-side Reply Routines
  * AUTHOR: Robert Collins (Originally Duane Wessels in client_side.c)
@@ -1496,17 +1496,39 @@ clientReplyContext::identifyFoundObject(StoreEntry *newEntry)
     }
 
     e = http->storeEntry();
-    /* Release negatively cached IP-cache entries on reload */
+    /* Release IP-cache entries on reload */
+
+    if (r->flags.nocache) {
+
+#if USE_DNSSERVERS
 
-    if (r->flags.nocache)
         ipcacheInvalidate(r->host);
 
+#else
+
+        ipcacheInvalidateNegative(r->host);
+
+#endif /* USE_DNSSERVERS */
+
+    }
+
 #if HTTP_VIOLATIONS
 
-    else if (r->flags.nocache_hack)
+    else if (r->flags.nocache_hack) {
+
+#if USE_DNSSERVERS
+
         ipcacheInvalidate(r->host);
 
-#endif
+#else
+
+        ipcacheInvalidateNegative(r->host);
+
+#endif /* USE_DNSSERVERS */
+
+    }
+
+#endif /* HTTP_VIOLATIONS */
 #if USE_CACHE_DIGESTS
 
     lookup_type = http->storeEntry() ? "HIT" : "MISS";
index 7e9e5b41eb531cd34896eaaa1d3ea8d0fe5a0e44..0d6666a62dc1291c3c261dc46fc398cf5160c380 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: comm.cc,v 1.395 2004/08/30 05:12:31 robertc Exp $
+ * $Id: comm.cc,v 1.396 2004/10/18 12:20:09 hno Exp $
  *
  * DEBUG: section 5     Socket Functions
  * AUTHOR: Harvest Derived
@@ -1231,9 +1231,14 @@ commConnectDnsHandle(const ipcache_addrs * ia, void *data)
 
     assert(ia->cur < ia->count);
     cs->in_addr = ia->in_addrs[ia->cur];
-    ipcacheCycleAddr(cs->host, NULL);
+
+    if (Config.onoff.balance_on_multiple_ip)
+        ipcacheCycleAddr(cs->host, NULL);
+
     cs->addrcount = ia->count;
+
     cs->connstart = squid_curtime;
+
     cs->connect();
 }
 
index 61166ff259264997d9f34fdaa078ccf6bc857e84..c6635f6f7d4038dd498912349799a8e856357d88 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: ipcache.cc,v 1.245 2004/10/15 21:12:47 hno Exp $
+ * $Id: ipcache.cc,v 1.246 2004/10/18 12:20:10 hno Exp $
  *
  * DEBUG: section 14    IP Cache
  * AUTHOR: Harvest Derived
@@ -129,6 +129,7 @@ ipcache_testname(void)
 static void
 ipcacheRelease(ipcache_entry * i)
 {
+    debug(14, 3) ("ipcacheRelease: Releasing entry for '%s'\n", (const char *) i->hash.key);
     hash_remove_link(ip_table, (hash_link *) i);
     dlinkDelete(&i->lru, &lru_list);
     ipcacheFreeEntry(i);
@@ -394,7 +395,7 @@ ipcacheParse(ipcache_entry *i, rfc1035_rr * answers, int nr, const char *error_m
 
     assert(answers);
 
-    for (j = 0, k = 0; k < nr; k++) {
+    for (k = 0; k < nr; k++) {
         if (answers[k].type != RFC1035_TYPE_A)
             continue;
 
@@ -685,6 +686,23 @@ ipcacheInvalidate(const char *name)
      */
 }
 
+void
+ipcacheInvalidateNegative(const char *name)
+{
+    ipcache_entry *i;
+
+    if ((i = ipcache_get(name)) == NULL)
+        return;
+
+    if (i->flags.negcached)
+        i->expires = squid_curtime;
+
+    /*
+     * NOTE, don't call ipcacheRelease here becuase we might be here due
+     * to a thread started from a callback.
+     */
+}
+
 ipcache_addrs *
 ipcacheCheckNumeric(const char *name)
 {
@@ -799,6 +817,7 @@ ipcacheMarkBadAddr(const char *name, struct in_addr addr)
     {
         ia->bad_mask[k] = TRUE;
         ia->badcount++;
+        i->expires = XMIN(squid_curtime + XMAX((time_t)60, Config.negativeDnsTtl), i->expires);
         debug(14, 2) ("ipcacheMarkBadAddr: %s [%s]\n", name, inet_ntoa(addr));
     }
 
index cd71c66d5b624f9f1d849607bceb1accec8157ad..c9da70aaade037641eb37fab5e61ec512a2ec68e 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: protos.h,v 1.495 2004/08/30 05:12:31 robertc Exp $
+ * $Id: protos.h,v 1.496 2004/10/18 12:20:10 hno Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -487,10 +487,9 @@ SQUIDCEXTERN void ipcache_nbgethostbyname(const char *name,
 SQUIDCEXTERN EVH ipcache_purgelru;
 SQUIDCEXTERN const ipcache_addrs *ipcache_gethostbyname(const char *, int flags);
 SQUIDCEXTERN void ipcacheInvalidate(const char *);
-SQUIDCEXTERN void ipcacheReleaseInvalid(const char *);
+SQUIDCEXTERN void ipcacheInvalidateNegative(const char *);
 SQUIDCEXTERN void ipcache_init(void);
 SQUIDCEXTERN void stat_ipcache_get(StoreEntry *);
-SQUIDCEXTERN int ipcacheQueueDrain(void);
 SQUIDCEXTERN void ipcacheCycleAddr(const char *name, ipcache_addrs *);
 
 SQUIDCEXTERN void ipcacheMarkBadAddr(const char *name, struct in_addr);
index 321be0dfa5ed1c7ea47f6b8c0245d2d28eb70af3..2ac1adf719710d52c608d32923b3f1c74db724b0 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: structs.h,v 1.492 2004/10/14 23:31:30 hno Exp $
+ * $Id: structs.h,v 1.493 2004/10/18 12:20:10 hno Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -556,6 +556,7 @@ struct _SquidConfig
 #endif
 
         int request_entities;
+        int balance_on_multiple_ip;
         int check_hostnames;
         int via;
         int emailErrData;