You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by rj...@apache.org on 2006/05/17 00:21:27 UTC

svn commit: r407093 - in /tomcat/connectors/trunk/jk: native/common/jk_lb_worker.c native/common/jk_shm.h native/common/jk_status.c native/common/jk_util.c xdocs/config/workers.xml

Author: rjung
Date: Tue May 16 15:21:23 2006
New Revision: 407093

URL: http://svn.apache.org/viewcvs?rev=407093&view=rev
Log:
Add attribute jvm_route to balanced workers.
Default value is equal to the worker name.
This attribute is used to match session stickyness.
It's useful, if you want to include Tomcat instances
as targets into more than one lb, but having different
lb specific properties.

Proposed by dhay (at) lexmark.com.

Modified:
    tomcat/connectors/trunk/jk/native/common/jk_lb_worker.c
    tomcat/connectors/trunk/jk/native/common/jk_shm.h
    tomcat/connectors/trunk/jk/native/common/jk_status.c
    tomcat/connectors/trunk/jk/native/common/jk_util.c
    tomcat/connectors/trunk/jk/xdocs/config/workers.xml

Modified: tomcat/connectors/trunk/jk/native/common/jk_lb_worker.c
URL: http://svn.apache.org/viewcvs/tomcat/connectors/trunk/jk/native/common/jk_lb_worker.c?rev=407093&r1=407092&r2=407093&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_lb_worker.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_lb_worker.c Tue May 16 15:21:23 2006
@@ -95,8 +95,9 @@
     JK_TRACE_EXIT(l);
 }
 
-/* Get the correct lb_value when recovering/starting/enabling a worker */
-/* This function needs to be externally synchronized! */
+/* Get the correct lb_value when recovering/starting/enabling a worker.
+ * This function needs to be externally synchronized!
+ */
 jk_uint64_t restart_value(lb_worker_t *p, jk_logger_t *l)
 {
     int i = 0;
@@ -206,8 +207,9 @@
 }
 
 
-/* Retrieve session id from the cookie or the parameter                      */
-/* (parameter first)                                                         */
+/* Retrieve session id from the cookie or the parameter
+ * (parameter first)
+ */
 static char *get_sessionid(jk_ws_service_t *s)
 {
     char *val;
@@ -268,9 +270,10 @@
     JK_TRACE_EXIT(l);
 }
 
-/* Divide old load values by the decay factor, */
-/* such that older values get less important */
-/* for the routing decisions. */
+/* Divide old load values by the decay factor,
+ * such that older values get less important
+ * for the routing decisions.
+ */
 static jk_uint64_t decay_load(lb_worker_t *p,
                               int exponent,
                               jk_logger_t *l)
@@ -347,9 +350,9 @@
     unsigned int i;
 
     for (i = 0; i < p->num_of_workers; i++) {
-        if (strcmp(p->lb_workers[i].s->name, name) == 0) {
+        if (strcmp(p->lb_workers[i].s->jvm_route, name) == 0) {
             rc = &p->lb_workers[i];
-            rc->r = &(rc->s->name[0]);
+            rc->r = &(rc->s->jvm_route[0]);
             break;
         }
     }
@@ -482,9 +485,9 @@
     worker_record_t *rc = NULL;
 
     rc = find_best_byvalue(p, l);
-    /* By default use worker name as session route */
+    /* By default use worker jvm route as session route */
     if (rc)
-        rc->r = &(rc->s->name[0]);
+        rc->r = &(rc->s->jvm_route[0]);
     else
         rc = find_failover_worker(p, l);
     return rc;
@@ -505,7 +508,7 @@
          * if there is a single one
          */
         if(!p->lb_workers[0].s->in_error_state && !p->lb_workers[0].s->is_stopped) {
-            p->lb_workers[0].r = &(p->lb_workers[0].s->name[0]);
+            p->lb_workers[0].r = &(p->lb_workers[0].s->jvm_route[0]);
             JK_TRACE_EXIT(l);
             return &p->lb_workers[0];
         }
@@ -567,8 +570,8 @@
                     }
                     if (JK_IS_DEBUG_LEVEL(l))
                         jk_log(l, JK_LOG_DEBUG,
-                               "found worker %s for route %s and partial sessionid %s",
-                               rc->s->name, session_route, sessionid);
+                               "found worker %s (%s) for route %s and partial sessionid %s",
+                               rc->s->name, rc->s->jvm_route, session_route, sessionid);
                         JK_TRACE_EXIT(l);
                     return rc;
                 }
@@ -598,8 +601,8 @@
     }
     if (rc && JK_IS_DEBUG_LEVEL(l)) {
         jk_log(l, JK_LOG_DEBUG,
-               "found best worker (%s) using method '%s'",
-               rc->s->name, lb_method_type[p->lbmethod]);
+               "found best worker %s (%s) using method '%s'",
+               rc->s->name, rc->s->jvm_route, lb_method_type[p->lbmethod]);
     }
     JK_TRACE_EXIT(l);
     return rc;
