Hi

I don't know if Squid already has this feature. If so I didn't figure out how.
I'm working in a patch to tag an originserver as 'dead' if there's a connection
refuse or a read_timeout.
fwdServerSetDead() does the trick, called from fwdServerClosed().
Within fwdStart() I'm calling "syncronously" fwdServerSetAlive() and trying to
loop through peers testing which is dead, to set it alive, after a given time
(which is for while hardcoded as 5 seconds).
My problem is that I'm not be able to loop through peers. All my methods
failed (look the last one, which is commented). Maybe I misunderstood
something.
Any help which is the best way to look around peers?

regards
Lucas Brasilino
diff -Nur squid-2.6.STABLE9.orig/src/forward.c squid-2.6.STABLE9/src/forward.c
--- squid-2.6.STABLE9.orig/src/forward.c	2007-01-18 22:21:01.000000000 -0200
+++ squid-2.6.STABLE9/src/forward.c	2007-01-30 16:31:56.000000000 -0200
@@ -67,6 +67,9 @@
 static Logfile *logfile = NULL;
 #endif
 
+static void fwdServerSetDead(FwdState * fwdState);
+static void fwdServerSetAlive(FwdState * fwdState);
+
 static peer *
 fwdStateServerPeer(FwdState * fwdState)
 {
@@ -190,14 +193,16 @@
     assert(fwdState->server_fd == fd);
     fwdState->server_fd = -1;
     if (EBIT_TEST(fwdState->entry->flags, ENTRY_DEFER_READ))
-	storeResetDefer(fwdState->entry);
+      storeResetDefer(fwdState->entry);
     if (fwdCheckRetry(fwdState)) {
-	int originserver = (fwdState->servers->peer == NULL);
-	debug(17, 3) ("fwdServerClosed: re-forwarding (%d tries, %d secs)\n",
+      int originserver = (fwdState->servers->peer == NULL);
+      debug(17, 3) ("fwdServerClosed: re-forwarding (%d tries, %d secs)\n",
 	    fwdState->n_tries,
-	    (int) (squid_curtime - fwdState->start));
+		      (int) (squid_curtime - fwdState->start));
+	/* setting server dead */
+	fwdServerSetDead (fwdState);
 	if (fwdState->servers->next) {
-	    /* use next, or cycle if origin server isn't last */
+	  /* use next, or cycle if origin server isn't last */
 	    FwdServer *fs = fwdState->servers;
 	    FwdServer **T, *T2 = NULL;
 	    fwdState->servers = fs->next;
@@ -878,6 +883,7 @@
     if (!fwdState->request->flags.pinned)
 	EBIT_SET(e->flags, ENTRY_FWD_HDR_WAIT);
     storeRegisterAbort(e, fwdAbort, fwdState);
+    fwdServerSetAlive(fwdState);
     peerSelect(r, e, fwdStartComplete, fwdState);
 }
 
@@ -1132,3 +1138,35 @@
 }
 
 #endif
+
+static void
+fwdServerSetDead (FwdState * fwdState)
+{
+    assert (fwdState);
+    debug (17,3) ("fwdServerSetDead: setting %s (%s) dead\n", 
+		  fwdState->servers->peer->name, 
+		  fwdState->servers->peer->host);
+    fwdState->servers->peer->life.orig_weight = 
+                  fwdState->servers->peer->weight;
+    fwdState->servers->peer->life.death = squid_curtime;
+    fwdState->servers->peer->weight = 0;
+}
+
+static void
+fwdServerSetAlive (FwdState * fwdState)
+{
+  assert (fwdState);
+  /*
+  FwdServer **cur;
+  debug (17,3) ("fwdServerSetAlive: running:");
+  for (*cur = fwdState->servers; *cur; cur = &(*cur)->next) {
+    if (((*cur)->peer->weight == 0) && 
+	(5 < (squid_curtime - (*cur)->peer->life.death))) {*/
+      debug (17,3) ("fwdServerSetAlive: setting %s (%s) alive\n", 
+		    (*cur)->peer->name, 
+		    (*cur)->peer->host);
+      (*cur)->peer->weight = (*cur)->peer->life.orig_weight;
+    }
+  }
+  */
+}
diff -Nur squid-2.6.STABLE9.orig/src/structs.h squid-2.6.STABLE9/src/structs.h
--- squid-2.6.STABLE9.orig/src/structs.h	2007-01-21 08:26:44.000000000 -0200
+++ squid-2.6.STABLE9/src/structs.h	2007-01-30 14:40:19.000000000 -0200
@@ -1439,6 +1439,10 @@
     } options;
     int weight;
     struct {
+        int orig_weight;
+        time_t death;
+    } life;
+    struct {
 	double avg_n_members;
 	int n_times_counted;
 	int n_replies_expected;

Reply via email to