| 471 | } |
| 472 | |
| 473 | static int proxy_balancer_pre_request(proxy_worker **worker, |
| 474 | proxy_balancer **balancer, |
| 475 | request_rec *r, |
| 476 | proxy_server_conf *conf, char **url) |
| 477 | { |
| 478 | int access_status; |
| 479 | proxy_worker *runtime; |
| 480 | char *route = NULL; |
| 481 | const char *sticky = NULL; |
| 482 | apr_status_t rv; |
| 483 | |
| 484 | *worker = NULL; |
| 485 | /* Step 1: check if the url is for us |
| 486 | * The url we can handle starts with 'balancer://' |
| 487 | * If balancer is already provided skip the search |
| 488 | * for balancer, because this is failover attempt. |
| 489 | */ |
| 490 | if (!*balancer && |
| 491 | (ap_cstr_casecmpn(*url, BALANCER_PREFIX, sizeof(BALANCER_PREFIX) - 1) |
| 492 | || !(*balancer = ap_proxy_get_balancer(r->pool, conf, *url, 1)))) |
| 493 | return DECLINED; |
| 494 | |
| 495 | /* Step 2: Lock the LoadBalancer |
| 496 | * XXX: perhaps we need the process lock here |
| 497 | */ |
| 498 | #if APR_HAS_THREADS |
| 499 | if ((rv = PROXY_THREAD_LOCK(*balancer)) != APR_SUCCESS) { |
| 500 | ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01166) |
| 501 | "%s: Lock failed for pre_request", (*balancer)->s->name); |
| 502 | return DECLINED; |
| 503 | } |
| 504 | #endif |
| 505 | |
| 506 | /* Step 3: force recovery */ |
| 507 | force_recovery(*balancer, r->server); |
| 508 | |
| 509 | /* Step 3.5: Update member list for the balancer */ |
| 510 | /* TODO: Implement as provider! */ |
| 511 | ap_proxy_sync_balancer(*balancer, r->server, conf); |
| 512 | |
| 513 | /* Step 4: find the session route */ |
| 514 | runtime = find_session_route(*balancer, r, &route, &sticky, url); |
| 515 | if (runtime) { |
| 516 | if ((*balancer)->lbmethod && (*balancer)->lbmethod->updatelbstatus) { |
| 517 | /* Call the LB implementation */ |
| 518 | (*balancer)->lbmethod->updatelbstatus(*balancer, runtime, r->server); |
| 519 | } |
| 520 | else { /* Use the default one */ |
| 521 | int i, total_factor = 0; |
| 522 | proxy_worker **workers; |
| 523 | /* We have a sticky load balancer |
| 524 | * Update the workers status |
| 525 | * so that even session routes get |
| 526 | * into account. |
| 527 | */ |
| 528 | workers = (proxy_worker **)(*balancer)->workers->elts; |
| 529 | for (i = 0; i < (*balancer)->workers->nelts; i++) { |
| 530 | /* Take into calculation only the workers that are |
nothing calls this directly
no test coverage detected