ASF Bugzilla – Attachment 29583 Details for
Bug 54134
new feature: ability to use multiple routes in sticky_session
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
mutiple-route patch
trunk_multiroute_session.patch (text/plain), 7.51 KB, created by
inu
on 2012-11-11 13:06:57 UTC
(
hide
)
Description:
mutiple-route patch
Filename:
MIME Type:
Creator:
inu
Created:
2012-11-11 13:06:57 UTC
Size:
7.51 KB
patch
obsolete
>Index: modules/proxy/mod_proxy_balancer.c >=================================================================== >--- modules/proxy/mod_proxy_balancer.c (Revision 1407935) >+++ modules/proxy/mod_proxy_balancer.c (Arbeitskopie) >@@ -200,6 +200,7 @@ > > /* Find the worker that has the 'route' defined > */ >+#if 0 > static proxy_worker *find_route_worker(proxy_balancer *balancer, > const char *route, request_rec *r) > { >@@ -264,7 +265,63 @@ > } > return NULL; > } >+#endif > >+static proxy_worker *find_worker_by_route(proxy_balancer *balancer, >+ const char *route, >+ int use_standby, >+ int use_redirect, >+ request_rec *r) >+{ >+ proxy_worker **workers; >+ >+ /* iterate over all workers in balancer */ >+ workers = (proxy_worker **)balancer->workers->elts; >+ for (int i = 0; i < balancer->workers->nelts; i++, workers++) { >+ proxy_worker *worker = *workers; >+ >+ /* if no route in worker, or route not matched, try next */ >+ if ((!*(worker->s->route)) || strcmp(worker->s->route, route) != 0) >+ continue; >+ >+ /* look for the redirect worker */ >+ if (use_redirect) { >+ /* if worker have no redirect, try next */ >+ if (!(*(worker->s->redirect))) >+ continue; >+ >+ /* search redirect worker */ >+ worker = find_worker_by_route(balancer, worker->s->redirect, >+ use_standby, 0, r); >+ if (worker) >+ return worker; >+ >+ continue; >+ } >+ >+ /* ignore worker in standby, or not. based on use_standby */ >+ if (use_standby ? >+ !PROXY_WORKER_IS_STANDBY(worker) : PROXY_WORKER_IS_STANDBY(worker)) >+ continue; >+ >+ /* found usable worker for route */ >+ if (PROXY_WORKER_IS_USABLE(worker)) >+ return worker; >+ >+ /* >+ * If the worker is in error state run >+ * retry on that worker. It will be marked as >+ * operational if the retry timeout is elapsed. >+ * The worker might still be unusable, but we try >+ * anyway. >+ */ >+ ap_proxy_retry_worker_fn("BALANCER", worker, r->server); >+ if (PROXY_WORKER_IS_USABLE(worker)) >+ return worker; >+ } >+ return NULL; >+} >+ > static proxy_worker *find_session_route(proxy_balancer *balancer, > request_rec *r, > char **route, >@@ -272,53 +329,95 @@ > char **url) > { > proxy_worker *worker = NULL; >+ char *routes = NULL; >+ char *next; > > if (!*balancer->s->sticky) > return NULL; > /* Try to find the sticky route inside url */ >- *route = get_path_param(r->pool, *url, balancer->s->sticky_path, balancer->s->scolonsep); >- if (*route) { >+ routes = get_path_param(r->pool, *url, balancer->s->sticky_path, >+ balancer->s->scolonsep); >+ if (routes) { > ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01159) > "Found value %s for stickysession %s", >- *route, balancer->s->sticky_path); >+ routes, balancer->s->sticky_path); > *sticky_used = balancer->s->sticky_path; > } > else { >- *route = get_cookie_param(r, balancer->s->sticky); >- if (*route) { >+ routes = get_cookie_param(r, balancer->s->sticky); >+ if (routes) { > *sticky_used = balancer->s->sticky; > ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01160) > "Found value %s for stickysession %s", >- *route, balancer->s->sticky); >+ routes, balancer->s->sticky); > } > } >+ >+ /* break if no route was found */ >+ if (!routes) >+ return NULL; >+ > /* > * If we found a value for stickysession, find the first '.' (or whatever > * sticky_separator is set to) within. Everything after '.' (if present) > * is our route. > */ >- if ((*route) && (balancer->s->sticky_separator != 0) && ((*route = strchr(*route, balancer->s->sticky_separator)) != NULL )) >- (*route)++; >- if ((*route) && (**route)) { >- ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01161) "Found route %s", *route); >- /* We have a route in path or in cookie >- * Find the worker that has this route defined. >- */ >- worker = find_route_worker(balancer, *route, r); >- if (worker && strcmp(*route, worker->s->route)) { >- /* >- * Notice that the route of the worker chosen is different from >- * the route supplied by the client. >+ if ((balancer->s->sticky_separator != 0) && >+ ((routes = strchr(routes, balancer->s->sticky_separator)) != NULL)) >+ routes++; >+ >+ /* found one or more routes. try to find a usable worker >+ * step 1. check all routes in stickysession >+ * step 2. check the redirect routes of all routes in stickysession >+ * step 3. check all routes in stickysession agains standby server >+ * step 4. check the redirect routes of all routes in stickysession >+ * against standby server >+ */ >+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, >+ APLOGNO(01161) "Found route(s) %s", routes); >+ for (int step = 1; step < 5; step++) { >+ *route = routes; >+ while ((*route) && (**route)) { >+ /* look for a additional route in sticky_session */ >+ if (balancer->s->sticky_separator != 0) { >+ next = strchr(*route, balancer->s->sticky_separator); >+ if (next) >+ *next = '\0'; >+ } >+ >+ /* search usable worker >+ * - use standby server in step 3 or above >+ * - use redirects in step 2 and 4 > */ >- apr_table_setn(r->subprocess_env, "BALANCER_ROUTE_CHANGED", "1"); >- ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01162) >- "Route changed from %s to %s", >- *route, worker->s->route); >+ worker = find_worker_by_route(balancer, *route, step >= 3, >+ step == 2 || step == 4, r); >+ if (worker) { >+ /* the route changed? >+ * only the first route in sticky_session in >+ * step 1 and 3 are unchanged >+ */ >+ if (!((step == 1 || step == 3) && *route == routes)) { >+ apr_table_setn(r->subprocess_env, "BALANCER_ROUTE_CHANGED", >+ "1"); >+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01162) >+ "Route changed from %s to %s", >+ routes, worker->s->route); >+ } >+ >+ return worker; >+ } >+ >+ /* found no usable worker, try next route */ >+ if (next) { >+ *next = balancer->s->sticky_separator; >+ next++; >+ } >+ *route = next; > } >- return worker; > } >- else >- return NULL; >+ >+ /* found no worker */ >+ return NULL; > } > > static proxy_worker *find_best_worker(proxy_balancer *balancer,
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 54134
: 29583