Author: rjung
Date: Wed Aug 23 14:02:24 2006
New Revision: 434177
URL: http://svn.apache.org/viewvc?rev=434177&view=rev
Log:
Cleanup of the code structure of the service method.
Adding TACE, JK_LOG_NULL_PARAMS and do the same null pointer
checks in all service methods.
95% of the diff log comes from changed indentation due to
deleted "if" statements.
Modified:
tomcat/connectors/trunk/jk/native/common/jk_ajp12_worker.c
tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c
tomcat/connectors/trunk/jk/native/common/jk_jni_worker.c
tomcat/connectors/trunk/jk/native/common/jk_lb_worker.c
tomcat/connectors/trunk/jk/native/common/jk_status.c
Modified: tomcat/connectors/trunk/jk/native/common/jk_ajp12_worker.c
URL:
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_ajp12_worker.c?rev=434177&r1=434176&r2=434177&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_ajp12_worker.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_ajp12_worker.c Wed Aug 23
14:02:24 2006
@@ -87,45 +87,50 @@
jk_ws_service_t *s,
jk_logger_t *l, int *is_error)
{
- jk_log(l, JK_LOG_DEBUG, "Into jk_endpoint_t::service");
+ ajp12_endpoint_t *p = e->endpoint_private;
+ unsigned int attempt;
+ int rc = -1;
+ /*
+ * AJP12 protocol is not recoverable.
+ */
- if (e && e->endpoint_private && s && is_error) {
- ajp12_endpoint_t *p = e->endpoint_private;
- unsigned int attempt;
- /*
- * AJP12 protocol is not recoverable.
- */
+ JK_TRACE_ENTER(l);
+
+ if (is_error)
*is_error = JK_HTTP_SERVER_ERROR;
+ if (!e || !e->endpoint_private || !s || !is_error) {
+ JK_LOG_NULL_PARAMS(l);
+ JK_TRACE_EXIT(l);
+ return JK_FALSE;
+ }
- for (attempt = 0; attempt < p->worker->connect_retry_attempts;
- attempt++) {
- p->sd =
- jk_open_socket(&p->worker->worker_inet_addr,
- JK_FALSE, -1, 0, l);
+ for (attempt = 0; attempt < p->worker->connect_retry_attempts;
+ attempt++) {
+ p->sd =
+ jk_open_socket(&p->worker->worker_inet_addr,
+ JK_FALSE, -1, 0, l);
- jk_log(l, JK_LOG_DEBUG, "In jk_endpoint_t::service, sd = %d",
- p->sd);
- if (IS_VALID_SOCKET(p->sd)) {
- break;
- }
- }
+ jk_log(l, JK_LOG_DEBUG, "In jk_endpoint_t::service, sd = %d",
+ p->sd);
if (IS_VALID_SOCKET(p->sd)) {
-
- jk_sb_open(&p->sb, p->sd);
- if (ajpv12_handle_request(p, s, l)) {
- jk_log(l, JK_LOG_DEBUG,
- "In jk_endpoint_t::service, sent request");
- return ajpv12_handle_response(p, s, l);
- }
+ break;
}
- jk_log(l, JK_LOG_ERROR, "In jk_endpoint_t::service, Error sd = %d",
- p->sd);
}
- else {
- jk_log(l, JK_LOG_ERROR,
- "In jk_endpoint_t::service, NULL parameters");
+ if (IS_VALID_SOCKET(p->sd)) {
+
+ jk_sb_open(&p->sb, p->sd);
+ if (ajpv12_handle_request(p, s, l)) {
+ jk_log(l, JK_LOG_DEBUG,
+ "In jk_endpoint_t::service, sent request");
+ rc = ajpv12_handle_response(p, s, l);
+ JK_TRACE_EXIT(l);
+ return rc;
+ }
}
+ jk_log(l, JK_LOG_ERROR, "In jk_endpoint_t::service, Error sd = %d",
+ p->sd);
+ JK_TRACE_EXIT(l);
return JK_FALSE;
}
Modified: tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c
URL:
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c?rev=434177&r1=434176&r2=434177&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c Wed Aug 23
14:02:24 2006
@@ -1654,152 +1654,152 @@
int i, err;
ajp_operation_t oper;
ajp_operation_t *op = &oper;
+ ajp_endpoint_t *p;
JK_TRACE_ENTER(l);
if (is_error)
*is_error = JK_HTTP_SERVER_ERROR;
+ if (!e || !e->endpoint_private || !s || !is_error) {
+ JK_LOG_NULL_PARAMS(l);
+ JK_TRACE_EXIT(l);
+ return JK_FALSE;
+ }
- if (e && e->endpoint_private && s && is_error) {
- ajp_endpoint_t *p = e->endpoint_private;
- op->request = jk_b_new(&(p->pool));
- jk_b_set_buffer_size(op->request, DEF_BUFFER_SZ);
- jk_b_reset(op->request);
-
- op->reply = jk_b_new(&(p->pool));
- jk_b_set_buffer_size(op->reply, DEF_BUFFER_SZ);
- jk_b_reset(op->reply);
-
- op->post = jk_b_new(&(p->pool));
- jk_b_set_buffer_size(op->post, DEF_BUFFER_SZ);
- jk_b_reset(op->post);
-
- op->recoverable = JK_TRUE;
- op->uploadfd = -1; /* not yet used, later ;) */
-
- p->left_bytes_to_send = s->content_length;
- p->reuse = JK_FALSE;
-
- s->secret = p->worker->secret;
+ p = e->endpoint_private;
+ op->request = jk_b_new(&(p->pool));
+ jk_b_set_buffer_size(op->request, DEF_BUFFER_SZ);
+ jk_b_reset(op->request);
+
+ op->reply = jk_b_new(&(p->pool));
+ jk_b_set_buffer_size(op->reply, DEF_BUFFER_SZ);
+ jk_b_reset(op->reply);
+
+ op->post = jk_b_new(&(p->pool));
+ jk_b_set_buffer_size(op->post, DEF_BUFFER_SZ);
+ jk_b_reset(op->post);
+
+ op->recoverable = JK_TRUE;
+ op->uploadfd = -1; /* not yet used, later ;) */
+
+ p->left_bytes_to_send = s->content_length;
+ p->reuse = JK_FALSE;
+
+ s->secret = p->worker->secret;
+
+ /*
+ * We get here initial request (in reqmsg)
+ */
+ if (!ajp_marshal_into_msgb(op->request, s, l, p)) {
+ *is_error = JK_REQUEST_TOO_LARGE;
+ jk_log(l, JK_LOG_INFO,
+ "Creating AJP message failed, "
+ "without recovery");
+ JK_TRACE_EXIT(l);
+ return JK_CLIENT_ERROR;
+ }
+ if (JK_IS_DEBUG_LEVEL(l)) {
+ jk_log(l, JK_LOG_DEBUG, "processing %s with %d retries",
+ p->worker->name, p->worker->worker.retries);
+ }
+ /*
+ * JK_RETRIES could be replaced by the number of workers in
+ * a load-balancing configuration
+ */
+ for (i = 0; i < p->worker->worker.retries; i++) {
/*
- * We get here initial request (in reqmsg)
+ * We're using reqmsg which hold initial request
+ * if Tomcat is stopped or restarted, we will pass reqmsg
+ * to next valid tomcat.
*/
- if (!ajp_marshal_into_msgb(op->request, s, l, p)) {
- *is_error = JK_REQUEST_TOO_LARGE;
- jk_log(l, JK_LOG_INFO,
- "Creating AJP message failed, "
- "without recovery");
- JK_TRACE_EXIT(l);
- return JK_CLIENT_ERROR;
- }
+ err = ajp_send_request(e, s, l, p, op);
+ if (err == JK_TRUE) {
- if (JK_IS_DEBUG_LEVEL(l)) {
- jk_log(l, JK_LOG_DEBUG, "processing %s with %d retries",
- p->worker->name, p->worker->worker.retries);
- }
- /*
- * JK_RETRIES could be replaced by the number of workers in
- * a load-balancing configuration
- */
- for (i = 0; i < p->worker->worker.retries; i++) {
- /*
- * We're using reqmsg which hold initial request
- * if Tomcat is stopped or restarted, we will pass reqmsg
- * to next valid tomcat.
+ /* If we have the no recoverable error, it's probably because
+ * the sender (browser) stopped sending data before the end
+ * (certainly in a big post)
*/
- err = ajp_send_request(e, s, l, p, op);
+ if (!op->recoverable) {
+ *is_error = JK_HTTP_SERVER_ERROR;
+ jk_log(l, JK_LOG_ERROR,
+ "sending request to tomcat failed "
+ "without recovery in send loop %d", i);
+ JK_TRACE_EXIT(l);
+ return JK_FALSE;
+ }
+
+ /* Up to there we can recover */
+
+ err = ajp_get_reply(e, s, l, p, op);
if (err == JK_TRUE) {
+ *is_error = JK_HTTP_OK;
+ /* Done with the request */
+ JK_TRACE_EXIT(l);
+ return JK_TRUE;
+ }
- /* If we have the no recoverable error, it's probably because
- * the sender (browser) stopped sending data before the end
- * (certainly in a big post)
+ if (err != JK_CLIENT_ERROR) {
+ /* if we can't get reply, check if no recover flag was set
+ * if is_recoverable_error is cleared, we have started
+ * receiving upload data and we must consider that
+ * operation is no more recoverable
*/
if (!op->recoverable) {
- *is_error = JK_HTTP_SERVER_ERROR;
+ *is_error = JK_HTTP_BAD_GATEWAY;
jk_log(l, JK_LOG_ERROR,
- "sending request to tomcat failed "
+ "receiving reply from tomcat failed "
"without recovery in send loop %d", i);
JK_TRACE_EXIT(l);
return JK_FALSE;
}
-
- /* Up to there we can recover */
-
- err = ajp_get_reply(e, s, l, p, op);
- if (err == JK_TRUE) {
- *is_error = JK_HTTP_OK;
- /* Done with the request */
- JK_TRACE_EXIT(l);
- return JK_TRUE;
- }
-
- if (err != JK_CLIENT_ERROR) {
- /* if we can't get reply, check if no recover flag was set
- * if is_recoverable_error is cleared, we have started
- * receiving upload data and we must consider that
- * operation is no more recoverable
- */
- if (!op->recoverable) {
- *is_error = JK_HTTP_BAD_GATEWAY;
- jk_log(l, JK_LOG_ERROR,
- "receiving reply from tomcat failed "
- "without recovery in send loop %d", i);
- JK_TRACE_EXIT(l);
- return JK_FALSE;
- }
- jk_log(l, JK_LOG_INFO,
- "Receiving from tomcat failed, "
- "recoverable operation attempt=%d", i);
- /* Check for custom retries */
- if (i >= JK_RETRIES) {
- jk_sleep_def();
- }
- }
- else {
- *is_error = JK_HTTP_BAD_REQUEST;
- jk_log(l, JK_LOG_INFO,
- "Receiving from tomcat failed, "
- "because of client error "
- "without recovery in send loop %d", i);
- JK_TRACE_EXIT(l);
- return JK_CLIENT_ERROR;
+ jk_log(l, JK_LOG_INFO,
+ "Receiving from tomcat failed, "
+ "recoverable operation attempt=%d", i);
+ /* Check for custom retries */
+ if (i >= JK_RETRIES) {
+ jk_sleep_def();
}
}
- if (err == JK_CLIENT_ERROR) {
+ else {
*is_error = JK_HTTP_BAD_REQUEST;
- if (p->worker->recovery_opts & RECOVER_ABORT_IF_CLIENTERROR) {
- /* Mark the endpoint for shutdown */
- p->reuse = JK_FALSE;
- }
jk_log(l, JK_LOG_INFO,
- "Sending request to tomcat failed, "
+ "Receiving from tomcat failed, "
"because of client error "
"without recovery in send loop %d", i);
JK_TRACE_EXIT(l);
return JK_CLIENT_ERROR;
}
- else {
- jk_log(l, JK_LOG_INFO,
- "Sending request to tomcat failed, "
- "recoverable operation attempt=%d", i + 1);
+ }
+ if (err == JK_CLIENT_ERROR) {
+ *is_error = JK_HTTP_BAD_REQUEST;
+ if (p->worker->recovery_opts & RECOVER_ABORT_IF_CLIENTERROR) {
+ /* Mark the endpoint for shutdown */
+ p->reuse = JK_FALSE;
}
- /* Get another connection from the pool and try again.
- * Note: All sockets are probably closed already.
- */
- ajp_next_connection(p, l);
+ jk_log(l, JK_LOG_INFO,
+ "Sending request to tomcat failed, "
+ "because of client error "
+ "without recovery in send loop %d", i);
+ JK_TRACE_EXIT(l);
+ return JK_CLIENT_ERROR;
}
- *is_error = JK_HTTP_SERVER_BUSY;
- /* Log the error only once per failed request. */
- jk_log(l, JK_LOG_ERROR,
- "Error connecting to tomcat. Tomcat is probably not started "
- "or is listening on the wrong port. worker=%s failed",
- p->worker->name);
-
- }
- else {
- jk_log(l, JK_LOG_ERROR, "end of service with error");
+ else {
+ jk_log(l, JK_LOG_INFO,
+ "Sending request to tomcat failed, "
+ "recoverable operation attempt=%d", i + 1);
+ }
+ /* Get another connection from the pool and try again.
+ * Note: All sockets are probably closed already.
+ */
+ ajp_next_connection(p, l);
}
+ *is_error = JK_HTTP_SERVER_BUSY;
+ /* Log the error only once per failed request. */
+ jk_log(l, JK_LOG_ERROR,
+ "Error connecting to tomcat. Tomcat is probably not started "
+ "or is listening on the wrong port. worker=%s failed",
+ p->worker->name);
JK_TRACE_EXIT(l);
return JK_FALSE;
Modified: tomcat/connectors/trunk/jk/native/common/jk_jni_worker.c
URL:
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_jni_worker.c?rev=434177&r1=434176&r2=434177&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_jni_worker.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_jni_worker.c Wed Aug 23
14:02:24 2006
@@ -254,7 +254,10 @@
jint rc;
JK_TRACE_ENTER(l);
- if (!e || !e->endpoint_private || !s) {
+
+ if (is_recoverable_error)
+ *is_recoverable_error = JK_FALSE;
+ if (!e || !e->endpoint_private || !s || !is_recoverable_error) {
JK_LOG_NULL_PARAMS(l);
JK_TRACE_EXIT(l);
return JK_FALSE;
@@ -262,11 +265,6 @@
p = e->endpoint_private;
- if (!is_recoverable_error) {
- JK_TRACE_EXIT(l);
- return JK_FALSE;
- }
-
if (!p->attached) {
/* Try to attach */
if (!(p->env = attach_to_jvm(p->worker, l))) {
@@ -285,8 +283,6 @@
* When we call the JVM we cannot know what happens
* So we can not recover !!!
*/
- *is_recoverable_error = JK_FALSE;
-
jk_log(l, JK_LOG_DEBUG, "In service, calling Tomcat...");
rc = (*(p->env))->CallIntMethod(p->env,
Modified: tomcat/connectors/trunk/jk/native/common/jk_lb_worker.c
URL:
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_lb_worker.c?rev=434177&r1=434176&r2=434177&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_lb_worker.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_lb_worker.c Wed Aug 23 14:02:24
2006
@@ -609,234 +609,239 @@
jk_ws_service_t *s,
jk_logger_t *l, int *is_error)
{
- JK_TRACE_ENTER(l);
+ lb_endpoint_t *p;
+ int attempt = 0;
+ int num_of_workers;
+ worker_record_t *prec = NULL;
- 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;
- worker_record_t *prec = NULL;
- /* Set returned error to OK */
- *is_error = JK_HTTP_OK;
-
- /* set the recovery post, for LB mode */
- s->reco_buf = jk_b_new(s->pool);
- jk_b_set_buffer_size(s->reco_buf, DEF_BUFFER_SZ);
- jk_b_reset(s->reco_buf);
- s->reco_status = RECO_INITED;
- if (JK_IS_DEBUG_LEVEL(l))
- jk_log(l, JK_LOG_DEBUG,
- "service sticky_session=%d",
- p->worker->s->sticky_session);
-
- while (num_of_workers) {
- worker_record_t *rec =
- get_most_suitable_worker(p->worker, s, attempt, l);
- int rc;
- /* Do not reuse previous worker, because
- * that worker already failed.
- */
- if (rec && rec != prec) {
- int is_service_error = JK_HTTP_OK;
- int service_stat = JK_FALSE;
- jk_endpoint_t *end = NULL;
-
- s->jvm_route = rec->r;
- rc = rec->w->get_endpoint(rec->w, &end, l);
-
- if (JK_IS_DEBUG_LEVEL(l))
- jk_log(l, JK_LOG_DEBUG,
- "service worker=%s jvm_route=%s",
- rec->s->name, s->jvm_route);
- if (rc && end) {
- size_t rd = 0;
- size_t wr = 0;
- /* Reset endpoint read and write sizes for
- * this request.
- */
- end->rd = end->wr = 0;
- if (p->worker->lblock == JK_LB_LOCK_PESSIMISTIC)
- jk_shm_lock();
+ JK_TRACE_ENTER(l);
- rec->s->elected++;
- /* Increment the number of workers serving request */
- p->worker->s->busy++;
- if (p->worker->s->busy > p->worker->s->max_busy)
- p->worker->s->max_busy = p->worker->s->busy;
- rec->s->busy++;
- if (p->worker->lbmethod == JK_LB_METHOD_REQUESTS)
- rec->s->lb_value += rec->s->lb_mult;
- else if (p->worker->lbmethod == JK_LB_METHOD_BUSYNESS)
- rec->s->lb_value += rec->s->lb_mult;
- if (rec->s->busy > rec->s->max_busy)
- rec->s->max_busy = rec->s->busy;
- if (p->worker->lblock == JK_LB_LOCK_PESSIMISTIC)
- jk_shm_unlock();
+ if (is_error)
+ *is_error = JK_HTTP_SERVER_ERROR;
+ if (!e || !e->endpoint_private || !s || !is_error) {
+ JK_LOG_NULL_PARAMS(l);
+ JK_TRACE_EXIT(l);
+ return JK_FALSE;
+ }
- service_stat = end->service(end, s, l, &is_service_error);
- rd = end->rd;
- wr = end->wr;
- end->done(&end, l);
+ p = e->endpoint_private;
+ num_of_workers = p->worker->num_of_workers;
- if (p->worker->lblock == JK_LB_LOCK_PESSIMISTIC)
- jk_shm_lock();
+ /* Set returned error to OK */
+ *is_error = JK_HTTP_OK;
- /* Update partial reads and writes if any */
- rec->s->readed += rd;
- rec->s->transferred += wr;
- if (p->worker->lbmethod == JK_LB_METHOD_TRAFFIC)
- rec->s->lb_value += (rd+wr)*rec->s->lb_mult;
- else if (p->worker->lbmethod == JK_LB_METHOD_BUSYNESS)
- if (rec->s->lb_value >= rec->s->lb_mult)
- rec->s->lb_value -= rec->s->lb_mult;
- else {
- rec->s->lb_value = 0;
- if (JK_IS_DEBUG_LEVEL(l)) {
- jk_log(l, JK_LOG_DEBUG,
- "worker %s has load value to low (%"
- JK_UINT64_T_FMT
- " < %"
- JK_UINT64_T_FMT
- ") ",
- "- correcting to 0",
- rec->s->name,
- rec->s->lb_value,
- rec->s->lb_mult);
- }
+ /* set the recovery post, for LB mode */
+ s->reco_buf = jk_b_new(s->pool);
+ jk_b_set_buffer_size(s->reco_buf, DEF_BUFFER_SZ);
+ jk_b_reset(s->reco_buf);
+ s->reco_status = RECO_INITED;
+ if (JK_IS_DEBUG_LEVEL(l))
+ jk_log(l, JK_LOG_DEBUG,
+ "service sticky_session=%d",
+ p->worker->s->sticky_session);
+
+ while (num_of_workers) {
+ worker_record_t *rec =
+ get_most_suitable_worker(p->worker, s, attempt, l);
+ int rc;
+ /* Do not reuse previous worker, because
+ * that worker already failed.
+ */
+ if (rec && rec != prec) {
+ int is_service_error = JK_HTTP_OK;
+ int service_stat = JK_FALSE;
+ jk_endpoint_t *end = NULL;
+
+ s->jvm_route = rec->r;
+ rc = rec->w->get_endpoint(rec->w, &end, l);
+
+ if (JK_IS_DEBUG_LEVEL(l))
+ jk_log(l, JK_LOG_DEBUG,
+ "service worker=%s jvm_route=%s",
+ rec->s->name, s->jvm_route);
+ if (rc && end) {
+ size_t rd = 0;
+ size_t wr = 0;
+ /* Reset endpoint read and write sizes for
+ * this request.
+ */
+ end->rd = end->wr = 0;
+ if (p->worker->lblock == JK_LB_LOCK_PESSIMISTIC)
+ jk_shm_lock();
+
+ rec->s->elected++;
+ /* Increment the number of workers serving request */
+ p->worker->s->busy++;
+ if (p->worker->s->busy > p->worker->s->max_busy)
+ p->worker->s->max_busy = p->worker->s->busy;
+ rec->s->busy++;
+ if (p->worker->lbmethod == JK_LB_METHOD_REQUESTS)
+ rec->s->lb_value += rec->s->lb_mult;
+ else if (p->worker->lbmethod == JK_LB_METHOD_BUSYNESS)
+ rec->s->lb_value += rec->s->lb_mult;
+ if (rec->s->busy > rec->s->max_busy)
+ rec->s->max_busy = rec->s->busy;
+ if (p->worker->lblock == JK_LB_LOCK_PESSIMISTIC)
+ jk_shm_unlock();
+
+ service_stat = end->service(end, s, l, &is_service_error);
+ rd = end->rd;
+ wr = end->wr;
+ end->done(&end, l);
+
+ if (p->worker->lblock == JK_LB_LOCK_PESSIMISTIC)
+ jk_shm_lock();
+
+ /* Update partial reads and writes if any */
+ rec->s->readed += rd;
+ rec->s->transferred += wr;
+ if (p->worker->lbmethod == JK_LB_METHOD_TRAFFIC)
+ rec->s->lb_value += (rd+wr)*rec->s->lb_mult;
+ else if (p->worker->lbmethod == JK_LB_METHOD_BUSYNESS)
+ if (rec->s->lb_value >= rec->s->lb_mult)
+ rec->s->lb_value -= rec->s->lb_mult;
+ else {
+ rec->s->lb_value = 0;
+ if (JK_IS_DEBUG_LEVEL(l)) {
+ jk_log(l, JK_LOG_DEBUG,
+ "worker %s has load value to low (%"
+ JK_UINT64_T_FMT
+ " < %"
+ JK_UINT64_T_FMT
+ ") ",
+ "- correcting to 0",
+ rec->s->name,
+ rec->s->lb_value,
+ rec->s->lb_mult);
}
-
- /* When returning the endpoint mark the worker as not busy.
- * We have at least one endpoint free
- */
- rec->s->is_busy = JK_FALSE;
- /* Decrement the busy worker count.
- * Check if the busy was reset to zero by graceful
- * restart of the server.
- */
- if (rec->s->busy)
- rec->s->busy--;
- if (p->worker->s->busy)
- p->worker->s->busy--;
- if (service_stat == JK_TRUE) {
- rec->s->in_error_state = JK_FALSE;
- rec->s->in_recovering = JK_FALSE;
- rec->s->error_time = 0;
- if (p->worker->lblock == JK_LB_LOCK_PESSIMISTIC)
- jk_shm_unlock();
- JK_TRACE_EXIT(l);
- return JK_TRUE;
}
+
+ /* When returning the endpoint mark the worker as not busy.
+ * We have at least one endpoint free
+ */
+ rec->s->is_busy = JK_FALSE;
+ /* Decrement the busy worker count.
+ * Check if the busy was reset to zero by graceful
+ * restart of the server.
+ */
+ if (rec->s->busy)
+ rec->s->busy--;
+ if (p->worker->s->busy)
+ p->worker->s->busy--;
+ if (service_stat == JK_TRUE) {
+ rec->s->in_error_state = JK_FALSE;
+ rec->s->in_recovering = JK_FALSE;
+ rec->s->error_time = 0;
if (p->worker->lblock == JK_LB_LOCK_PESSIMISTIC)
jk_shm_unlock();
+ JK_TRACE_EXIT(l);
+ return JK_TRUE;
}
- else {
- /* If we can not get the endpoint
- * mark the worker as busy rather then
- * as in error if the attemp number is
- * greater then the number of retries.
- */
- attempt++;
- if (attempt > p->worker->s->retries) {
- rec->s->is_busy = JK_TRUE;
- num_of_workers = 0;
- }
- jk_log(l, JK_LOG_INFO,
- "could not get free endpoint for worker %s (attempt
%d)",
- rec->s->name, attempt);
- /* In case of attempt > num of workers sleep for 100 ms
- * on each consequtive attempt.
- */
- if (attempt > (int)p->worker->num_of_workers)
- jk_sleep_def();
- continue;
+ if (p->worker->lblock == JK_LB_LOCK_PESSIMISTIC)
+ jk_shm_unlock();
+ }
+ else {
+ /* If we can not get the endpoint
+ * mark the worker as busy rather then
+ * as in error if the attemp number is
+ * greater then the number of retries.
+ */
+ attempt++;
+ if (attempt > p->worker->s->retries) {
+ rec->s->is_busy = JK_TRUE;
+ num_of_workers = 0;
}
- if (service_stat == JK_FALSE) {
- /*
- * 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(NULL);
+ jk_log(l, JK_LOG_INFO,
+ "could not get free endpoint for worker %s (attempt
%d)",
+ rec->s->name, attempt);
+ /* In case of attempt > num of workers sleep for 100 ms
+ * on each consequtive attempt.
+ */
+ if (attempt > (int)p->worker->num_of_workers)
+ jk_sleep_def();
+ continue;
+ }
+ if (service_stat == JK_FALSE) {
+ /*
+ * 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(NULL);
- if (is_service_error != JK_HTTP_SERVER_BUSY) {
- /*
- * 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;
- }
- jk_log(l, JK_LOG_INFO,
- "service failed, worker %s is in error state",
- rec->s->name);
- }
- else if (service_stat == JK_CLIENT_ERROR) {
+ if (is_service_error != JK_HTTP_SERVER_BUSY) {
/*
- * Clent error !!!
- * Since this is bad request do not fail over.
+ * Error is not recoverable - break with an error.
*/
- rec->s->errors++;
- rec->s->in_error_state = JK_FALSE;
- rec->s->in_recovering = JK_FALSE;
- rec->s->error_time = 0;
+ 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_log(l, JK_LOG_INFO,
- "unrecoverable error %d, request failed."
- " Client failed in the middle of request,"
- " we can't recover to another instance.",
- is_service_error);
JK_TRACE_EXIT(l);
- return JK_CLIENT_ERROR;
- }
- 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;
- */
+ return JK_FALSE;
}
+ jk_log(l, JK_LOG_INFO,
+ "service failed, worker %s is in error state",
+ rec->s->name);
+ }
+ else if (service_stat == JK_CLIENT_ERROR) {
/*
- * Error is recoverable by submitting the request to
- * another worker... Lets try to do that.
- */
- if (JK_IS_DEBUG_LEVEL(l))
- jk_log(l, JK_LOG_DEBUG,
- "recoverable error... will try to recover on other
host");
+ * Client error !!!
+ * Since this is bad request do not fail over.
+ */
+ rec->s->errors++;
+ rec->s->in_error_state = JK_FALSE;
+ rec->s->in_recovering = JK_FALSE;
+ rec->s->error_time = 0;
+ *is_error = is_service_error;
+
+ jk_log(l, JK_LOG_INFO,
+ "unrecoverable error %d, request failed."
+ " Client failed in the middle of request,"
+ " we can't recover to another instance.",
+ is_service_error);
+ JK_TRACE_EXIT(l);
+ return JK_CLIENT_ERROR;
}
-#if 0
else {
- /* NULL record, no more workers left ... */
- jk_log(l, JK_LOG_ERROR,
- "All tomcat instances failed, no more workers left");
- JK_TRACE_EXIT(l);
- *is_error = JK_HTTP_SERVER_BUSY;
- return JK_FALSE;
+ /* 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;
+ */
}
-#endif
- --num_of_workers;
- prec = rec;
+ /*
+ * Error is recoverable by submitting the request to
+ * another worker... Lets try to do that.
+ */
+ if (JK_IS_DEBUG_LEVEL(l))
+ jk_log(l, JK_LOG_DEBUG,
+ "recoverable error... will try to recover on other
host");
}
- jk_log(l, JK_LOG_INFO,
- "All tomcat instances are busy or in error state");
- JK_TRACE_EXIT(l);
- /* Set error to Timeout */
- *is_error = JK_HTTP_SERVER_BUSY;
- return JK_FALSE;
+#if 0
+ else {
+ /* NULL record, no more workers left ... */
+ jk_log(l, JK_LOG_ERROR,
+ "All tomcat instances failed, no more workers left");
+ JK_TRACE_EXIT(l);
+ *is_error = JK_HTTP_SERVER_BUSY;
+ return JK_FALSE;
+ }
+#endif
+ --num_of_workers;
+ prec = rec;
}
- if (is_error)
- *is_error = JK_HTTP_SERVER_ERROR;
- JK_LOG_NULL_PARAMS(l);
+ jk_log(l, JK_LOG_INFO,
+ "All tomcat instances are busy or in error state");
+ /* Set error to Timeout */
+ *is_error = JK_HTTP_SERVER_BUSY;
JK_TRACE_EXIT(l);
return JK_FALSE;
}
Modified: tomcat/connectors/trunk/jk/native/common/jk_status.c
URL:
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_status.c?rev=434177&r1=434176&r2=434177&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_status.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_status.c Wed Aug 23 14:02:24
2006
@@ -841,146 +841,148 @@
jk_ws_service_t *s,
jk_logger_t *l, int *is_recoverable_error)
{
- JK_TRACE_ENTER(l);
+ char buf[128];
+ char *worker = NULL;
+ int cmd;
+ int mime;
+ status_endpoint_t *p;
- if (e && e->endpoint_private && s) {
- char buf[128];
- char *worker = NULL;
- int cmd;
- int mime;
- status_endpoint_t *p = e->endpoint_private;
+ JK_TRACE_ENTER(l);
+ if (is_recoverable_error)
*is_recoverable_error = JK_FALSE;
+ if (!e || !e->endpoint_private || !s || !is_recoverable_error) {
+ JK_LOG_NULL_PARAMS(l);
+ JK_TRACE_EXIT(l);
+ return JK_FALSE;
+ }
- /* Step 1: Process GET params and update configuration */
- cmd = status_cmd_type(s->query_string);
- mime = status_mime_type(s->query_string);
- if (cmd > 0 && (status_cmd("w", s->query_string, buf, sizeof(buf)) !=
NULL))
- worker = strdup(buf);
- if ((cmd == 2) && worker) {
- /* lock shared memory */
- jk_shm_lock();
- update_worker(s, p->s_worker, worker, l);
- /* update modification time to reflect the current config */
- jk_shm_set_workers_time(time(NULL));
- /* Since we updated the config no need to reload
- * on the next request
- */
- jk_shm_sync_access_time();
- /* unlock the shared memory */
- jk_shm_unlock();
- }
- else if ((cmd == 3) && worker) {
- /* lock shared memory */
- jk_shm_lock();
- reset_worker(s, p->s_worker, worker, l);
- /* update modification time to reflect the current config */
- jk_shm_set_workers_time(time(NULL));
- /* Since we updated the config no need to reload
- * on the next request
- */
- jk_shm_sync_access_time();
- /* unlock the shared memory */
- jk_shm_unlock();
- }
- if (mime == 0) {
- int refresh = status_int("refresh", s->query_string, -1);
- s->start_response(s, 200, "OK", headers_names, headers_vhtml, 3);
- s->write(s, JK_STATUS_HEAD, sizeof(JK_STATUS_HEAD) - 1);
- if (cmd > 1) {
- jk_putv(s, "\n<meta http-equiv=\"Refresh\" content=\"0;url=",
- s->req_uri, "\">", NULL);
- }
- else if (cmd == 0 && refresh >= 0) {
- jk_printf(s, "\n<meta http-equiv=\"Refresh\"
content=\"%d;url=%s?%s\">",
- refresh, s->req_uri, s->query_string);
- }
- if (p->s_worker->css) {
- jk_putv(s, "\n<link rel=\"stylesheet\" type=\"text/css\"
href=\"",
- p->s_worker->css, "\" />\n", NULL);
- }
- s->write(s, JK_STATUS_HEND, sizeof(JK_STATUS_HEND) - 1);
- if ( cmd <= 1 ) {
- jk_puts(s, "<h1>JK Status Manager for ");
- jk_puts(s, s->server_name);
- jk_puts(s, "</h1>\n\n");
- jk_putv(s, "<dl><dt>Server Version:</dt><dd>",
- s->server_software, "</dd>\n", NULL);
- jk_putv(s, "<dt>JK Version:</dt><dd>",
- JK_VERSTRING, "\n</dd></dl>\n", NULL);
- }
- if ( cmd == 0 ) {
- jk_putv(s, "[<a href=\"", s->req_uri, NULL);
- if (refresh >= 0) {
- char *buf = jk_pool_alloc(s->pool, sizeof(char *) *
BIG_POOL_SIZE);
- const char *str = s->query_string;
- int result = 0;
- int scan = 0;
-
- while (str[scan] != 0) {
- if (strncmp(&str[scan], "refresh=", 8) == 0) {
- scan += 8;
- while (str[scan] != 0 && str[scan] != '&')
- scan++;
- if (str[scan] == '&')
- scan++;
+ p = e->endpoint_private;
+
+ /* Step 1: Process GET params and update configuration */
+ cmd = status_cmd_type(s->query_string);
+ mime = status_mime_type(s->query_string);
+ if (cmd > 0 && (status_cmd("w", s->query_string, buf, sizeof(buf)) !=
NULL))
+ worker = strdup(buf);
+ if ((cmd == 2) && worker) {
+ /* lock shared memory */
+ jk_shm_lock();
+ update_worker(s, p->s_worker, worker, l);
+ /* update modification time to reflect the current config */
+ jk_shm_set_workers_time(time(NULL));
+ /* Since we updated the config no need to reload
+ * on the next request
+ */
+ jk_shm_sync_access_time();
+ /* unlock the shared memory */
+ jk_shm_unlock();
+ }
+ else if ((cmd == 3) && worker) {
+ /* lock shared memory */
+ jk_shm_lock();
+ reset_worker(s, p->s_worker, worker, l);
+ /* update modification time to reflect the current config */
+ jk_shm_set_workers_time(time(NULL));
+ /* Since we updated the config no need to reload
+ * on the next request
+ */
+ jk_shm_sync_access_time();
+ /* unlock the shared memory */
+ jk_shm_unlock();
+ }
+ if (mime == 0) {
+ int refresh = status_int("refresh", s->query_string, -1);
+ s->start_response(s, 200, "OK", headers_names, headers_vhtml, 3);
+ s->write(s, JK_STATUS_HEAD, sizeof(JK_STATUS_HEAD) - 1);
+ if (cmd > 1) {
+ jk_putv(s, "\n<meta http-equiv=\"Refresh\" content=\"0;url=",
+ s->req_uri, "\">", NULL);
+ }
+ else if (cmd == 0 && refresh >= 0) {
+ jk_printf(s, "\n<meta http-equiv=\"Refresh\"
content=\"%d;url=%s?%s\">",
+ refresh, s->req_uri, s->query_string);
+ }
+ if (p->s_worker->css) {
+ jk_putv(s, "\n<link rel=\"stylesheet\" type=\"text/css\" href=\"",
+ p->s_worker->css, "\" />\n", NULL);
+ }
+ s->write(s, JK_STATUS_HEND, sizeof(JK_STATUS_HEND) - 1);
+ if ( cmd <= 1 ) {
+ jk_puts(s, "<h1>JK Status Manager for ");
+ jk_puts(s, s->server_name);
+ jk_puts(s, "</h1>\n\n");
+ jk_putv(s, "<dl><dt>Server Version:</dt><dd>",
+ s->server_software, "</dd>\n", NULL);
+ jk_putv(s, "<dt>JK Version:</dt><dd>",
+ JK_VERSTRING, "\n</dd></dl>\n", NULL);
+ }
+ if ( cmd == 0 ) {
+ jk_putv(s, "[<a href=\"", s->req_uri, NULL);
+ if (refresh >= 0) {
+ char *buf = jk_pool_alloc(s->pool, sizeof(char *) *
BIG_POOL_SIZE);
+ const char *str = s->query_string;
+ int result = 0;
+ int scan = 0;
+
+ while (str[scan] != 0) {
+ if (strncmp(&str[scan], "refresh=", 8) == 0) {
+ scan += 8;
+ while (str[scan] != 0 && str[scan] != '&')
+ scan++;
+ if (str[scan] == '&')
+ scan++;
+ }
+ else {
+ if (result > 0 && str[scan] != 0 && str[scan] != '&') {
+ buf[result] = '&';
+ result++;
}
- else {
- if (result > 0 && str[scan] != 0 && str[scan] !=
'&') {
- buf[result] = '&';
- result++;
- }
- while (str[scan] != 0 && str[scan] != '&') {
- buf[result] = str[scan];
- result++;
- scan++;
- }
- if (str[scan] == '&')
- scan++;
+ while (str[scan] != 0 && str[scan] != '&') {
+ buf[result] = str[scan];
+ result++;
+ scan++;
}
+ if (str[scan] == '&')
+ scan++;
}
- buf[result] = 0;
-
- if (buf && buf[0])
- jk_putv(s, "?", buf, NULL);
- jk_puts(s, "\">stop");
- }
- else {
- jk_puts(s, "?");
- if (s->query_string && s->query_string[0])
- jk_putv(s, s->query_string, "&", NULL);
- jk_puts(s, "refresh=10\">start");
}
- jk_puts(s, " auto update</a>]");
- }
- if ( cmd <= 1 ) {
- /* Step 2: Display configuration */
- display_workers(s, p->s_worker, worker, l);
+ buf[result] = 0;
+
+ if (buf && buf[0])
+ jk_putv(s, "?", buf, NULL);
+ jk_puts(s, "\">stop");
+ }
+ else {
+ jk_puts(s, "?");
+ if (s->query_string && s->query_string[0])
+ jk_putv(s, s->query_string, "&", NULL);
+ jk_puts(s, "refresh=10\">start");
}
-
- s->write(s, JK_STATUS_BEND, sizeof(JK_STATUS_BEND) - 1);
-
- }
- else if (mime == 1) {
- s->start_response(s, 200, "OK", headers_names, headers_vxml, 3);
- s->write(s, JK_STATUS_XMLH, sizeof(JK_STATUS_XMLH) - 1);
- dump_config(s, p->s_worker, l);
- s->write(s, JK_STATUS_XMLE, sizeof(JK_STATUS_XMLE) - 1);
- }
- else {
- s->start_response(s, 200, "OK", headers_names, headers_vtxt, 3);
- s->write(s, JK_STATUS_TEXTUPDATE_RESPONCE,
- sizeof(JK_STATUS_TEXTUPDATE_RESPONCE) - 1);
+ jk_puts(s, " auto update</a>]");
}
- if (worker)
- free(worker);
- JK_TRACE_EXIT(l);
- return JK_TRUE;
- }
+ if ( cmd <= 1 ) {
+ /* Step 2: Display configuration */
+ display_workers(s, p->s_worker, worker, l);
+ }
+
+ s->write(s, JK_STATUS_BEND, sizeof(JK_STATUS_BEND) - 1);
- jk_log(l, JK_LOG_ERROR, "status: end of service with error");
+ }
+ else if (mime == 1) {
+ s->start_response(s, 200, "OK", headers_names, headers_vxml, 3);
+ s->write(s, JK_STATUS_XMLH, sizeof(JK_STATUS_XMLH) - 1);
+ dump_config(s, p->s_worker, l);
+ s->write(s, JK_STATUS_XMLE, sizeof(JK_STATUS_XMLE) - 1);
+ }
+ else {
+ s->start_response(s, 200, "OK", headers_names, headers_vtxt, 3);
+ s->write(s, JK_STATUS_TEXTUPDATE_RESPONCE,
+ sizeof(JK_STATUS_TEXTUPDATE_RESPONCE) - 1);
+ }
+ if (worker)
+ free(worker);
JK_TRACE_EXIT(l);
- return JK_FALSE;
+ return JK_TRUE;
}
static int JK_METHOD done(jk_endpoint_t **e, jk_logger_t *l)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]