Author: jfrederic.clere(a)jboss.com
Date: 2009-03-05 10:03:40 -0500 (Thu, 05 Mar 2009)
New Revision: 2337
Modified:
trunk/mod_cluster/native/include/mod_proxy_cluster.h
trunk/mod_cluster/native/mod_manager/mod_manager.c
trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
Log:
Use mod_proxy logic instead ours.
Modified: trunk/mod_cluster/native/include/mod_proxy_cluster.h
===================================================================
--- trunk/mod_cluster/native/include/mod_proxy_cluster.h 2009-03-05 11:06:23 UTC (rev
2336)
+++ trunk/mod_cluster/native/include/mod_proxy_cluster.h 2009-03-05 15:03:40 UTC (rev
2337)
@@ -39,10 +39,9 @@
* @param r request_rec structure.
* @param id ident of the worker.
* @param load load factor to set if test is ok.
- * @param scheme AJP/http/https protocol to use.
* @return 0: All OK 500 : Error
*/
-int (* proxy_node_isup)(request_rec *r, int id, char *scheme, int load);
+int (* proxy_node_isup)(request_rec *r, int id, int load);
};
typedef struct balancer_method balancer_method;
#endif /*MOD_PROXY_CLUSTER_H*/
Modified: trunk/mod_cluster/native/mod_manager/mod_manager.c
===================================================================
--- trunk/mod_cluster/native/mod_manager/mod_manager.c 2009-03-05 11:06:23 UTC (rev 2336)
+++ trunk/mod_cluster/native/mod_manager/mod_manager.c 2009-03-05 15:03:40 UTC (rev 2337)
@@ -1172,10 +1172,10 @@
* Call the ping/pong logic
* Do a ping/png request to the node and set the load factor.
*/
-static int isnode_up(request_rec *r, int id, char *scheme, int Load)
+static int isnode_up(request_rec *r, int id, int Load)
{
if (balancerhandler != NULL) {
- return (balancerhandler->proxy_node_isup(r, id, scheme, Load));
+ return (balancerhandler->proxy_node_isup(r, id, Load));
}
return OK;
}
@@ -1233,7 +1233,7 @@
ap_set_content_type(r, "text/plain");
ap_rprintf(r, "Type=STATUS-RSP&JVMRoute=%s", nodeinfo.mess.JVMRoute);
- if (isnode_up(r, node->mess.id, node->mess.Type, Load) != OK)
+ if (isnode_up(r, node->mess.id, Load) != OK)
ap_rprintf(r, "&State=NOTOK");
else
ap_rprintf(r, "&State=OK");
Modified: trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
===================================================================
--- trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2009-03-05 11:06:23 UTC
(rev 2336)
+++ trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2009-03-05 15:03:40 UTC
(rev 2337)
@@ -135,67 +135,8 @@
}
#endif
-/* connection cleanup routine */
/* XXX: Should use the proxy_util one. */
-static apr_status_t connection_cleanup(void *theconn)
-{
- proxy_conn_rec *conn = (proxy_conn_rec *)theconn;
- proxy_worker *worker = conn->worker;
-
- /*
- * If the connection pool is NULL the worker
- * cleanup has been run. Just return.
- */
- if (!worker->cp) {
- return APR_SUCCESS;
- }
-
#if APR_HAS_THREADS
- /* Sanity check: Did we already return the pooled connection? */
- if (conn->inreslist) {
- ap_log_perror(APLOG_MARK, APLOG_ERR, 0, conn->pool,
- "proxy: Pooled connection 0x%pp for worker %s has been"
- " already returned to the connection pool.",
- (void *) conn,
- worker->name);
- return APR_SUCCESS;
- }
-#endif
-
- /* determine if the connection need to be closed */
-#if MODULE_MAGIC_NUMBER_MAJOR>=20080722
- if (conn->close)
-#else
- if (conn->close_on_recycle || conn->close)
-#endif
- {
- apr_pool_t *p = conn->pool;
- apr_pool_clear(p);
- conn = apr_pcalloc(p, sizeof(proxy_conn_rec));
- conn->pool = p;
- conn->worker = worker;
-#if AP_MODULE_MAGIC_AT_LEAST(20051115,13)
- apr_pool_create(&(conn->scpool), p);
- apr_pool_tag(conn->scpool, "proxy_conn_scpool");
-#endif
- }
-#if APR_HAS_THREADS
- if (worker->hmax && worker->cp->res) {
- conn->inreslist = 1;
- apr_reslist_release(worker->cp->res, (void *)conn);
- }
- else
-#endif
- {
- worker->cp->conn = conn;
- }
-
- /* Always return the SUCCESS */
- return APR_SUCCESS;
-}
-
-/* XXX: Should use the proxy_util one. */
-#if APR_HAS_THREADS
static apr_status_t conn_pool_cleanup(void *theworker)
{
proxy_worker *worker = (proxy_worker *)theworker;
@@ -1120,10 +1061,9 @@
"ajp_cping_cpong: Done");
return status;
}
-static apr_status_t proxy_cluster_try_pingpong(request_rec *r, proxy_worker *worker, char
*scheme)
+static apr_status_t proxy_cluster_try_pingpong(request_rec *r, proxy_worker *worker, char
*url, proxy_server_conf *conf)
{
- apr_status_t rv;
- proxy_conn_rec *conn;
+ apr_status_t status;
apr_interval_time_t timeout;
apr_interval_time_t savetimeout;
char savetimeout_set;
@@ -1131,73 +1071,30 @@
#else
proxy_cluster_helper *helperping;
#endif
- /* get the proxy_conn_rec: from ap_proxy_acquire_connection */
-#if APR_HAS_THREADS
- /* prefork() is not "safe" as we have now 2 threads... */
- if (worker->hmax && worker->cp->res) {
- rv = apr_reslist_acquire(worker->cp->res, (void **)&conn);
- }
- else
-#endif
- {
- /* create the new connection if the previous was destroyed */
- rv = APR_SUCCESS;
- if (!worker->cp->conn) {
- /* XXX: What appends is worker->cp->pool is NULL */
- if (worker->cp->pool) {
- connection_constructor((void **)&conn, worker,
worker->cp->pool);
- } else
- rv = APR_ENOPOOL;
- }
- else {
- conn = worker->cp->conn;
- worker->cp->conn = NULL;
- }
- }
+ proxy_conn_rec *backend = NULL;
+ char server_portstr[32];
+ char *locurl = url;
+ apr_uri_t *uri;
- if (rv != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
- "proxy_cluster_try_pingpong: failed acquiring
connection");
- if (conn) {
- conn->close = 1;
- ap_proxy_release_connection(scheme, conn, r->server);
+ /* create space for state information */
+ status = ap_proxy_acquire_connection(worker->scheme, &backend, worker,
r->server);
+ if (status != OK) {
+ if (backend) {
+ backend->close_on_recycle = 1;
+ ap_proxy_release_connection(worker->scheme, backend, r->server);
}
- return rv;
+ return status;
}
- conn->worker = worker;
- conn->close = 0;
-#if APR_HAS_THREADS
- conn->inreslist = 0;
-#endif
-
- /* Replace ap_proxy_determine_connection XXX: Still not ok */
- if (!conn->hostname) {
- conn->hostname = apr_pstrdup(conn->pool, worker->hostname);
- conn->port = worker->port;
- ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
- "proxy_cluster_try_pingpong: connection to %s : %d",
- conn->hostname, conn->port);
-
- if (conn->sock) {
- apr_socket_close(conn->sock);
- conn->sock = NULL;
- }
- if (conn->connection) {
- apr_pool_cleanup_kill(conn->connection->pool, conn,
connection_cleanup);
- conn->connection = NULL;
- }
- rv = apr_sockaddr_info_get(&(conn->addr),
- conn->hostname, APR_UNSPEC,
- conn->port, 0,
- conn->pool);
- if (rv != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
- "proxy_cluster_try_pingpong: can't resolve %s",
- conn->hostname);
- ap_proxy_release_connection(scheme, conn, r->server);
- return rv;
- }
+ /* Step One: Determine Who To Connect To */
+ uri = apr_palloc(r->pool, sizeof(*uri)); /* We don't use it anyway */
+ status = ap_proxy_determine_connection(r->pool, r, conf, worker, backend,
+ uri, &locurl, worker->hostname,
worker->port,
+ server_portstr,
+ sizeof(server_portstr));
+ if (status != OK) {
+ ap_proxy_release_connection(worker->scheme, backend, r->server);
+ return status;
}
/* Set the timeout: Note that the default timeout logic in the proxy_util.c is:
@@ -1220,36 +1117,36 @@
worker->timeout_set = 1;
worker->timeout = timeout;
- /* Connect to the backend: Check connected/reuse otherwise create new */
- rv = ap_proxy_connect_backend(scheme, conn, worker, r->server);
+ /* Step Two: Make the Connection */
+ status = ap_proxy_connect_backend(worker->scheme, backend, worker, r->server);
worker->timeout_set = savetimeout_set;
worker->timeout = savetimeout;
- if (rv != APR_SUCCESS) {
+ if (status != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
"proxy_cluster_try_pingpong: can't connect to
backend");
- ap_proxy_release_connection(scheme, conn, r->server);
- return rv;
+ ap_proxy_release_connection(worker->scheme, backend, r->server);
+ return status;
}
/* XXX: For the moment we support only AJP */
- if (strcasecmp(scheme, "AJP") == 0) {
- rv = ajp_handle_cping_cpong(conn->sock, r, timeout);
- if (rv != APR_SUCCESS) {
+ if (strcasecmp(worker->scheme, "AJP") == 0) {
+ status = ajp_handle_cping_cpong(backend->sock, r, timeout);
+ if (status != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
"proxy_cluster_try_pingpong: cping_cpong failed");
- conn->close++;
+ backend->close++;
}
}
- ap_proxy_release_connection(scheme, conn, r->server);
- return rv;
+ ap_proxy_release_connection(worker->scheme, backend, r->server);
+ return status;
}
/*
* Check that we could connect to the node
* id : worker id
* load : load factor from the cluster manager.
*/
-static int proxy_node_isup(request_rec *r, int id, char *scheme, int load)
+static int proxy_node_isup(request_rec *r, int id, int load)
{
void *sconf = r->server->module_config;
proxy_server_conf *conf = (proxy_server_conf *)
@@ -1277,7 +1174,11 @@
/* Try a ping/pong to check the node */
if (load > 0) {
/* Only try usuable nodes */
- rv = proxy_cluster_try_pingpong(r, worker, scheme);
+ char sport[7];
+ char *url;
+ apr_snprintf(sport, sizeof(sport), ":%d", worker->port);
+ url = apr_pstrcat(r->pool, worker->scheme, "ajp://",
worker->hostname, sport, "/", NULL);
+ rv = proxy_cluster_try_pingpong(r, worker, url, conf);
if (rv != APR_SUCCESS) {
worker->s->status |= PROXY_WORKER_IN_ERROR;
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,