[mod_cluster-commits] mod_cluster SVN: r820 - trunk/native/mod_proxy_cluster.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Apr 27 12:33:56 EDT 2012


Author: jfrederic.clere at jboss.com
Date: 2012-04-27 12:33:55 -0400 (Fri, 27 Apr 2012)
New Revision: 820

Modified:
   trunk/native/mod_proxy_cluster/mod_proxy_cluster.c
Log:
For MODCLUSTER-305.


Modified: trunk/native/mod_proxy_cluster/mod_proxy_cluster.c
===================================================================
--- trunk/native/mod_proxy_cluster/mod_proxy_cluster.c	2012-04-27 12:54:10 UTC (rev 819)
+++ trunk/native/mod_proxy_cluster/mod_proxy_cluster.c	2012-04-27 16:33:55 UTC (rev 820)
@@ -111,6 +111,15 @@
 };
 typedef struct proxy_vhost_table proxy_vhost_table;
 
+/* Balancer table copy for local use */
+struct proxy_balancer_table
+{
+	int sizebalancer;
+	int* balancers;
+	balancerinfo_t* balancer_info;
+};
+typedef struct proxy_balancer_table proxy_balancer_table;
+
 /* reslist constructor */
 /* XXX: Should use the proxy_util one. */
 static apr_status_t connection_constructor(void **resource, void *params,
@@ -1191,6 +1200,7 @@
 }
 
 
+/* Read the virtual host table from shared memory */
 static void read_vhost_table(request_rec *r, proxy_vhost_table *vhost_table)
 {
     int i;
@@ -1237,6 +1247,29 @@
     }
 }
 
+/* Read the balancer table from shared memory */
+static void read_balancer_table(request_rec *r, proxy_balancer_table *balancer_table)
+{
+    int i;
+    int size;
+    size = balancer_storage->get_max_size_balancer();
+    if (size == 0) { 
+        balancer_table->sizebalancer = 0;
+        balancer_table->balancers = NULL;
+        balancer_table->balancer_info = NULL;
+        return;
+    }
+    balancer_table->balancers =  apr_palloc(r->pool, sizeof(int) * size);
+    balancer_table->sizebalancer = balancer_storage->get_ids_used_balancer(balancer_table->balancers);
+    balancer_table->balancer_info = apr_palloc(r->pool, sizeof(balancerinfo_t) * balancer_table->sizebalancer);
+    for (i = 0; i < balancer_table->sizebalancer; i++) {
+        balancerinfo_t* h;
+        int balancer_index = balancer_table->balancers[i];
+        balancer_storage->read_balancer(balancer_index, &h);
+        balancer_table->balancer_info[i] = *h;
+    }
+}
+
 /**
  * Find the best nodes for a request (check host and context (and balancer))
  * @param r the request_rec
@@ -1422,6 +1455,21 @@
 }
 
 /*
+ * Check that the balancer is in our balancer table
+ */
+static int isbalancer_ours(proxy_balancer *balancer, proxy_balancer_table *balancer_table)
+{
+    int i;
+    for (i = 0; i < balancer_table->sizebalancer; i++) {
+        if (strcmp(balancer_table->balancer_info[i].balancer, &balancer->name[11]))
+            continue;
+        else
+            return 1; /* found */
+    }
+    return 0;
+}
+
+/*
  * Check that the worker corresponds to a node that belongs to the same domain according to the JVMRoute.
  */ 
 static int isnode_domain_ok(request_rec *r, nodeinfo_t *node,
@@ -1939,7 +1987,8 @@
  */
 static const char *get_route_balancer(request_rec *r, proxy_server_conf *conf,
                                       proxy_vhost_table *vhost_table,
-                                      proxy_context_table *context_table)
+                                      proxy_context_table *context_table,
+                                      proxy_balancer_table *balancer_table)
 {
     proxy_balancer *balancer;
     char *route = NULL;
@@ -1954,12 +2003,14 @@
             continue;
         if (strlen(balancer->name)<=11)
             continue;
+        if (!isbalancer_ours(balancer, balancer_table))
+            continue;
 
         sessionid = cluster_get_sessionid(r, balancer->sticky, r->uri, &sticky_used);
         if (sessionid) {
             ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
-                         "cluster: Found value %s for "
-                         "stickysession %s", sessionid, balancer->sticky);
+                         "cluster: %s Found value %s for "
+                         "stickysession %s", balancer->name, sessionid, balancer->sticky);
             if ((route = strchr(sessionid, '.')) != NULL )
                 route++;
             if (route && *route) {
@@ -2107,8 +2158,10 @@
 
     proxy_vhost_table vhost_table;
     proxy_context_table context_table;
+    proxy_balancer_table balancer_table;
     read_vhost_table(r, &vhost_table);
     read_context_table(r, &context_table);
+    read_balancer_table(r, &balancer_table);
 
 #if HAVE_CLUSTER_EX_DEBUG
     ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_DEBUG, 0, r->server,
@@ -2116,11 +2169,11 @@
                  r->proxyreq, r->filename, r->handler, r->uri, r->args, r->unparsed_uri);
 #endif
 
-    balancer = get_route_balancer(r, conf, &vhost_table, &context_table);
+    balancer = get_route_balancer(r, conf, &vhost_table, &context_table, &balancer_table);
     if (!balancer) {
         /* May be the balancer has not been created (XXX: use shared memory to find the balancer ...) */
         update_workers_node(conf, r->pool, r->server, 1);
-        balancer = get_route_balancer(r, conf, &vhost_table, &context_table);
+        balancer = get_route_balancer(r, conf, &vhost_table, &context_table, &balancer_table);
     }
     if (!balancer)
         balancer = get_context_host_balancer(r, &vhost_table, &context_table);



More information about the mod_cluster-commits mailing list