@@ -883,6 +886,7 @@
                                   &worker_names,
                                   &num_of_workers) && num_of_workers) {
             unsigned int i = 0;
+            unsigned int j = 0;
 
             p->lb_workers = jk_pool_alloc(&p->p,
                                           num_of_workers *
@@ -910,6 +914,10 @@
                 if (p->lb_workers[i].s->lb_factor < 1) {
                     p->lb_workers[i].s->lb_factor = 1;
                 }
+                if ((s = jk_get_worker_jvm_route(props, worker_names[i], NULL)))
+                    strncpy(p->lb_workers[i].s->jvm_route, s, JK_SHM_STR_SIZ);
+                else
+                    strncpy(p->lb_workers[i].s->jvm_route, worker_names[i], JK_SHM_STR_SIZ);
                 if ((s = jk_get_worker_domain(props, worker_names[i], NULL)))
                     strncpy(p->lb_workers[i].s->domain, s, JK_SHM_STR_SIZ);
                 if ((s = jk_get_worker_redirect(props, worker_names[i], NULL)))
@@ -948,12 +956,30 @@
                 for (i = 0; i < num_of_workers; i++) {
                     if (JK_IS_DEBUG_LEVEL(l)) {
                         jk_log(l, JK_LOG_DEBUG,
-                               "Balanced worker %i has name %s in domain %s",
-                               i, p->lb_workers[i].s->name, p->lb_workers[i].s->domain);
+                               "Balanced worker %i has name %s and jvm_route %s in domain %s",
+                               i,
+                               p->lb_workers[i].s->name,
+                               p->lb_workers[i].s->jvm_route,
+                               p->lb_workers[i].s->domain);
                     }
                 }
                 p->num_of_workers = num_of_workers;
                 update_mult(p, l);
+                for (i = 0; i < num_of_workers; i++) {
+                    for (j = 0; j < i; j++) {
+                        if (strcmp(p->lb_workers[i].s->jvm_route, p->lb_workers[j].s->jvm_route) == 0) {
+                            jk_log(l, JK_LOG_ERROR,
+                                   "Balanced workers number %i (%s) and %i (%s) share the same jvm_route %s - aborting configuration!",
+                                   i,
+                                   p->lb_workers[i].s->name,
+                                   j,
+                                   p->lb_workers[j].s->name,
+                                   p->lb_workers[i].s->jvm_route);
+                            JK_TRACE_EXIT(l);
+                            return JK_FALSE;
+                        }
+                    }
+                }
                 JK_TRACE_EXIT(l);
                 return JK_TRUE;
             }

Modified: tomcat/connectors/trunk/jk/native/common/jk_shm.h
URL: http://svn.apache.org/viewcvs/tomcat/connectors/trunk/jk/native/common/jk_shm.h?rev=407093&r1=407092&r2=407093&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_shm.h (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_shm.h Tue May 16 15:21:23 2006
@@ -65,6 +65,8 @@
     volatile int connected;
     /* worker name */
     char    name[JK_SHM_STR_SIZ+1];
+    /* jvm route */
+    char    jvm_route[JK_SHM_STR_SIZ+1];
     /* worker domain */
     char    domain[JK_SHM_STR_SIZ+1];
     /* worker redirect route */

