Hi,

some days ago I sent a question for an only routing lb-worker. Costin asked for 
the patch and here it is.

I added two config-directives for the lb-worker:

local_worker
- this is the name of the worker which should get the request if there is no 
session or no jvmRoute.

fault_action
- the possible values are 'balance' and 'reject'. Explanation follows.

Behaviour of lb-worker:
a.) there is a jvmRoute and the corresponding node is ok:
     -> The request goes to the corresponding node

b.) there is no jvmRoute or the corresponding node didn't answered:
     -> if a local_worker was given. this one will get the request.
     -> if a local_worker was given, but it is in error state:
     fault_action == reject: the request gets an error.
     fault_action == balance: try to find another worker from the list of
                              balanced workers (c.).
     -> if no local_worker was given, go directly to c.).

c.) if no worker was found in a) and b) the normal balancing behaviour takes place.

I looked at cvs-repopsitory and it seems that jk_lb_worker.c and jk_util.c have 
the same version (1.8, 1.12) like mine from 
jakarta-tomcat-connectors-4.0.2-src.tar.gz.

I need the fault_action, because our load balancer should not route a request to 
a node without a working local tomcat. So it is an error if an unrouteable 
request arrives at a node without a working local tomcat. And it is also an 
error to route it to one of the other nodes, because sometimes we switch off one 
node only by telling the load balancer not to use it for requests. In this case 
the modules should use this node only for requests with a session on it and not 
for requests without a session. But for other use cases it might be useful if 
mod_jk tries to balance the request in case of a failure of the local tomcat.

I hope it is useful. Sorry i haven't looked into jk2 at this time, but may be i 
get time to do it soon.

Bernd
-- 
Dipl.-Inform. Bernd Koecke
UNIX-Entwicklung
Schlund+Partner AG
Fon: +49-721-91374-0
E-Mail: [EMAIL PROTECTED]
--- jk_lb_worker.c.orig Thu Apr  4 13:20:00 2002
+++ jk_lb_worker.c      Fri Apr  5 11:03:09 2002
@@ -95,6 +95,9 @@
     worker_record_t *lb_workers;
     unsigned num_of_workers;
 
+    worker_record_t *default_worker;
+    unsigned reject_on_fault;
+
     jk_pool_t p;
     jk_pool_atom_t buf[TINY_POOL_SIZE];
 
@@ -269,6 +272,27 @@
         }
     }
 
+    if (p->default_worker) {
+        rc = p->default_worker;
+        if (rc->in_error_state) {
+            if (!rc->in_recovering) {
+                time_t now = time(0);
+
+                if ((now - rc->error_time) > WAIT_BEFORE_RECOVER) {
+                    rc->in_recovering = JK_TRUE;
+                    rc->error_time = now;
+                } else {
+                    rc = NULL;
+                }
+            } else {
+                rc = NULL;
+            }
+        }
+        if (rc || p->reject_on_fault) {
+            return rc;
+        }
+    }
+
     for(i = 0 ; i < p->num_of_workers ; i++) {
         if(p->lb_workers[i].in_error_state) {
             if(!p->lb_workers[i].in_recovering) {
@@ -321,6 +345,8 @@
 
             if(rec) {
                 int is_recoverable = JK_FALSE;
+                jk_log(l, JK_LOG_DEBUG, "In jk_lb_worker::service routing to worker 
+'%s'\n",
+                    rec->name);
                 
                 s->jvm_route = jk_pool_strdup(s->pool,  rec->name);
 
@@ -415,6 +441,22 @@
         lb_worker_t *p = pThis->worker_private;
         char **worker_names;
         unsigned num_of_workers;
+        char *default_worker_name;
+        unsigned reject_on_fault = JK_FALSE;
+
+        if (jk_get_lb_default_worker_name(props, p->name, &default_worker_name)) {
+            jk_log(l, JK_LOG_DEBUG,
+                "In jk_lb_worker_t::validate found a local worker is %s\n",
+                default_worker_name);
+            jk_get_lb_fault_action(props, p->name, &reject_on_fault);
+        } else {
+            jk_log(l, JK_LOG_DEBUG,
+                "In jk_lb_worker_t::validate didn't found a local worker\n");
+        }
+        p->reject_on_fault = reject_on_fault;
+        jk_log(l, JK_LOG_DEBUG,
+            "In jk_lb_worker_t::validate reject_on_fault is '%u'\n",
+            p->reject_on_fault);
         
         if(jk_get_lb_worker_list(props,
                                  p->name,
@@ -449,6 +491,12 @@
                                      we,
                                      l) || !p->lb_workers[i].w) {
                     break;
+                }
+                if (default_worker_name && 0 == strcmp(p->lb_workers[i].name, 
+default_worker_name)) {
+                    p->default_worker = &(p->lb_workers[i]);
+                    jk_log(l, JK_LOG_DEBUG,
+                        "In jk_lb_worker_t::validate got a local worker '%s'\n",
+                        p->default_worker->name);
                 }
             }
 
--- jk_util.c.orig      Thu Apr  4 13:15:42 2002
+++ jk_util.c   Thu Apr  4 15:31:08 2002
@@ -85,6 +85,10 @@
 #define CACHE_OF_WORKER             ("cachesize")
 #define LOAD_FACTOR_OF_WORKER       ("lbfactor")
 #define BALANCED_WORKERS            ("balanced_workers")
+#define LOCAL_WORKER                ("local_worker")
+#define FAULT_ACTION                ("fault_action")
+#define FAULT_ACTION_BALANCE        ("balance")
+#define FAULT_ACTION_REJECT         ("reject")
 #define WORKER_AJP12                ("ajp12")
 #define DEFAULT_WORKER_TYPE         JK_AJP12_WORKER_NAME
 #define SECRET_KEY_OF_WORKER        ("secretkey")
@@ -439,6 +443,41 @@
     sprintf(buf, "%s.%s.%s", PREFIX_OF_WORKER, wname, LOAD_FACTOR_OF_WORKER);
 
     return map_get_double(m, buf, DEFAULT_LB_FACTOR);
+}
+
+int jk_get_lb_default_worker_name(jk_map_t *m,
+                                  const char *lb_wname,
+                                  char **def_name)
+{
+    char buf[1024];
+    if (m && lb_wname && def_name) {
+        sprintf(buf, "%s.%s.%s", PREFIX_OF_WORKER, lb_wname, LOCAL_WORKER);
+        *def_name = map_get_string(m, buf, NULL);
+        if (*def_name) return JK_TRUE;
+    }
+
+    return JK_FALSE;
+}
+
+int jk_get_lb_fault_action(jk_map_t *m,
+                           const char *lb_wname,
+                           unsigned *action)
+{
+    char buf[1024];
+    if (m && lb_wname && action) {
+        char *tmp_action;
+        sprintf(buf, "%s.%s.%s", PREFIX_OF_WORKER, lb_wname, FAULT_ACTION);
+        tmp_action = map_get_string(m, buf, NULL);
+        if (tmp_action) {
+            if (0 == strcmp(tmp_action, FAULT_ACTION_BALANCE)) {
+                *action = JK_FALSE;
+            } else if (0 == strcmp(tmp_action, FAULT_ACTION_REJECT)) {
+                *action = JK_TRUE;
+            }
+        }
+        return JK_TRUE;
+    }
+    return JK_FALSE;
 }
 
 int jk_get_lb_worker_list(jk_map_t *m, 

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to