mturk 2005/02/16 07:09:21 Modified: jk/native/apache-1.3 mod_jk.c jk/native/apache-2.0 mod_jk.c jk/native/common jk_ajp12_worker.c jk_ajp_common.c jk_global.h jk_lb_worker.c jk_service.h jk/native/iis jk_isapi_plugin.c Log: Change the way how is_recoverable is handled. Instead this which was never used, use that value to return the specific http error code, namely 500 or 503. Revision Changes Path 1.69 +5 -5 jakarta-tomcat-connectors/jk/native/apache-1.3/mod_jk.c Index: mod_jk.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/apache-1.3/mod_jk.c,v retrieving revision 1.68 retrieving revision 1.69 diff -u -r1.68 -r1.69 --- mod_jk.c 15 Feb 2005 07:30:49 -0000 1.68 +++ mod_jk.c 16 Feb 2005 15:09:20 -0000 1.69 @@ -1637,6 +1637,7 @@ struct timeval tv_begin, tv_end; #endif int rc = JK_FALSE; + int is_error = JK_HTTP_SERVER_ERROR; apache_private_data_t private_data; jk_ws_service_t s; jk_pool_atom_t buf[SMALL_POOL_SIZE]; @@ -1661,8 +1662,7 @@ if (init_ws_service(&private_data, &s, conf)) { jk_endpoint_t *end = NULL; if (worker->get_endpoint(worker, &end, l)) { - int is_recoverable_error = JK_FALSE; - rc = end->service(end, &s, l, &is_recoverable_error); + rc = end->service(end, &s, l, &is_error); if (s.content_read < s.content_length || (s.is_chunked && !s.no_more_chunks)) { @@ -1705,7 +1705,7 @@ " for worker=%s", worker_name); JK_TRACE_EXIT(l); - return HTTP_INTERNAL_SERVER_ERROR; + return is_error; } jk_close_pool(&private_data.p); @@ -1739,7 +1739,7 @@ " for worker=%s", rc, worker_name); JK_TRACE_EXIT(l); - return HTTP_INTERNAL_SERVER_ERROR; + return is_error; } } else { 1.126 +5 -5 jakarta-tomcat-connectors/jk/native/apache-2.0/mod_jk.c Index: mod_jk.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/apache-2.0/mod_jk.c,v retrieving revision 1.125 retrieving revision 1.126 diff -u -r1.125 -r1.126 --- mod_jk.c 15 Feb 2005 07:30:49 -0000 1.125 +++ mod_jk.c 16 Feb 2005 15:09:20 -0000 1.126 @@ -86,8 +86,8 @@ #define __sys_timeval_h__ #endif -#include "jk_ajp13.h" #include "jk_global.h" +#include "jk_ajp13.h" #include "jk_logger.h" #include "jk_map.h" #include "jk_pool.h" @@ -1797,6 +1797,7 @@ #ifndef NO_GETTIMEOFDAY struct timeval tv_begin, tv_end; #endif + int is_error = HTTP_INTERNAL_SERVER_ERROR; int rc = JK_FALSE; apache_private_data_t private_data; jk_ws_service_t s; @@ -1829,9 +1830,8 @@ /* worker->get_endpoint might fail if we are out of memory so check */ /* and handle it */ if (worker->get_endpoint(worker, &end, xconf->log)) { - int is_recoverable_error = JK_FALSE; rc = end->service(end, &s, xconf->log, - &is_recoverable_error); + &is_error); if (s.content_read < s.content_length || (s.is_chunked && !s.no_more_chunks)) { @@ -1915,7 +1915,7 @@ " for worker=%s", rc, worker_name); JK_TRACE_EXIT(xconf->log); - return HTTP_INTERNAL_SERVER_ERROR; + return is_error; } } else { 1.24 +5 -5 jakarta-tomcat-connectors/jk/native/common/jk_ajp12_worker.c Index: jk_ajp12_worker.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_ajp12_worker.c,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- jk_ajp12_worker.c 16 Feb 2005 08:15:56 -0000 1.23 +++ jk_ajp12_worker.c 16 Feb 2005 15:09:20 -0000 1.24 @@ -85,15 +85,15 @@ static int JK_METHOD service(jk_endpoint_t *e, jk_ws_service_t *s, - jk_logger_t *l, int *is_recoverable_error) + jk_logger_t *l, int *is_error) { jk_log(l, JK_LOG_DEBUG, "Into jk_endpoint_t::service"); - if (e && e->endpoint_private && s && is_recoverable_error) { + if (e && e->endpoint_private && s && is_error) { ajp12_endpoint_t *p = e->endpoint_private; unsigned attempt; - *is_recoverable_error = JK_TRUE; + *is_error = 0; for (attempt = 0; attempt < p->worker->connect_retry_attempts; attempt++) { @@ -113,7 +113,7 @@ * After we are connected, each error that we are going to * have is probably unrecoverable */ - *is_recoverable_error = JK_FALSE; + *is_error = JK_HTTP_SERVER_ERROR; jk_sb_open(&p->sb, p->sd); if (ajpv12_handle_request(p, s, l)) { jk_log(l, JK_LOG_DEBUG, 1.83 +14 -13 jakarta-tomcat-connectors/jk/native/common/jk_ajp_common.c Index: jk_ajp_common.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_ajp_common.c,v retrieving revision 1.82 retrieving revision 1.83 diff -u -r1.82 -r1.83 --- jk_ajp_common.c 16 Feb 2005 11:08:14 -0000 1.82 +++ jk_ajp_common.c 16 Feb 2005 15:09:20 -0000 1.83 @@ -1562,7 +1562,7 @@ */ int JK_METHOD ajp_service(jk_endpoint_t *e, jk_ws_service_t *s, - jk_logger_t *l, int *is_recoverable_error) + jk_logger_t *l, int *is_error) { int i, err; ajp_operation_t oper; @@ -1570,9 +1570,12 @@ JK_TRACE_ENTER(l); - if (e && e->endpoint_private && s && is_recoverable_error) { + if (e && e->endpoint_private && s && is_error) { ajp_endpoint_t *p = e->endpoint_private; op->request = jk_b_new(&(p->pool)); + /* Presume there will be no errors */ + *is_error = JK_HTTP_OK; + jk_b_set_buffer_size(op->request, DEF_BUFFER_SZ); jk_b_reset(op->request); @@ -1589,7 +1592,7 @@ p->left_bytes_to_send = s->content_length; p->reuse = JK_FALSE; - *is_recoverable_error = JK_TRUE; + *is_error = 0; s->secret = p->worker->secret; @@ -1597,7 +1600,7 @@ * We get here initial request (in reqmsg) */ if (!ajp_marshal_into_msgb(op->request, s, l, p)) { - *is_recoverable_error = JK_FALSE; + *is_error = JK_HTTP_SERVER_ERROR; JK_TRACE_EXIT(l); return JK_FALSE; } @@ -1622,7 +1625,7 @@ * (certainly in a big post) */ if (!op->recoverable) { - *is_recoverable_error = JK_FALSE; + *is_error = JK_HTTP_SERVER_ERROR; jk_log(l, JK_LOG_ERROR, "sending request to tomcat failed " "without recovery in send loop %d", i); @@ -1631,7 +1634,7 @@ } /* Up to there we can recover */ - *is_recoverable_error = JK_TRUE; + *is_error = 0; err = ajp_get_reply(e, s, l, p, op); if (err > 0) { @@ -1646,7 +1649,7 @@ * operation is no more recoverable */ if (!op->recoverable) { - *is_recoverable_error = JK_FALSE; + *is_error = JK_HTTP_SERVER_ERROR; jk_log(l, JK_LOG_ERROR, "receiving reply from tomcat failed " "without recovery in send loop %d", i); @@ -1662,11 +1665,8 @@ } } } - /* Get another connection from the pool */ - ajp_next_connection(&p, l); - if (err == JK_CLIENT_ERROR) { - *is_recoverable_error = JK_FALSE; + *is_error = JK_HTTP_SERVER_ERROR; jk_log(l, JK_LOG_ERROR, "Client connection aborted or network problems"); JK_TRACE_EXIT(l); @@ -1677,7 +1677,8 @@ "Sending request to tomcat failed, " "recoverable operation attempt=%d", i); } - + /* Get another connection from the pool and try again */ + ajp_next_connection(&p, l); } /* Log the error only once per failed request. */ 1.44 +9 -1 jakarta-tomcat-connectors/jk/native/common/jk_global.h Index: jk_global.h =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_global.h,v retrieving revision 1.43 retrieving revision 1.44 diff -u -r1.43 -r1.44 --- jk_global.h 15 Feb 2005 11:43:15 -0000 1.43 +++ jk_global.h 16 Feb 2005 15:09:21 -0000 1.44 @@ -171,6 +171,14 @@ #define PATH_ENV_VARIABLE ("LD_LIBRARY_PATH") #endif +/* HTTP Error codes + */ + +#define JK_HTTP_SERVER_ERROR 500 +#define JK_HTTP_SERVER_BUSY 503 +#define JK_HTTP_OK 200 + + /* * RECO STATUS */ 1.56 +58 -32 jakarta-tomcat-connectors/jk/native/common/jk_lb_worker.c Index: jk_lb_worker.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_lb_worker.c,v retrieving revision 1.55 retrieving revision 1.56 diff -u -r1.55 -r1.56 --- jk_lb_worker.c 16 Feb 2005 13:46:30 -0000 1.55 +++ jk_lb_worker.c 16 Feb 2005 15:09:21 -0000 1.56 @@ -477,16 +477,16 @@ static int JK_METHOD service(jk_endpoint_t *e, jk_ws_service_t *s, - jk_logger_t *l, int *is_recoverable_error) + jk_logger_t *l, int *is_error) { JK_TRACE_ENTER(l); - if (e && e->endpoint_private && s && is_recoverable_error) { + if (e && e->endpoint_private && s && is_error) { lb_endpoint_t *p = e->endpoint_private; int attempt = 0; - + int num_of_workers = p->worker->num_of_workers; /* you can not recover on another load balancer */ - *is_recoverable_error = JK_FALSE; + *is_error = JK_HTTP_OK; /* set the recovery post, for LB mode */ s->reco_buf = jk_b_new(s->pool); @@ -498,13 +498,13 @@ "service sticky_session=%d", p->worker->s->sticky_session); - while (1) { + while (num_of_workers) { worker_record_t *rec = get_most_suitable_worker(p->worker, s, attempt++, l); int rc; if (rec) { - int is_recoverable = JK_FALSE; + int is_service_error = JK_HTTP_OK; jk_endpoint_t *end = NULL; s->jvm_route = jk_pool_strdup(s->pool, rec->s->name); @@ -518,8 +518,12 @@ rec->s->elected++; if (rc && end) { int src; - end->rd = end->wr = 0; - src = end->service(end, s, l, &is_recoverable); + /* Reset endpoint read and write sizes for + * this request. + */ + end->rd = end->wr = 0; + src = end->service(end, s, l, &is_service_error); + /* Update partial reads and writes if any */ rec->s->readed += end->rd; rec->s->transferred += end->wr; end->done(&end, l); @@ -531,46 +535,68 @@ return JK_TRUE; } } - rec->s->errors++; - /* - * Service failed !!! - * - * Time for fault tolerance (if possible)... - */ - - rec->s->in_error_state = JK_TRUE; - rec->s->in_recovering = JK_FALSE; - rec->s->error_time = time(0); - - if (end && !is_recoverable) { + if (end) { /* - * Error is not recoverable - break with an error. + * Service failed !!! + * + * Time for fault tolerance (if possible)... + */ + + rec->s->errors++; + rec->s->in_error_state = JK_TRUE; + rec->s->in_recovering = JK_FALSE; + rec->s->error_time = time(0); + + if (is_service_error > JK_HTTP_OK) { + /* + * Error is not recoverable - break with an error. + */ + jk_log(l, JK_LOG_ERROR, + "unrecoverable error %d, request failed." + " Tomcat failed in the middle of request," + " we can't recover to another instance.", + is_service_error); + *is_error = is_service_error; + JK_TRACE_EXIT(l); + return JK_FALSE; + } + } + else { + /* If we can not get the endpoint from the worker + * that does not mean that the worker is in error + * state. It means that the worker is busy. + * We will try another worker. + * To prevent infinite loop decrement worker count; */ - jk_log(l, JK_LOG_ERROR, - "unrecoverable error, request failed." - " Tomcat failed in the middle of request," - " we can't recover to another instance."); - JK_TRACE_EXIT(l); - return JK_FALSE; + --num_of_workers; } - /* * Error is recoverable by submitting the request to * another worker... Lets try to do that. */ - jk_log(l, JK_LOG_DEBUG, - "recoverable error... will try to recover on other host"); + if (JK_IS_DEBUG_LEVEL(l)) + jk_log(l, JK_LOG_DEBUG, + "recoverable error... will try to recover on other host"); } else { /* NULL record, no more workers left ... */ jk_log(l, JK_LOG_ERROR, - "lb: All tomcat instances failed, no more workers left."); + "All tomcat instances failed, no more workers left"); JK_TRACE_EXIT(l); + *is_error = JK_HTTP_SERVER_ERROR; return JK_FALSE; } } + jk_log(l, JK_LOG_INFO, + "All tomcat instances are busy, no more endpoints left. " + "Rise cache_size to match the load"); + JK_TRACE_EXIT(l); + /* Set error to Server busy */ + *is_error = JK_HTTP_SERVER_BUSY; + return JK_FALSE; } - + if (is_error) + *is_error = JK_HTTP_SERVER_ERROR; JK_LOG_NULL_PARAMS(l); JK_TRACE_EXIT(l); return JK_FALSE; 1.29 +5 -4 jakarta-tomcat-connectors/jk/native/common/jk_service.h Index: jk_service.h =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_service.h,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- jk_service.h 15 Feb 2005 08:52:53 -0000 1.28 +++ jk_service.h 16 Feb 2005 15:09:21 -0000 1.29 @@ -290,12 +290,13 @@ /* * Forward a request to the servlet engine. The request is described - * by the jk_ws_service_t object. I'm not sure exactly how - * is_recoverable_error is being used. + * by the jk_ws_service_t object. + * is_error is either 0 meaning recoverable or set to + * the HTTP error code. */ int (JK_METHOD * service) (jk_endpoint_t *e, jk_ws_service_t *s, - jk_logger_t *l, int *is_recoverable_error); + jk_logger_t *l, int *is_error); /* * Called when this particular endpoint has finished processing a 1.39 +4 -3 jakarta-tomcat-connectors/jk/native/iis/jk_isapi_plugin.c Index: jk_isapi_plugin.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/iis/jk_isapi_plugin.c,v retrieving revision 1.38 retrieving revision 1.39 diff -u -r1.38 -r1.39 --- jk_isapi_plugin.c 13 Feb 2005 12:26:24 -0000 1.38 +++ jk_isapi_plugin.c 16 Feb 2005 15:09:21 -0000 1.39 @@ -927,14 +927,15 @@ /* Update retries for this worker */ s.retries = worker->retries; if (worker->get_endpoint(worker, &e, logger)) { - int recover = JK_FALSE; - if (e->service(e, &s, logger, &recover)) { + int is_error = JK_HTTP_SERVER_ERROR; + if (e->service(e, &s, logger, &is_error)) { rc = HSE_STATUS_SUCCESS; lpEcb->dwHttpStatusCode = HTTP_STATUS_OK; jk_log(logger, JK_LOG_DEBUG, "service() returned OK"); } else { + lpEcb->dwHttpStatusCode = is_error; jk_log(logger, JK_LOG_ERROR, "service() failed"); }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]