Modified: tomcat/connectors/trunk/jk/native/common/jk_status.c
URL: http://svn.apache.org/viewcvs/tomcat/connectors/trunk/jk/native/common/jk_status.c?rev=407093&r1=407092&r2=407093&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_status.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_status.c Tue May 16 15:21:23 2006
@@ -447,7 +447,7 @@
             jk_printf(s, "<td>%s</td>", lb->lblock == JK_LB_LOCK_DEFAULT ? JK_LB_LM_DEFAULT : JK_LB_LM_PESSIMISTIC);
             jk_puts(s, "</tr>\n</table>\n<br/>\n");
             jk_puts(s, "<table><tr>"
-                    "<th>Name</th><th>Type</th><th>Host</th><th>Addr</th>"
+                    "<th>Name</th><th>Type</th><th>jvmRoute</th><th>Host</th><th>Addr</th>"
                     "<th>Stat</th><th>F</th><th>M</th><th>V</th><th>Acc</th><th>Err</th>"
                     "<th>Wr</th><th>Rd</th><th>Busy</th><th>Max</th><th>RR</th><th>Cd</th></tr>\n");
             for (j = 0; j < lb->num_of_workers; j++) {
@@ -460,6 +460,7 @@
                 if (dworker && strcmp(dworker, wr->s->name) == 0)
                     selected = j;
                 jk_putv(s, "<td>", status_worker_type(wr->w->type), "</td>", NULL);
+                jk_putv(s, "<td>", wr->s->jvm_route, "</td>", NULL);
                 jk_printf(s, "<td>%s:%d</td>", a->host, a->port);
                 jk_putv(s, "<td>", jk_dump_hinfo(&a->worker_inet_addr, buf),
                         "</td>", NULL);
@@ -497,7 +498,8 @@
             if (selected >= 0) {
                 worker_record_t *wr = &(lb->lb_workers[selected]);
                 jk_putv(s, "<hr/><h3>Edit worker settings for ",
-                        wr->s->name, "</h3>\n", NULL);
+                        wr->s->name, " (JVM Route ", 
+                        wr->s->jvm_route, ")</h3>\n", NULL);
                 jk_putv(s, "<form method=\"GET\" action=\"",
                         s->req_uri, "\">\n", NULL);
                 jk_puts(s, "<table>\n<input type=\"hidden\" name=\"cmd\" ");
@@ -577,6 +579,7 @@
     jk_puts(s, "<hr/><table>\n"
             "<tr><th>Name</th><td>Worker route name</td></tr>\n"
             "<tr><th>Type</th><td>Worker type</td></tr>\n"
+            "<tr><th>jvmRoute</th><td>Worker JVM Route</td></tr>\n"
             "<tr><th>Addr</th><td>Backend Address info</td></tr>\n"
             "<tr><th>Stat</th><td>Worker status</td></tr>\n"
             "<tr><th>F</th><td>Load Balancer Factor</td></tr>\n"
@@ -662,6 +665,8 @@
             jk_printf(s, " readed=\"%" JK_UINT64_T_FMT "\"", wr->s->readed);
             jk_printf(s, " busy=\"%u\"", wr->s->busy);
             jk_printf(s, " maxbusy=\"%u\"", wr->s->max_busy);
+            if (wr->s->jvm_route && *wr->s->jvm_route)
+                jk_printf(s, " jvm_route=\"%s\"", wr->s->jvm_route);
             if (wr->s->redirect && *wr->s->redirect)
                 jk_printf(s, " redirect=\"%s\"", wr->s->redirect);
             if (wr->s->domain && *wr->s->domain)

Modified: tomcat/connectors/trunk/jk/native/common/jk_util.c
URL: http://svn.apache.org/viewcvs/tomcat/connectors/trunk/jk/native/common/jk_util.c?rev=407093&r1=407092&r2=407093&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_util.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_util.c Tue May 16 15:21:23 2006
@@ -62,6 +62,7 @@
 #define BALANCE_WORKERS             ("balance_workers")
 #define STICKY_SESSION              ("sticky_session")
 #define STICKY_SESSION_FORCE        ("sticky_session_force")
+#define JVM_ROUTE_OF_WORKER         ("jvm_route")
 #define DOMAIN_OF_WORKER            ("domain")
 #define REDIRECT_OF_WORKER          ("redirect")
 #define MOUNT_OF_WORKER             ("mount")
@@ -383,6 +384,16 @@
     return jk_map_get_string(m, buf, DEFAULT_WORKER_TYPE);
 }
 
+const char *jk_get_worker_jvm_route(jk_map_t *m, const char *wname, const char *def)
+{
+    char buf[1024];
+    if (!m || !wname) {
+        return NULL;
+    }
+    MAKE_WORKER_PARAM(JVM_ROUTE_OF_WORKER);
+    return jk_map_get_string(m, buf, def);
+}
+
 const char *jk_get_worker_domain(jk_map_t *m, const char *wname, const char *def)
 {
     char buf[1024];
@@ -1054,6 +1065,7 @@
     LOAD_FACTOR_OF_WORKER,
     STICKY_SESSION,
     STICKY_SESSION_FORCE,
+    JVM_ROUTE_OF_WORKER,
     DOMAIN_OF_WORKER,
     REDIRECT_OF_WORKER,
     MOUNT_OF_WORKER,

Modified: tomcat/connectors/trunk/jk/xdocs/config/workers.xml
URL: http://svn.apache.org/viewcvs/tomcat/connectors/trunk/jk/xdocs/config/workers.xml?rev=407093&r1=407092&r2=407093&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/xdocs/config/workers.xml (original)
+++ tomcat/connectors/trunk/jk/xdocs/config/workers.xml Tue May 16 15:21:23 2006
@@ -413,6 +413,23 @@
 </p>
 </directive>
 
+<directive name="jvm_route" default="" required="false">
+Normally the name of a balanced worker in a load balancer is equal to the jvmRoute
+of the corresponding Tomcat instance. If you want to include a worker corresponding
+to a Tomcat instance into several load balancers with different balancing configuration
+(e.g. disabled, stopped) you can use this attribute.
+<p>
+Define a seperate worker per lb and per Tomcat instance with an arbitrary worker name and 
+set the jvm_route attribute of the worker equal to the jvmRoute of the target Tomcat instance.
+</p>
+<p>
+If this attribute is left empty, the name of the worker will be used.
+</p>
+<p>
+This feature has been added in <b>jk 1.2.16</b>.
+</p>
+</directive>
+
 <directive name="secret" default="" required="false">
 If set to AJP Connector secret keyword, only request with this keyword are successfull responding.
 Use <b>request.useSecret="true"</b> and <b>request.secret="secret key word"</b> at your tomcat ajp
@@ -429,4 +446,4 @@
 </section>
 
 </body>
-</document>
\ No newline at end of file
+</document>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org