mod_proxy_balancer.c revision 5772afb03a895afcebaf30a107c44022fc9b5224
842ae4bd224140319ae7feec1872b93dfd491143fielding/* Licensed to the Apache Software Foundation (ASF) under one or more
842ae4bd224140319ae7feec1872b93dfd491143fielding * contributor license agreements. See the NOTICE file distributed with
842ae4bd224140319ae7feec1872b93dfd491143fielding * this work for additional information regarding copyright ownership.
842ae4bd224140319ae7feec1872b93dfd491143fielding * The ASF licenses this file to You under the Apache License, Version 2.0
842ae4bd224140319ae7feec1872b93dfd491143fielding * (the "License"); you may not use this file except in compliance with
842ae4bd224140319ae7feec1872b93dfd491143fielding * the License. You may obtain a copy of the License at
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * Unless required by applicable law or agreed to in writing, software
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * distributed under the License is distributed on an "AS IS" BASIS,
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * See the License for the specific language governing permissions and
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * limitations under the License.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* Load balancer module for Apache proxy */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic const char *balancer_mutex_type = "proxy-balancer-shm";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic int (*ap_proxy_retry_worker_fn)(const char *proxy_function,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Register our mutex type before the config is read so we
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * can adjust the mutex settings using the Mutex directive.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic int balancer_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb rv = ap_mutex_register(pconf, balancer_mutex_type, NULL,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbextern void proxy_update_members(proxy_balancer **balancer, request_rec *r,
7184de27ec1d62a83c41cdeac0953ca9fd661e8csfstatic int proxy_balancer_canon(request_rec *r, char *url)
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz const char *err;
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz /* TODO: offset of BALANCER_PREFIX ?? */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "canonicalising URL %s", url);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* do syntatic check.
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe * We break the URL into host, port, path, search
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01157)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "error parsing URL %s: %s",
18b5268e013574026b2503b1641baf3299045f45sf * now parse path/search args, according to rfc1738:
18b5268e013574026b2503b1641baf3299045f45sf * process the path. With proxy-noncanon set (by
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * mod_proxy) we use the raw, unparsed uri
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd path = ap_proxy_canonenc(r->pool, url, strlen(url), enc_path, 0,
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe r->filename = apr_pstrcat(r->pool, "proxy:", BALANCER_PREFIX, host,
185aa71728867671e105178b4c66fbc22b65ae26sf "/", path, (search) ? "?" : "", (search) ? search : "", NULL);
4760b58cc9fe170e4ad4648ed4ff7a422a2cef38sfstatic void init_balancer_members(apr_pool_t *p, server_rec *s,
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01158)
3e392a5afd51526de3cb15d57ee46d8cb160ae65gregames "Looking at %s -> %s%s initialized?", balancer->s->name, worker->s->name,
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf worker_is_initialized = PROXY_WORKER_IS_INITIALIZED(worker);
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar /* Set default number of attempts to the number of
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar * workers.
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar if (!balancer->s->max_attempts_set && balancer->workers->nelts > 1) {
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz balancer->s->max_attempts = balancer->workers->nelts - 1;
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar/* Retrieve the parameter with the given name
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar * Something like 'JSESSIONID=12345...N'
2a6e98ba4ffa30ded5d8831664c5cb2a170a56b6coarstatic char *get_path_param(apr_pool_t *pool, char *url,
3e392a5afd51526de3cb15d57ee46d8cb160ae65gregames for (path = strstr(url, name); path; path = strstr(path + 1, name)) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * Session path was found, get its value
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe path = apr_strtok(apr_pstrdup(pool, path), pathdelims, &q);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowestatic char *get_cookie_param(request_rec *r, const char *name)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe const char *cookies;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if ((cookies = apr_table_get(r->headers_in, "Cookie"))) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe for (start_cookie = ap_strstr_c(cookies, name); start_cookie;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf * Session cookie was found, get its value
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe/* Find the worker that has the 'route' defined
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowestatic proxy_worker *find_route_worker(proxy_balancer *balancer,
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes workers = (proxy_worker **)balancer->workers->elts;
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes for (i = 0; i < balancer->workers->nelts; i++, workers++) {
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes if ( (checking_standby ? !PROXY_WORKER_IS_STANDBY(worker) : PROXY_WORKER_IS_STANDBY(worker)) )
18b5268e013574026b2503b1641baf3299045f45sf if (*(worker->s->route) && strcmp(worker->s->route, route) == 0) {
18b5268e013574026b2503b1641baf3299045f45sf * If the worker is in error state run
18b5268e013574026b2503b1641baf3299045f45sf * retry on that worker. It will be marked as
d9cc5de428947d5c7221d7d42ceefea649bcab48sf * operational if the retry timeout is elapsed.
18b5268e013574026b2503b1641baf3299045f45sf * The worker might still be unusable, but we try
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq * We have a worker that is unusable.
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq * It can be in error or disabled, but in case
185aa71728867671e105178b4c66fbc22b65ae26sf * it has a redirection set use that redirection worker.
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq * This enables to safely remove the member from the
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq * balancer. Of course you will need some kind of
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq * session replication between those two remote.
18b5268e013574026b2503b1641baf3299045f45sf rworker = find_route_worker(balancer, worker->s->redirect, r);
18b5268e013574026b2503b1641baf3299045f45sf /* Check if the redirect worker is usable */
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes if (rworker && !PROXY_WORKER_IS_USABLE(rworker)) {
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes * If the worker is in error state run
18b5268e013574026b2503b1641baf3299045f45sf * retry on that worker. It will be marked as
18b5268e013574026b2503b1641baf3299045f45sf * operational if the retry timeout is elapsed.
18b5268e013574026b2503b1641baf3299045f45sf * The worker might still be unusable, but we try
18b5268e013574026b2503b1641baf3299045f45sf ap_proxy_retry_worker_fn("BALANCER", rworker, r->server);
18b5268e013574026b2503b1641baf3299045f45sfstatic proxy_worker *find_session_route(proxy_balancer *balancer,
69bbd0a9d1892949e1d4e454c10e8ad24b37c759sf const char **sticky_used,
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes /* Try to find the sticky route inside url */
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes *route = get_path_param(r->pool, *url, balancer->s->sticky_path, balancer->s->scolonsep);
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01159)
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes "Found value %s for stickysession %s",
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01160)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe "Found value %s for stickysession %s",
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * If we found a value for stickysession, find the first '.' (or whatever
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * sticky_separator is set to) within. Everything after '.' (if present)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * is our route.
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if ((*route) && (balancer->s->sticky_separator != 0) && ((*route = strchr(*route, balancer->s->sticky_separator)) != NULL ))
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01161) "Found route %s", *route);
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe /* We have a route in path or in cookie
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * Find the worker that has this route defined.
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * Notice that the route of the worker chosen is different from
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * the route supplied by the client.
0540a0b469147b52e858587270dba31c2aaa9e09wrowe apr_table_setn(r->subprocess_env, "BALANCER_ROUTE_CHANGED", "1");
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01162)
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe "Route changed from %s to %s",
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisdstatic proxy_worker *find_best_worker(proxy_balancer *balancer,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if ((rv = PROXY_THREAD_LOCK(balancer)) != APR_SUCCESS) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01163)
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd "%s: Lock failed for find_best_worker()",
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd candidate = (*balancer->lbmethod->finder)(balancer, r);
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp if ((rv = PROXY_THREAD_UNLOCK(balancer)) != APR_SUCCESS) {
f46cb698a1b32d16a0107566568f67d8c3f8ee9csf ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01164)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "%s: Unlock failed for find_best_worker()",
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd /* All the workers are in error state or disabled.
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * If the balancer has a timeout sleep for a while
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * and try again to find the worker. The chances are
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * that some other thread will release a connection.
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * By default the timeout is not set, and the server
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * returns SERVER_BUSY.
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd /* XXX: This can perhaps be build using some
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * smarter mechanism, like tread_cond.
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * But since the statuses can came from
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * different childs, use the provided algo.
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd /* Set the timeout to 0 so that we don't
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * end in infinite loop
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd /* Try again */
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd /* restore the timeout */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic int rewrite_url(request_rec *r, proxy_worker *worker,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* we break the URL into host, port, uri */
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return ap_proxyerror(r, HTTP_BAD_REQUEST, apr_pstrcat(r->pool,
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe *url = apr_pstrcat(r->pool, worker->s->name, path, NULL);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowestatic void force_recovery(proxy_balancer *balancer, server_rec *s)
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz for (i = 0; i < balancer->workers->nelts; i++, worker++) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (!((*worker)->s->status & PROXY_WORKER_IN_ERROR)) {
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz /* Try if we can recover */
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz ap_proxy_retry_worker_fn("BALANCER", *worker, s);
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz if (!((*worker)->s->status & PROXY_WORKER_IN_ERROR)) {
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar /* If all workers are in error state force the recovery.
11fb2f3611e6ff9a541e10b13e3108934f828141gregames for (i = 0; i < balancer->workers->nelts; i++, worker++) {
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01165)
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz "%s: Forcing recovery for worker (%s)",
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowestatic apr_status_t decrement_busy_count(void *worker_)
c3e233736c4a453cbb2166a041f779e86230630asfstatic int proxy_balancer_pre_request(proxy_worker **worker,
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz /* Step 1: check if the url is for us
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz * The url we can handle starts with 'balancer://'
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * If balancer is already provided skip the search
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * for balancer, because this is failover attempt.
8aefbd756763807188d2e3ce336a8680e4893066wrowe !(*balancer = ap_proxy_get_balancer(r->pool, conf, *url, 1)))
700b96db75e7cfadb5219978c1735b710d583763wrowe /* Step 2: Lock the LoadBalancer
700b96db75e7cfadb5219978c1735b710d583763wrowe * XXX: perhaps we need the process lock here
700b96db75e7cfadb5219978c1735b710d583763wrowe if ((rv = PROXY_THREAD_LOCK(*balancer)) != APR_SUCCESS) {
700b96db75e7cfadb5219978c1735b710d583763wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01166)
700b96db75e7cfadb5219978c1735b710d583763wrowe "%s: Lock failed for pre_request", (*balancer)->s->name);
700b96db75e7cfadb5219978c1735b710d583763wrowe /* Step 3: force recovery */
700b96db75e7cfadb5219978c1735b710d583763wrowe /* Step 3.5: Update member list for the balancer */
700b96db75e7cfadb5219978c1735b710d583763wrowe /* TODO: Implement as provider! */
700b96db75e7cfadb5219978c1735b710d583763wrowe /* Step 4: find the session route */
700b96db75e7cfadb5219978c1735b710d583763wrowe runtime = find_session_route(*balancer, r, &route, &sticky, url);
700b96db75e7cfadb5219978c1735b710d583763wrowe if ((*balancer)->lbmethod && (*balancer)->lbmethod->updatelbstatus) {
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf /* Call the LB implementation */
700b96db75e7cfadb5219978c1735b710d583763wrowe (*balancer)->lbmethod->updatelbstatus(*balancer, runtime, r->server);
700b96db75e7cfadb5219978c1735b710d583763wrowe else { /* Use the default one */
700b96db75e7cfadb5219978c1735b710d583763wrowe /* We have a sticky load balancer
700b96db75e7cfadb5219978c1735b710d583763wrowe * Update the workers status
700b96db75e7cfadb5219978c1735b710d583763wrowe * so that even session routes get
700b96db75e7cfadb5219978c1735b710d583763wrowe * into account.
700b96db75e7cfadb5219978c1735b710d583763wrowe workers = (proxy_worker **)(*balancer)->workers->elts;
700b96db75e7cfadb5219978c1735b710d583763wrowe /* Take into calculation only the workers that are
700b96db75e7cfadb5219978c1735b710d583763wrowe * not in error state or not disabled.
8aefbd756763807188d2e3ce336a8680e4893066wrowe * We have a route provided that doesn't match the
8aefbd756763807188d2e3ce336a8680e4893066wrowe * balancer name. See if the provider route is the
8aefbd756763807188d2e3ce336a8680e4893066wrowe * member of the same balancer in which case return 503
8aefbd756763807188d2e3ce336a8680e4893066wrowe workers = (proxy_worker **)(*balancer)->workers->elts;
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (*((*workers)->s->route) && strcmp((*workers)->s->route, route) == 0) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01167)
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe "%s: All workers are in error state for route (%s)",
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((rv = PROXY_THREAD_UNLOCK(*balancer)) != APR_SUCCESS) {
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01168)
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf "%s: Unlock failed for pre_request",
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((rv = PROXY_THREAD_UNLOCK(*balancer)) != APR_SUCCESS) {
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01169)
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe "%s: Unlock failed for pre_request",
23c6309e36a63b13b61c35999c978017521993d6wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01170)
185aa71728867671e105178b4c66fbc22b65ae26sf "%s: All workers are in error state",
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01171)
8aefbd756763807188d2e3ce336a8680e4893066wrowe "%s: No workers in balancer",
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * This balancer has sticky sessions and the client either has not
185aa71728867671e105178b4c66fbc22b65ae26sf * supplied any routing information or all workers for this route
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * including possible redirect and hotstandby workers are in error
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * state, but we have found another working worker for this
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe * balancer where we can send the request. Thus notice that we have
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * changed the route to the backend.
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_table_setn(r->subprocess_env, "BALANCER_ROUTE_CHANGED", "1");
cf6ef072483172309861d06e85b1aeff4573c060wrowe apr_pool_cleanup_register(r->pool, *worker, decrement_busy_count,
cf6ef072483172309861d06e85b1aeff4573c060wrowe /* Add balancer/worker info to env. */
cf6ef072483172309861d06e85b1aeff4573c060wrowe /* Rewrite the url from 'balancer://url'
cf6ef072483172309861d06e85b1aeff4573c060wrowe * to the 'worker_scheme://worker_hostname[:worker_port]/url'
cf6ef072483172309861d06e85b1aeff4573c060wrowe * This replaces the balancers fictional name with the
2d4ea77e21ef7f3707d2c27f6117cc0a36e99b83trawick * real hostname of the elected worker.
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick /* Add the session route to request notes if present */
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick /* Add session info to env. */
2d4ea77e21ef7f3707d2c27f6117cc0a36e99b83trawick ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01172)
ecde48c75338ff5712f2036711f813c6dedca28ewrowe "%s: worker (%s) rewritten to %s",
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoarstatic int proxy_balancer_post_request(proxy_worker *worker,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if ((rv = PROXY_THREAD_LOCK(balancer)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01173)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "%s: Lock failed for post_request",
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01174)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "%s: Forcing worker (%s%s) into error state "
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "due to status code %d matching 'failonstatus' "
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "balancer parameter",
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem && (apr_table_get(r->notes, "proxy_timedout")) != NULL) {
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(02460)
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem "%s: Forcing worker (%s%s) into error state "
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem "due to timeout and 'failonstatus' parameter being set",
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem balancer->s->name, worker->s->name, (worker->s->uds?"|":""));
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem if ((rv = PROXY_THREAD_UNLOCK(balancer)) != APR_SUCCESS) {
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01175)
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem "%s: Unlock failed for post_request", balancer->s->name);
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01176)
eb12400ff685a3b69476736ca4b5389f348b9d63rpluem "proxy_balancer_post_request for (%s)", balancer->s->name);
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem /* Recalculate lbfactors */
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem /* Special case if there is only one worker its
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem * load factor will always be 1
75c02648f9afe9a1da5d5482703fcbca306ffcdcpquerna (*workers)->s->lbstatus = (*workers)->s->lbfactor = 1;
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem /* Update the status entries */
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem proxy_server_conf *conf = (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe/* post_config hook: */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowestatic int balancer_post_config(apr_pool_t *pconf, apr_pool_t *plog,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* balancer_post_config() will be called twice during startup. So, don't
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * set up the static data the 1st time through. */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (ap_state_query(AP_SQ_MAIN_STATE) == AP_SQ_MS_CREATE_PRE_CONFIG) {
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(02230)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "mod_proxy must be loaded for mod_proxy_balancer");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * Get slotmem setups
8aefbd756763807188d2e3ce336a8680e4893066wrowe storage = ap_lookup_provider(AP_SLOTMEM_PROVIDER_GROUP, "shm",
700b96db75e7cfadb5219978c1735b710d583763wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01177)
700b96db75e7cfadb5219978c1735b710d583763wrowe "Failed to lookup provider 'shm' for '%s': is "
700b96db75e7cfadb5219978c1735b710d583763wrowe "mod_slotmem_shm loaded??",
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * Go thru each Vhost and create the shared mem slotmem for
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * each balancer's workers
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe while (s) {
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe conf = (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
185aa71728867671e105178b4c66fbc22b65ae26sf * During create_proxy_config() we created a dummy id. Now that
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * we have identifying info, we can create the real id
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe (s->error_fname ? s->error_fname : DEFAULT_ERRORLOG));
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe /* Shared memory already created for this proxy_server_conf.
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe conf->max_balancers = conf->balancers->nelts + conf->bgrowth;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01178) "Doing balancers create: %d, %d (%d)",
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01179) "balancer slotmem_create failed");
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe /* Initialize shared scoreboard data */
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
cf6ef072483172309861d06e85b1aeff4573c060wrowe const char *sname;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker unsigned int index;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe /* now that we have the right id, we need to redo the sname field */
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe ap_pstr2_alnum(pconf, balancer->s->name + sizeof(BALANCER_PREFIX) - 1,
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe sname = apr_pstrcat(pconf, conf->id, "_", sname, NULL);
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe PROXY_STRNCPY(balancer->s->sname, sname); /* We know this will succeed */
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe balancer->max_workers = balancer->workers->nelts + balancer->growth;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe /* Create global mutex */
38bcc87d9a06e8ba81165421403f275eca4e313btrawick rv = ap_global_mutex_create(&(balancer->gmutex), NULL, balancer_mutex_type,
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01180)
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe "mutex creation of %s : %s failed", balancer_mutex_type,
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe apr_pool_cleanup_register(pconf, (void *)s, lock_remove,
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe /* setup shm for balancers */
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe bshm = ap_proxy_find_balancershm(storage, conf->bslot, balancer, &index);
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe if ((rv = storage->fgrab(conf->bslot, index)) != APR_SUCCESS) {
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(02408) "balancer slotmem_fgrab failed");
cf6ef072483172309861d06e85b1aeff4573c060wrowe if ((rv = storage->grab(conf->bslot, &index)) != APR_SUCCESS) {
cf6ef072483172309861d06e85b1aeff4573c060wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01181) "balancer slotmem_grab failed");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((rv = storage->dptr(conf->bslot, index, (void *)&bshm)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01182) "balancer slotmem_dptr failed");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((rv = ap_proxy_share_balancer(balancer, bshm, index)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01183) "Cannot share balancer");
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* create slotmem slots for workers */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01184) "Doing workers create: %s (%s), %d, %d [%u]",
548b2980e83f609186a76e98fb245d02e8547bc3jerenkrantz ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01185) "worker slotmem_create failed");
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz /* sync all timestamps */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* now go thru each worker */
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe for (j = 0; j < balancer->workers->nelts; j++, workers++) {
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf shm = ap_proxy_find_workershm(storage, balancer->wslot, worker, &index);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if ((rv = storage->fgrab(balancer->wslot, index)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(02409) "worker slotmem_fgrab failed");
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((rv = storage->grab(balancer->wslot, &index)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01186) "worker slotmem_grab failed");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((rv = storage->dptr(balancer->wslot, index, (void *)&shm)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01187) "worker slotmem_dptr failed");
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick if ((rv = ap_proxy_share_worker(worker, shm, index)) != APR_SUCCESS) {
f08810eff40a2bddd2bc0103453c4ae775ea62bewrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01188) "Cannot share worker");
700b96db75e7cfadb5219978c1735b710d583763wrowe /* We could have just read-in a persisted config. Force a sync. */
700b96db75e7cfadb5219978c1735b710d583763wrowestatic void create_radio(const char *name, unsigned int flag, request_rec *r)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_rvputs(r, "<td>On <input name='", name, "' id='", name, "' value='1' type=radio", NULL);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_rvputs(r, "> <br/> Off <input name='", name, "' id='", name, "' value='0' type=radio", NULL);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoarstatic void push2table(const char *input, apr_table_t *params,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe/* Manages the loadfactors and member status
700b96db75e7cfadb5219978c1735b710d583763wrowe * The balancer, worker and nonce are obtained from
700b96db75e7cfadb5219978c1735b710d583763wrowe * the request args (?b=...&w=...&nonce=....).
700b96db75e7cfadb5219978c1735b710d583763wrowe * All other params are pulled from any POST
700b96db75e7cfadb5219978c1735b710d583763wrowe * data that exists.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * /.../<whatever>/balancer/worker/nonce
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar const char *name;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe const char *action;
700b96db75e7cfadb5219978c1735b710d583763wrowe /* is this for us? */
700b96db75e7cfadb5219978c1735b710d583763wrowe if ((r->method_number != M_GET) && (r->method_number != M_POST)) {
700b96db75e7cfadb5219978c1735b710d583763wrowe conf = (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
700b96db75e7cfadb5219978c1735b710d583763wrowe for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
700b96db75e7cfadb5219978c1735b710d583763wrowe if ((rv = PROXY_THREAD_LOCK(balancer)) != APR_SUCCESS) {
700b96db75e7cfadb5219978c1735b710d583763wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01189)
700b96db75e7cfadb5219978c1735b710d583763wrowe "%s: Lock failed for balancer_handler",
2520f59894a3e07fefa881ef68aaded763a8d447ben if ((rv = PROXY_THREAD_UNLOCK(balancer)) != APR_SUCCESS) {
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01190)
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar "%s: Unlock failed for balancer_handler",
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar const char *allowed[] = { "w", "b", "nonce", "xml", NULL };
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01191) "parsing r->args");
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz ib = apr_brigade_create(r->connection->pool, r->connection->bucket_alloc);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe rv = ap_get_brigade(r->input_filters, ib, AP_MODE_READBYTES,
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_pstrcat(r->pool, BALANCER_PREFIX, name, NULL), 0);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker wsel = ap_proxy_get_worker(r->pool, bsel, conf, name);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Check that the supplied nonce matches this server's nonce;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar * otherwise ignore all parameters, to prevent a CSRF attack. */
700b96db75e7cfadb5219978c1735b710d583763wrowe /* First set the params */
69adb3d949e3dd17c0492a01fc2cf298832c7eefwrowe const char *val;
cf6ef072483172309861d06e85b1aeff4573c060wrowe ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01192) "settings worker params");
e8f95a682820a599fe41b22977010636be5c2717jim if (strlen(val) && strlen(val) < sizeof(wsel->s->route))
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (strlen(val) && strlen(val) < sizeof(wsel->s->redirect))
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* if enabling, we need to reset all lb params */
cf6ef072483172309861d06e85b1aeff4573c060wrowe if (bsel && !was_usable && PROXY_WORKER_IS_USABLE(wsel)) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe const char *val;
cf6ef072483172309861d06e85b1aeff4573c060wrowe ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01193)
cf6ef072483172309861d06e85b1aeff4573c060wrowe "settings balancer params");
71fe373d064756fb261876443806ece033ee3309slive lbmethod = ap_lookup_provider(PROXY_LBMETHOD, val, "0");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe nworker = ap_proxy_get_worker(r->pool, bsel, conf, val);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (!nworker && storage->num_free_slots(bsel->wslot)) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01194)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "%s: Lock failed for adding worker",
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ret = ap_proxy_define_worker(conf->pool, &nworker, bsel, conf, val, 0);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe unsigned int index;
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener if ((rv = storage->grab(bsel->wslot, &index)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_EMERG, rv, r, APLOGNO(01195)
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar "worker slotmem_grab failed");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
700b96db75e7cfadb5219978c1735b710d583763wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01196)
700b96db75e7cfadb5219978c1735b710d583763wrowe "%s: Unlock failed for adding worker",
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((rv = storage->dptr(bsel->wslot, index, (void *)&shm)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_EMERG, rv, r, APLOGNO(01197)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "worker slotmem_dptr failed");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01198)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "%s: Unlock failed for adding worker",
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((rv = ap_proxy_share_worker(nworker, shm, index)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_EMERG, rv, r, APLOGNO(01199)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "Cannot share worker");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01200)
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd "%s: Unlock failed for adding worker",
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((rv = ap_proxy_initialize_worker(nworker, r->server, conf->pool)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_EMERG, rv, r, APLOGNO(01201)
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar "Cannot init worker");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01202)
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar "%s: Unlock failed for adding worker",
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* sync all timestamps */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe bsel->wupdated = bsel->s->wupdated = nworker->s->updated = apr_time_now();
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd /* by default, all new workers are disabled */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01203)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "%s: Unlock failed for adding worker",
c2cf53a40a9814eb91db2cdf820f97d943f21628coar ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01204) "genning page");
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_rputs("<?xml version='1.0' encoding='UTF-8' ?>\n", r);
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_rputs("<httpd:manager xmlns:httpd='http://httpd.apache.org'>\n", r);
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* Start proxy_balancer */
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_rvputs(r, " <httpd:name>", balancer->s->name, "</httpd:name>\n", NULL);
c2cf53a40a9814eb91db2cdf820f97d943f21628coar ap_rvputs(r, " <httpd:stickysession>", balancer->s->sticky,
8aefbd756763807188d2e3ce336a8680e4893066wrowe " <httpd:nofailover>%s</httpd:nofailover>\n",
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe " <httpd:timeout>%" APR_TIME_T_FMT "</httpd:timeout>",
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe " <httpd:maxattempts>%d</httpd:maxattempts>\n",
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_rvputs(r, " <httpd:lbmethod>", balancer->lbmethod->name,
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar " <httpd:scolonpathdelim>%s</httpd:scolonpathdelim>\n",
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd /* End proxy_balancer */
0540a0b469147b52e858587270dba31c2aaa9e09wrowe /* Start proxy_worker */
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_rvputs(r, " <httpd:name>", worker->s->name, (worker->s->uds?"|":""),
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_rprintf(r, " <httpd:loadfactor>%d</httpd:loadfactor>\n",
0540a0b469147b52e858587270dba31c2aaa9e09wrowe " <httpd:port>%d</httpd:port>\n",
948096a99010fccf648814fecf38f75c689172d7wrowe " <httpd:timeout>%" APR_TIME_T_FMT "</httpd:timeout>\n",
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe " <httpd:acquire>%" APR_TIME_T_FMT "</httpd:acquire>\n",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb " <httpd:recv_buffer_size>%" APR_SIZE_T_FMT "</httpd:recv_buffer_size>\n",
948096a99010fccf648814fecf38f75c689172d7wrowe " <httpd:io_buffer_size>%" APR_SIZE_T_FMT "</httpd:io_buffer_size>\n",
948096a99010fccf648814fecf38f75c689172d7wrowe " <httpd:keepalive>%s</httpd:keepalive>\n",
948096a99010fccf648814fecf38f75c689172d7wrowe /* Begin proxy_worker_stat */
948096a99010fccf648814fecf38f75c689172d7wrowe else if (worker->s->status & PROXY_WORKER_HOT_STANDBY)
948096a99010fccf648814fecf38f75c689172d7wrowe if ((worker->s->error_time > 0) && apr_rfc822_date(date, worker->s->error_time) == APR_SUCCESS) {
a9a4544168a37b43bd180b3703ccee995f27a80awrowe " <httpd:retries>%d</httpd:retries>\n",
948096a99010fccf648814fecf38f75c689172d7wrowe " <httpd:lbstatus>%d</httpd:lbstatus>\n",
948096a99010fccf648814fecf38f75c689172d7wrowe " <httpd:loadfactor>%d</httpd:loadfactor>\n",
948096a99010fccf648814fecf38f75c689172d7wrowe " <httpd:transferred>%" APR_OFF_T_FMT "</httpd:transferred>\n",
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd " <httpd:elected>%" APR_SIZE_T_FMT "</httpd:elected>\n",
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* End proxy_worker_stat */
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz " <httpd:flushwait>%d</httpd:flushwait>\n",
948096a99010fccf648814fecf38f75c689172d7wrowe " <httpd:disablereuse>%s</httpd:disablereuse>\n",
948096a99010fccf648814fecf38f75c689172d7wrowe " <httpd:connectiontimeout>%" APR_TIME_T_FMT "</httpd:connectiontimeout>\n",
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ap_set_content_type(r, "text/html; charset=ISO-8859-1");
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd "<html><head><title>Balancer Manager</title>\n", r);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar "table {\n"
948096a99010fccf648814fecf38f75c689172d7wrowe " border-width: 1px;\n"
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd " border-spacing: 3px;\n"
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd " border-style: solid;\n"
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd " border-color: gray;\n"
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd " border-collapse: collapse;\n"
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar " background-color: white;\n"
053497224246c4dbef9af594cacf5c00ed271e6cwrowe " text-align: center;\n"
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd " border-width: 1px;\n"
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd " padding: 2px;\n"
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd " border-style: dotted;\n"
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd " border-color: gray;\n"
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd " background-color: white;\n"
a9a4544168a37b43bd180b3703ccee995f27a80awrowe " text-align: center;\n"
948096a99010fccf648814fecf38f75c689172d7wrowe " border-width: 1px;\n"
948096a99010fccf648814fecf38f75c689172d7wrowe " padding: 2px;\n"
053497224246c4dbef9af594cacf5c00ed271e6cwrowe " border-style: dotted;\n"
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar " border-color: gray;\n"
053497224246c4dbef9af594cacf5c00ed271e6cwrowe " background-color: white;\n"
053497224246c4dbef9af594cacf5c00ed271e6cwrowe " text-align: center;\n"
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar "</style>\n</head>\n", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, ap_escape_html(r->pool, ap_get_server_name(r)),
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rvputs(r, "<dt>Balancer changes will ", conf->bal_persist ? "" : "NOT ",
7a3c5fd3b3f86cdd450d551e326b3b9a04ea8248sf ap_rvputs(r, "<dt>Balancers are ", conf->inherit ? "" : "NOT ",
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rvputs(r, "<dt>ProxyPass settings are ", conf->ppinherit ? "" : "NOT ",
7a3c5fd3b3f86cdd450d551e326b3b9a04ea8248sf ap_rvputs(r, "<a href=\"", ap_escape_uri(r->pool, r->uri), "?b=",
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe ap_rvputs(r, balancer->s->name, "</a> [",balancer->s->sname, "]</h3>\n", NULL);
b5bd19d82874782007a2f9bcb19341a483c1270cwrowe "<th>MaxMembers</th><th>StickySession</th><th>DisableFailover</th><th>Timeout</th><th>FailoverAttempts</th><th>Method</th>"
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe "<th>Path</th><th>Active</th></tr>\n<tr>", r);
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe /* the below is a safe cast, since the number of slots total will
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe * never be more than max_workers, which is restricted to int */
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp ap_rprintf(r, "<td>%d [%d Used]</td>\n", balancer->max_workers,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd balancer->max_workers - (int)storage->num_free_slots(balancer->wslot));
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (strcmp(balancer->s->sticky, balancer->s->sticky_path)) {
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz ap_rvputs(r, "<td>", balancer->s->sticky, NULL);
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz ap_rprintf(r, "</td><td>%" APR_TIME_T_FMT "</td>",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rprintf(r, "<td>%d</td>\n", balancer->s->max_attempts);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "<th>Worker URL</th>"
aa047239dedf0d26e8efecfade32e7337f35df19wrowe "<th>Route</th><th>RouteRedir</th>"
aa047239dedf0d26e8efecfade32e7337f35df19wrowe "<th>Factor</th><th>Set</th><th>Status</th>"
aa047239dedf0d26e8efecfade32e7337f35df19wrowe "<th>Elected</th><th>Busy</th><th>Load</th><th>To</th><th>From</th>"
a9a4544168a37b43bd180b3703ccee995f27a80awrowe "</tr>\n", r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe balancer->s->name + sizeof(BALANCER_PREFIX) - 1, "&w=",
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rvputs(r, (worker->s->uds ? "<i>" : ""), worker->s->name,
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rvputs(r, "<td>", ap_escape_html(r->pool, worker->s->route),
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ap_rprintf(r, "</td><td>%d</td>", worker->s->lbfactor);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, ap_proxy_parse_wstatus(r->pool, worker), NULL);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rprintf(r, "<td>%" APR_SIZE_T_FMT "</td>", worker->s->elected);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rprintf(r, "<td>%" APR_SIZE_T_FMT "</td>", worker->s->busy);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_rputs(apr_strfsize(worker->s->transferred, fbuf), r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rvputs(r, (wsel->s->uds?"<i>":""), wsel->s->name, (wsel->s->uds?"|</i>":""), "</h3>\n", NULL);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rputs("<form method=\"POST\" enctype=\"application/x-www-form-urlencoded\" action=\"", r);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_rvputs(r, ap_escape_uri(r->pool, action), "\">\n", NULL);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rputs("<dl>\n<table><tr><td>Load factor:</td><td><input name='w_lf' id='w_lf' type=text ", r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rprintf(r, "value='%d'></td></tr>\n", wsel->s->lbfactor);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rputs("<tr><td>LB Set:</td><td><input name='w_ls' id='w_ls' type=text ", r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rprintf(r, "value='%d'></td></tr>\n", wsel->s->lbset);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("<tr><td>Route:</td><td><input name='w_wr' id='w_wr' type=text ", r);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_rvputs(r, "value=\"", ap_escape_html(r->pool, wsel->s->route),
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rputs("<tr><td>Route Redirect:</td><td><input name='w_rr' id='w_rr' type=text ", r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rvputs(r, "value=\"", ap_escape_html(r->pool, wsel->s->redirect),
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar "<th>Ignore Errors</th>"
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "<th>Draining Mode</th>"
aa047239dedf0d26e8efecfade32e7337f35df19wrowe "<th>Disabled</th>"
0540a0b469147b52e858587270dba31c2aaa9e09wrowe "<th>Hot Standby</th></tr>\n<tr>", r);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar create_radio("w_status_I", (PROXY_WORKER_IGNORE_ERRORS & wsel->s->status), r);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar create_radio("w_status_N", (PROXY_WORKER_DRAIN & wsel->s->status), r);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe create_radio("w_status_D", (PROXY_WORKER_DISABLED & wsel->s->status), r);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar create_radio("w_status_H", (PROXY_WORKER_HOT_STANDBY & wsel->s->status), r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rputs("<tr><td colspan=2><input type=submit value='Submit'></td></tr>\n", r);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_rvputs(r, "</table>\n<input type=hidden name='w' id='w' ", NULL);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rvputs(r, "value='", ap_escape_uri(r->pool, wsel->s->name), "'>\n", NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, "<input type=hidden name='b' id='b' ", NULL);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_rvputs(r, "value='", bsel->s->name + sizeof(BALANCER_PREFIX) - 1,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ap_rvputs(r, "<input type=hidden name='nonce' id='nonce' value='",
aa047239dedf0d26e8efecfade32e7337f35df19wrowe } else if (bsel) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("<form method='POST' enctype='application/x-www-form-urlencoded' action='", r);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd provs = ap_list_provider_names(r->pool, PROXY_LBMETHOD, "0");
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ap_rputs("<td>\n<select name='b_lbm' id='b_lbm'>", r);
a9a4544168a37b43bd180b3703ccee995f27a80awrowe ap_rvputs(r,"<option value='", pname->provider_name, "'", NULL);
a9a4544168a37b43bd180b3703ccee995f27a80awrowe if (strcmp(pname->provider_name, bsel->s->lbpname) == 0)
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rputs("<tr><td>Timeout:</td><td><input name='b_tmo' id='b_tmo' type=text ", r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rprintf(r, "value='%" APR_TIME_T_FMT "'></td></tr>\n", apr_time_sec(bsel->s->timeout));
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar ap_rputs("<tr><td>Failover Attempts:</td><td><input name='b_max' id='b_max' type=text ", r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rprintf(r, "value='%d'></td></tr>\n", bsel->s->max_attempts);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("<tr><td>Sticky Session:</td><td><input name='b_ss' id='b_ss' size=64 type=text ", r);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_rputs("'> (Use '-' to delete)</td></tr>\n", r);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_rputs("<tr><td>Add New Worker:</td><td><input name='b_nwrkr' id='b_nwrkr' size=32 type=text>"
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf " Are you sure? <input name='b_wyes' id='b_wyes' type=checkbox value='1'>"
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf "</td></tr>", r);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_rputs("<tr><td colspan=2><input type=submit value='Submit'></td></tr>\n", r);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_rvputs(r, "</table>\n<input type=hidden name='b' id='b' ", NULL);
7a3c5fd3b3f86cdd450d551e326b3b9a04ea8248sf ap_rvputs(r, "value='", bsel->s->name + sizeof(BALANCER_PREFIX) - 1,
11e076839c8d5a82d55e710194d0daac51390dbdsf ap_rvputs(r, "<input type=hidden name='nonce' id='nonce' value='",
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sfstatic void balancer_child_init(apr_pool_t *p, server_rec *s)
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf while (s) {
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf proxy_server_conf *conf = (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf unsigned int num;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf storage->attach(&(conf->bslot), conf->id, &size, &num, p);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01205) "slotmem_attach failed");
6b15044d54a096e6323ff1540f1a491e8de7622dsf for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
6b15044d54a096e6323ff1540f1a491e8de7622dsf ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s, APLOGNO(01206)
6b15044d54a096e6323ff1540f1a491e8de7622dsf "Failed to init balancer %s in child",
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sfstatic void ap_proxy_balancer_register_hook(apr_pool_t *p)
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf /* Only the mpm_winnt has child init hook handler.
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf * make sure that we are called after the mpm
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf * initializes
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf static const char *const aszPred[] = { "mpm_winnt.c", "mod_slotmem_shm.c", NULL};
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf static const char *const aszPred2[] = { "mod_proxy.c", NULL};
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf /* manager handler */
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_hook_post_config(balancer_post_config, aszPred2, NULL, APR_HOOK_MIDDLE);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_hook_pre_config(balancer_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_hook_handler(balancer_handler, NULL, NULL, APR_HOOK_FIRST);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_hook_child_init(balancer_child_init, aszPred, NULL, APR_HOOK_MIDDLE);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf proxy_hook_pre_request(proxy_balancer_pre_request, NULL, NULL, APR_HOOK_FIRST);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf proxy_hook_post_request(proxy_balancer_post_request, NULL, NULL, APR_HOOK_FIRST);