Fixes, tidying up, etc.

This commit is contained in:
counterpoint
2015-06-03 12:03:00 +01:00
parent 6e803c647b
commit cb7eb5848b

View File

@ -84,7 +84,7 @@ static SPINLOCK dcbspin = SPINLOCK_INIT;
static SPINLOCK zombiespin = SPINLOCK_INIT; static SPINLOCK zombiespin = SPINLOCK_INIT;
static void dcb_final_free(DCB *dcb); static void dcb_final_free(DCB *dcb);
static bool dcb_set_state_nomutex( static bool dcb_set_state_nolock(
DCB* dcb, DCB* dcb,
const dcb_state_t new_state, const dcb_state_t new_state,
dcb_state_t* old_state); dcb_state_t* old_state);
@ -1319,8 +1319,9 @@ dcb_close(DCB *dcb)
char *user; char *user;
user = session_getUser(dcb->session); user = session_getUser(dcb->session);
if (!rc if (0 == rc
&& user && user
&& strlen(user)
&& dcb->server && dcb->server
&& dcb->server->persistpoolmax && dcb->server->persistpoolmax
&& dcb_persistent_clean_count(dcb) < dcb->server->persistpoolmax) && dcb_persistent_clean_count(dcb) < dcb->server->persistpoolmax)
@ -1676,6 +1677,8 @@ gw_dcb_state2string (int state) {
return "DCB Allocated"; return "DCB Allocated";
case DCB_STATE_POLLING: case DCB_STATE_POLLING:
return "DCB in the polling loop"; return "DCB in the polling loop";
case DCB_STATE_NOPOLLING:
return "DCB not in the polling loop";
case DCB_STATE_LISTENING: case DCB_STATE_LISTENING:
return "DCB for listening socket"; return "DCB for listening socket";
case DCB_STATE_DISCONNECTED: case DCB_STATE_DISCONNECTED:
@ -1684,14 +1687,16 @@ gw_dcb_state2string (int state) {
return "DCB memory could be freed"; return "DCB memory could be freed";
case DCB_STATE_ZOMBIE: case DCB_STATE_ZOMBIE:
return "DCB Zombie"; return "DCB Zombie";
case DCB_STATE_UNDEFINED:
return "DCB undefined state";
default: default:
return "DCB (unknown)"; return "DCB (unknown - erroneous)";
} }
} }
/** /**
* A DCB based wrapper for printf. Allows formatting printing to * A DCB based wrapper for printf. Allows formatting printing to
* a descritor control block. * a descriptor control block.
* *
* @param dcb Descriptor to write to * @param dcb Descriptor to write to
* @param fmt A printf format string * @param fmt A printf format string
@ -1768,40 +1773,43 @@ void dcb_hashtable_stats(
bool dcb_set_state( bool dcb_set_state(
DCB* dcb, DCB* dcb,
const dcb_state_t new_state, const dcb_state_t new_state,
dcb_state_t* old_state) dcb_state_t* old_state_ptr)
{ {
bool succp; bool succp;
dcb_state_t state ; dcb_state_t old_state_buffer;
CHK_DCB(dcb); CHK_DCB(dcb);
spinlock_acquire(&dcb->dcb_initlock);
succp = dcb_set_state_nomutex(dcb, new_state, &state);
spinlock_acquire(&dcb->dcb_initlock);
succp = dcb_set_state_nolock(dcb, new_state, &old_state_buffer);
spinlock_release(&dcb->dcb_initlock); spinlock_release(&dcb->dcb_initlock);
if (old_state != NULL) { if (old_state_ptr != NULL)
*old_state = state; {
*old_state_ptr = old_state_buffer;
} }
return succp; return succp;
} }
static bool dcb_set_state_nomutex( static bool dcb_set_state_nolock(
DCB* dcb, DCB* dcb,
const dcb_state_t new_state, const dcb_state_t new_state,
dcb_state_t* old_state) dcb_state_t* old_state_ptr)
{ {
bool succp = false; bool succp = false;
dcb_state_t state = DCB_STATE_UNDEFINED; bool old_state_supplied = true;
dcb_state_t state_buffer;
CHK_DCB(dcb); CHK_DCB(dcb);
state = dcb->state; if (NULL == old_state_ptr)
{
if (old_state != NULL) { old_state_supplied = false;
*old_state = state; old_state_ptr = &state_buffer;
} }
*old_state_ptr = dcb->state;
switch (state) { switch (*old_state_ptr) {
case DCB_STATE_UNDEFINED: case DCB_STATE_UNDEFINED:
dcb->state = new_state; dcb->state = new_state;
succp = true; succp = true;
@ -1817,10 +1825,6 @@ static bool dcb_set_state_nomutex(
case DCB_STATE_DISCONNECTED: case DCB_STATE_DISCONNECTED:
dcb->state = new_state; dcb->state = new_state;
succp = true; succp = true;
break;
default:
ss_dassert(old_state != NULL);
break;
} }
break; break;
@ -1829,10 +1833,6 @@ static bool dcb_set_state_nomutex(
case DCB_STATE_NOPOLLING: case DCB_STATE_NOPOLLING:
dcb->state = new_state; dcb->state = new_state;
succp = true; succp = true;
break;
default:
ss_dassert(old_state != NULL);
break;
} }
break; break;
@ -1841,10 +1841,6 @@ static bool dcb_set_state_nomutex(
case DCB_STATE_NOPOLLING: case DCB_STATE_NOPOLLING:
dcb->state = new_state; dcb->state = new_state;
succp = true; succp = true;
break;
default:
ss_dassert(old_state != NULL);
break;
} }
break; break;
@ -1854,10 +1850,6 @@ static bool dcb_set_state_nomutex(
dcb->state = new_state; dcb->state = new_state;
case DCB_STATE_POLLING: /*< ok to try but state can't change */ case DCB_STATE_POLLING: /*< ok to try but state can't change */
succp = true; succp = true;
break;
default:
ss_dassert(old_state != NULL);
break;
} }
break; break;
@ -1867,10 +1859,6 @@ static bool dcb_set_state_nomutex(
dcb->state = new_state; dcb->state = new_state;
case DCB_STATE_POLLING: /*< ok to try but state can't change */ case DCB_STATE_POLLING: /*< ok to try but state can't change */
succp = true; succp = true;
break;
default:
ss_dassert(old_state != NULL);
break;
} }
break; break;
@ -1879,15 +1867,10 @@ static bool dcb_set_state_nomutex(
case DCB_STATE_FREED: case DCB_STATE_FREED:
dcb->state = new_state; dcb->state = new_state;
succp = true; succp = true;
break;
default:
ss_dassert(old_state != NULL);
break;
} }
break; break;
case DCB_STATE_FREED: case DCB_STATE_FREED:
ss_dassert(old_state != NULL);
break; break;
default: default:
@ -1904,24 +1887,25 @@ static bool dcb_set_state_nomutex(
if (succp) { if (succp) {
LOGIF(LD, (skygw_log_write_flush( LOGIF(LD, (skygw_log_write_flush(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [dcb_set_state_nomutex] dcb %p fd %d %s -> %s", "%lu [dcb_set_state_nolock] dcb %p fd %d %s -> %s",
pthread_self(), pthread_self(),
dcb, dcb,
dcb->fd, dcb->fd,
STRDCBSTATE(state), STRDCBSTATE(*old_state_ptr),
STRDCBSTATE(dcb->state)))); STRDCBSTATE(dcb->state))));
} }
else else
{ {
LOGIF(LD, (skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [dcb_set_state_nomutex] Failed " "%lu [dcb_set_state_nolock] Failed "
"to change state of DCB %p. " "to change state of DCB %p. "
"Old state %s > new state %s.", "Old state %s > new state %s.",
pthread_self(), pthread_self(),
dcb, dcb,
(old_state == NULL ? "NULL" : STRDCBSTATE(*old_state)), (old_state_ptr == NULL ? "NULL" : STRDCBSTATE(*old_state_ptr)),
STRDCBSTATE(new_state)))); STRDCBSTATE(new_state))));
ss_dassert(old_state_supplied);
} }
return succp; return succp;
} }
@ -2340,6 +2324,7 @@ dcb_persistent_clean_count(DCB *dcb)
dcb_call_callback(persistentdcb, DCB_REASON_CLOSE); dcb_call_callback(persistentdcb, DCB_REASON_CLOSE);
dcb_add_to_zombieslist(persistentdcb); dcb_add_to_zombieslist(persistentdcb);
atomic_add(&server->stats.n_persistent, -1); atomic_add(&server->stats.n_persistent, -1);
atomic_add(&server->stats.n_connections, -1);
} }
else else
{ {