You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by mt...@apache.org on 2004/08/10 16:58:25 UTC
cvs commit: jakarta-tomcat-connectors/ajp/proxy mod_proxy.c proxy_balancer.c proxy_util.c mod_proxy.h
mturk 2004/08/10 07:58:24
Modified: ajp/proxy mod_proxy.c proxy_balancer.c proxy_util.c
mod_proxy.h
Log:
Implement the worker retry functionality.
It uses either worker->retry option or default 60 second retry
that is on each revolution extended by another 60 seconds.
Revision Changes Path
1.33 +1 -1 jakarta-tomcat-connectors/ajp/proxy/mod_proxy.c
Index: mod_proxy.c
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/ajp/proxy/mod_proxy.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- mod_proxy.c 10 Aug 2004 13:49:11 -0000 1.32
+++ mod_proxy.c 10 Aug 2004 14:58:24 -0000 1.33
@@ -97,7 +97,7 @@
else if (!strcasecmp(key, "retry")) {
ival = atoi(val);
if (ival < 1)
- return "Retry must be al least one second";
+ return "Retry must be at least one second";
worker->retry = apr_time_from_sec(ival);
}
else if (!strcasecmp(key, "ttl")) {
1.6 +7 -4 jakarta-tomcat-connectors/ajp/proxy/proxy_balancer.c
Index: proxy_balancer.c
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/ajp/proxy/proxy_balancer.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- proxy_balancer.c 10 Aug 2004 13:52:51 -0000 1.5
+++ proxy_balancer.c 10 Aug 2004 14:58:24 -0000 1.6
@@ -146,11 +146,14 @@
/* First try to see if we have available candidate */
for (i = 0; i < balancer->workers->nelts; i++) {
- /* If the worker is not error state
- * or not in disabled mode
+ /* See if the retry timeout is ellapsed
+ * for the workers flagged as IN_ERROR
+ */
+ if (!PROXY_WORKER_IS_USABLE(worker->w))
+ ap_proxy_retry_worker("BALANCER", worker->w, r->server)
+ /* If the worker is not in error state
+ * or not disabled.
*/
-
- /* TODO: read the scoreboard status */
if (PROXY_WORKER_IS_USABLE(worker->w)) {
if (!candidate)
candidate = worker;
1.24 +47 -2 jakarta-tomcat-connectors/ajp/proxy/proxy_util.c
Index: proxy_util.c
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/ajp/proxy/proxy_util.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- proxy_util.c 10 Aug 2004 13:50:53 -0000 1.23
+++ proxy_util.c 10 Aug 2004 14:58:24 -0000 1.24
@@ -1471,6 +1471,31 @@
return rv;
}
+PROXY_DECLARE(int) ap_proxy_retry_worker(const char *proxy_function,
+ proxy_worker *worker,
+ server_rec *s)
+{
+ if (worker->status & PROXY_WORKER_IN_ERROR) {
+ apr_interval_time_t diff;
+ apr_time_t now = apr_time_now();
+ if (worker->retry)
+ diff = worker->retry;
+ else
+ diff = apr_time_from_sec(60 + 60 * worker->retries++);
+ if (now > worker->error_time + diff) {
+ worker->status &= ~PROXY_WORKER_IN_ERROR;
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
+ "proxy: %s: retrying the worker for (%s)",
+ proxy_function, worker->hostname);
+ return OK;
+ }
+ else
+ return DECLINED;
+ }
+ else
+ return OK;
+}
+
PROXY_DECLARE(int) ap_proxy_acquire_connection(const char *proxy_function,
proxy_conn_rec **conn,
proxy_worker *worker,
@@ -1483,10 +1508,22 @@
ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
"proxy: %s: failed to initialize worker for (%s)",
proxy_function, worker->hostname);
- return DECLINED;
+ return HTTP_INTERNAL_SERVER_ERROR;
}
worker->status = PROXY_WORKER_INITIALIZED;
}
+
+ if (!PROXY_WORKER_IS_USABLE(worker)) {
+ /* Retry the worker */
+ ap_proxy_retry_worker(proxy_function, worker, s);
+
+ if (!PROXY_WORKER_IS_USABLE(worker)) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
+ "proxy: %s: disabled connection for (%s)",
+ proxy_function, worker->hostname);
+ return HTTP_SERVICE_UNAVAILABLE;
+ }
+ }
#if APR_HAS_THREADS
if (worker->hmax) {
rv = apr_reslist_acquire(worker->cp->res, (void **)conn);
@@ -1508,7 +1545,7 @@
ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
"proxy: %s: failed to acquire connection for (%s)",
proxy_function, worker->hostname);
- return DECLINED;
+ return HTTP_SERVICE_UNAVAILABLE;
}
return OK;
}
@@ -1722,6 +1759,14 @@
conn->sock = newsock;
conn->worker = worker;
connected = 1;
+ }
+ /* Put the entire worker to error state
+ * Altrough some connections may be alive
+ * no further connections to the worker could be made
+ */
+ if (!connected && PROXY_WORKER_IS_USABLE(worker)) {
+ worker->status |= PROXY_WORKER_IN_ERROR;
+ worker->error_time = apr_time_now();
}
return connected ? OK : DECLINED;
}
1.30 +1 -0 jakarta-tomcat-connectors/ajp/proxy/mod_proxy.h
Index: mod_proxy.h
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/ajp/proxy/mod_proxy.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- mod_proxy.h 10 Aug 2004 13:50:53 -0000 1.29
+++ mod_proxy.h 10 Aug 2004 14:58:24 -0000 1.30
@@ -384,6 +384,7 @@
PROXY_DECLARE(int) ap_proxy_determine_connection(apr_pool_t *p, request_rec *r, proxy_server_conf *conf, proxy_worker *worker, proxy_conn_rec *conn,
apr_pool_t *ppool, apr_uri_t *uri, char **url, const char *proxyname, apr_port_t proxyport,
char *server_portstr, int server_portstr_size);
+PROXY_DECLARE(int) ap_proxy_retry_worker(const char *proxy_function, proxy_worker *worker, server_rec *s);
PROXY_DECLARE(int) ap_proxy_acquire_connection(const char *proxy_function, proxy_conn_rec **conn, proxy_worker *worker, server_rec *s);
PROXY_DECLARE(int) ap_proxy_release_connection(const char *proxy_function, proxy_conn_rec *conn, server_rec *s);
PROXY_DECLARE(apr_status_t) ap_proxy_close_connection(proxy_conn_rec *conn);
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org