1
0
mirror of https://github.com/apache/httpd.git synced 2025-08-08 15:02:10 +03:00

Allow for searching w/i shm slots for a specific worker and balancer

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1421953 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jim Jagielski
2012-12-14 16:14:06 +00:00
parent ae3f320786
commit 74708ea8f3
4 changed files with 103 additions and 16 deletions

View File

@@ -1 +1 @@
2408 2410

View File

@@ -705,6 +705,32 @@ PROXY_DECLARE(apr_status_t) ap_proxy_initialize_balancer(proxy_balancer *balance
server_rec *s, server_rec *s,
apr_pool_t *p); apr_pool_t *p);
/**
* Find the shm of the worker as needed
* @param storage slotmem provider
* @param slot slotmem instance
* @param worker worker to find
* @param index pointer to index within slotmem of worker
* @return pointer to shm of worker, or NULL
*/
PROXY_DECLARE(proxy_worker_shared *) ap_proxy_find_workershm(ap_slotmem_provider_t *storage,
ap_slotmem_instance_t *slot,
proxy_worker *worker,
unsigned int *index);
/**
* Find the shm of the balancer as needed
* @param storage slotmem provider
* @param slot slotmem instance
* @param worker worker to find
* @param index pointer to index within slotmem of balancer
* @return pointer to shm of balancer, or NULL
*/
PROXY_DECLARE(proxy_balancer_shared *) ap_proxy_find_balancershm(ap_slotmem_provider_t *storage,
ap_slotmem_instance_t *slot,
proxy_balancer *balancer,
unsigned int *index);
/** /**
* Get the most suitable worker and/or balancer for the request * Get the most suitable worker and/or balancer for the request
* @param worker worker used for processing request * @param worker worker used for processing request

View File

@@ -797,6 +797,7 @@ static int balancer_post_config(apr_pool_t *pconf, apr_pool_t *plog,
proxy_worker *worker; proxy_worker *worker;
proxy_balancer_shared *bshm; proxy_balancer_shared *bshm;
const char *sname; const char *sname;
unsigned int index;
/* now that we have the right id, we need to redo the sname field */ /* now that we have the right id, we need to redo the sname field */
ap_pstr2_alnum(pconf, balancer->s->name + sizeof(BALANCER_PREFIX) - 1, ap_pstr2_alnum(pconf, balancer->s->name + sizeof(BALANCER_PREFIX) - 1,
@@ -820,16 +821,24 @@ static int balancer_post_config(apr_pool_t *pconf, apr_pool_t *plog,
apr_pool_cleanup_null); apr_pool_cleanup_null);
/* setup shm for balancers */ /* setup shm for balancers */
if ((rv = storage->fgrab(conf->bslot, i)) != APR_SUCCESS) { bshm = ap_proxy_find_balancershm(storage, conf->bslot, balancer, &index);
if (bshm) {
if ((rv = storage->fgrab(conf->bslot, index)) != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(02408) "balancer slotmem_fgrab failed");
return !OK;
}
}
else {
if ((rv = storage->grab(conf->bslot, &index)) != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01181) "balancer slotmem_grab failed"); ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01181) "balancer slotmem_grab failed");
return !OK; return !OK;
} }
if ((rv = storage->dptr(conf->bslot, i, (void *)&bshm)) != APR_SUCCESS) { if ((rv = storage->dptr(conf->bslot, index, (void *)&bshm)) != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01182) "balancer slotmem_dptr failed"); ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01182) "balancer slotmem_dptr failed");
return !OK; return !OK;
} }
if ((rv = ap_proxy_share_balancer(balancer, bshm, i)) != APR_SUCCESS) { }
if ((rv = ap_proxy_share_balancer(balancer, bshm, index)) != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01183) "Cannot share balancer"); ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01183) "Cannot share balancer");
return !OK; return !OK;
} }
@@ -859,16 +868,26 @@ static int balancer_post_config(apr_pool_t *pconf, apr_pool_t *plog,
proxy_worker_shared *shm; proxy_worker_shared *shm;
worker = *workers; worker = *workers;
if ((rv = storage->fgrab(balancer->wslot, j)) != APR_SUCCESS) {
shm = ap_proxy_find_workershm(storage, balancer->wslot, worker, &index);
if (shm) {
if ((rv = storage->fgrab(balancer->wslot, index)) != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(02409) "worker slotmem_fgrab failed");
return !OK;
}
}
else {
if ((rv = storage->grab(balancer->wslot, &index)) != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01186) "worker slotmem_grab failed"); ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01186) "worker slotmem_grab failed");
return !OK; return !OK;
} }
if ((rv = storage->dptr(balancer->wslot, j, (void *)&shm)) != APR_SUCCESS) { if ((rv = storage->dptr(balancer->wslot, index, (void *)&shm)) != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01187) "worker slotmem_dptr failed"); ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01187) "worker slotmem_dptr failed");
return !OK; return !OK;
} }
if ((rv = ap_proxy_share_worker(worker, shm, j)) != APR_SUCCESS) { }
if ((rv = ap_proxy_share_worker(worker, shm, index)) != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01188) "Cannot share worker"); ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01188) "Cannot share worker");
return !OK; return !OK;
} }

View File

@@ -2779,6 +2779,48 @@ PROXY_DECLARE(apr_status_t) ap_proxy_sync_balancer(proxy_balancer *b, server_rec
return APR_SUCCESS; return APR_SUCCESS;
} }
PROXY_DECLARE(proxy_worker_shared *) ap_proxy_find_workershm(ap_slotmem_provider_t *storage,
ap_slotmem_instance_t *slot,
proxy_worker *worker,
unsigned int *index)
{
proxy_worker_shared *shm;
unsigned int i, limit;
limit = storage->num_slots(slot);
for (i = 0; i < limit; i++) {
if (storage->dptr(slot, i, (void *)&shm) != APR_SUCCESS) {
return NULL;
}
if ((worker->s->hash.def == shm->hash.def) &&
(worker->s->hash.fnv == shm->hash.fnv)) {
*index = i;
return shm;
}
}
return NULL;
}
PROXY_DECLARE(proxy_balancer_shared *) ap_proxy_find_balancershm(ap_slotmem_provider_t *storage,
ap_slotmem_instance_t *slot,
proxy_balancer *balancer,
unsigned int *index)
{
proxy_balancer_shared *shm;
unsigned int i, limit;
limit = storage->num_slots(slot);
for (i = 0; i < limit; i++) {
if (storage->dptr(slot, i, (void *)&shm) != APR_SUCCESS) {
return NULL;
}
if ((balancer->s->hash.def == shm->hash.def) &&
(balancer->s->hash.fnv == shm->hash.fnv)) {
*index = i;
return shm;
}
}
return NULL;
}
void proxy_util_register_hooks(apr_pool_t *p) void proxy_util_register_hooks(apr_pool_t *p)
{ {
APR_REGISTER_OPTIONAL_FN(ap_proxy_retry_worker); APR_REGISTER_OPTIONAL_FN(ap_proxy_retry_worker);