mod_lbmethod_heartbeat.c revision 36ef8f77bffe75d1aa327882be1b5bdbe2ff567a
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mod_proxy.h"
#include "scoreboard.h"
#include "ap_mpm.h"
#include "apr_version.h"
#include "apr_hooks.h"
#include "ap_slotmem.h"
#include "heartbeat.h"
#ifndef LBM_HEARTBEAT_MAX_LASTSEEN
/* If we haven't seen a heartbeat in the last N seconds, don't count this IP
* as allive.
*/
#define LBM_HEARTBEAT_MAX_LASTSEEN (10)
#endif
/*
* configuration structure
* path: path of the file where the heartbeat information is stored.
*/
typedef struct lb_hb_ctx_t
{
const char *path;
} lb_hb_ctx_t;
typedef struct hb_server_t {
const char *ip;
int busy;
int ready;
int port;
int id;
} hb_server_t;
typedef struct ctx_servers {
static void
{
char *key;
char *value;
char *strtok_state;
while (key) {
if (value) {
value++; /* Skip passed the = */
}
else {
value = "1";
}
/*
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
"Found query arg: %s = %s", key, value);
*/
}
}
{
apr_file_t *fp;
if (!path) {
return APR_SUCCESS;
}
if (rv) {
return rv;
}
if (rv) {
return rv;
}
{
char *t;
int lineno = 0;
do {
char buf[4096];
const char *ip;
if (APR_BRIGADE_EMPTY(bb)) {
break;
}
APR_BLOCK_READ, sizeof(buf));
lineno++;
if (rv) {
return rv;
}
if (bsize == 0) {
break;
}
/* comment */
if (buf[0] == '#') {
continue;
}
/* line format: <IP> <query_string>\n */
if (!t) {
continue;
}
t++;
}
}
}
}
}
/* Server has zero threads active, but lots of them ready,
* it likely just started up, so lets /4 the number ready,
* to prevent us from completely flooding it with all new
* requests.
*/
}
} while (1);
}
return APR_SUCCESS;
}
{
}
}
return APR_SUCCESS;
}
{
return APR_SUCCESS;
}
{
if (hm_serversmem) {
} else
return rv;
}
/*
* Finding a random number in a range.
* n' = a + n(b-a+1)/(M+1)
* where:
* n' = random number in range
* a = low end of range
* b = high end of range
* n = random number of 0..M
* M = maxint
* Algorithm 'borrowed' from PHP's rand() function.
*/
{
if (rv) {
return rv;
}
return APR_SUCCESS;
}
request_rec *r)
{
int i;
apr_uint32_t openslots = 0;
lb_hb_ctx_t *ctx =
if (rv) {
"lb_heartbeat: Unable to read heartbeats at '%s'",
return NULL;
}
if (!server) {
continue;
}
if (!PROXY_WORKER_IS_USABLE(*worker)) {
}
if (PROXY_WORKER_IS_USABLE(*worker)) {
}
}
}
if (openslots > 0) {
apr_uint32_t c = 0;
apr_uint32_t pick = 0;
if (rv) {
"lb_heartbeat: failed picking a random number. how random.");
return NULL;
}
for (i = 0; i < up_servers->nelts; i++) {
}
}
}
return mycandidate;
}
return APR_SUCCESS;
}
return APR_SUCCESS;
}
static const proxy_balancer_method heartbeat =
{
"heartbeat",
NULL,
&reset,
&age
};
{
const char *userdata_key = "mod_lbmethod_heartbeat_init";
void *data;
unsigned int num;
if (!data) {
/* first call do nothing */
return OK;
}
if (!storage) {
ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, s, "ap_lookup_provider %s failed", AP_SLOTMEM_PROVIDER_GROUP);
return OK;
}
/* Try to use a slotmem created by mod_heartmonitor */
if (!hm_serversmem) {
} else
if (hm_serversmem)
return OK;
}
static void register_hooks(apr_pool_t *p)
{
}
{
return ctx;
}
{
}
else {
}
return ps;
}
{
lb_hb_ctx_t *ctx =
return err;
}
return NULL;
}
static const command_rec cmds[] = {
"Path to read heartbeat data."),
{NULL}
};
NULL, /* create per-directory config structure */
NULL, /* merge per-directory config structures */
lb_hb_create_config, /* create per-server config structure */
lb_hb_merge_config, /* merge per-server config structures */
cmds, /* command apr_table_t */
register_hooks /* register hooks */
};