Whenever monitored server's state changes, a callback, router_handle_state_switch is called for each DCB in MaxScale session. The DCB referring to the server in question will be passed as parameter to backend DCB's hangup function.

The logic that solves the situation is not in place yet.
This commit is contained in:
VilhoRaatikka 2014-06-13 13:30:50 +03:00
parent 9eda859724
commit dfc9141a38
4 changed files with 63 additions and 45 deletions

View File

@ -1727,3 +1727,37 @@ int rval = 0;
return rval;
}
void dcb_call_foreach (
SERVER* srv,
DCB_REASON reason)
{
switch (reason) {
case DCB_REASON_CLOSE:
case DCB_REASON_DRAINED:
case DCB_REASON_HIGH_WATER:
case DCB_REASON_LOW_WATER:
case DCB_REASON_ERROR:
case DCB_REASON_HUP:
case DCB_REASON_NOT_RESPONDING:
{
DCB* dcb;
spinlock_acquire(&dcbspin);
dcb = allDCBs;
while (dcb)
{
dcb_call_callback(dcb, DCB_REASON_NOT_RESPONDING);
dcb = dcb->next;
}
spinlock_release(&dcbspin);
break;
}
default:
break;
}
return;
}

View File

@ -35,7 +35,7 @@ typedef enum bref_state {
BREF_NOT_USED = 0x00,
BREF_IN_USE = 0x01,
BREF_WAITING_RESULT = 0x02, /*< for anything that responds */
BREF_CLOSED = 0x08
BREF_CLOSED = 0x04
} bref_state_t;
#define BREF_IS_NOT_USED(s) (s->bref_state & BREF_NOT_USED)

View File

@ -692,6 +692,11 @@ MONITOR_SERVERS *ptr;
{
monitorDatabase(handle, ptr);
if (mon_status_changed(ptr))
{
dcb_call_foreach(ptr->server, DCB_REASON_NOT_RESPONDING);
}
if (mon_status_changed(ptr) ||
mon_print_fail_status(ptr))
{
@ -700,7 +705,7 @@ MONITOR_SERVERS *ptr;
"Backend server %s:%d state : %s",
ptr->server->name,
ptr->server->port,
STRSRVSTATUS(ptr->server))));
STRSRVSTATUS(ptr->server))));
}
if (SERVER_IS_DOWN(ptr->server))
{

View File

@ -224,8 +224,7 @@ static void refreshInstance(
static void bref_clear_state(backend_ref_t* bref, bref_state_t state);
static void bref_set_state(backend_ref_t* bref, bref_state_t state);
static int router_handle_not_responding(DCB* dcb, DCB_REASON reason, void* data);
static void hangup_server_connections (ROUTER_INSTANCE* inst);
static int router_handle_state_switch(DCB* dcb, DCB_REASON reason, void* data);
static SPINLOCK instlock;
static ROUTER_INSTANCE* instances;
@ -1596,14 +1595,14 @@ static bool select_connect_backend_servers(
session,
b->backend_server->protocol);
if (backend_ref[i].bref_dcb != NULL)
if (backend_ref[i].bref_dcb != NULL)
{
slaves_connected += 1;
dcb_add_callback(
backend_ref[i].bref_dcb,
DCB_REASON_NOT_RESPONDING,
&router_handle_not_responding,
NULL);
&router_handle_state_switch,
(void *)&backend_ref[i]);
bref_clear_state(&backend_ref[i],
BREF_NOT_USED);
bref_set_state(&backend_ref[i],
@ -2745,56 +2744,36 @@ static backend_ref_t* get_bref_from_dcb(
return bref;
}
static int router_handle_not_responding(
static int router_handle_state_switch(
DCB* dcb,
DCB_REASON reason,
void* data)
{
ROUTER_INSTANCE* inst;
backend_ref_t* bref;
int rc = 1;
CHK_DCB(dcb);
CHK_SESSION(dcb->session);
inst = dcb->session->service->router_instance;
bref = (backend_ref_t *)data;
CHK_BACKEND_REF(bref);
if (bref->bref_dcb != dcb)
{
goto return_rc;
}
switch (reason) {
case DCB_REASON_NOT_RESPONDING:
hangup_server_connections(inst);
if (BREF_IS_WAITING_RESULT(bref))
{
printf("foo");
dcb->func.hangup(dcb);
}
break;
default:
break;
}
return 1;
return_rc:
return rc;
}
static void hangup_server_connections (
ROUTER_INSTANCE* inst)
{
ROUTER_CLIENT_SES* rses;
SERVER* fail_server;
rses = inst->connections;
while (rses != NULL)
{
backend_ref_t* bref;
CHK_CLIENT_RSES(rses);
bref = rses->rses_backend_ref;
while (bref != NULL)
{
CHK_BACKEND_REF(bref);
CHK_BACKEND(bref->bref_backend);
if (bref->bref_backend->backend_server == fail_server &&
BREF_IS_WAITING_RESPONSE(bref))
{
bref->bref_dcb->func.hangup;
}
bref ++;
}
rses = rses->next;
}
}