-------
Removed DCB states DCB_STATE_IDLE, and DCB_STATE_PROCESSING.
Added DCB_STATE_UNDEFINED for initial content for state variable which doesn't have any specific value set, and DCB_STATE_NOPOLLING to indicate that dcb has been removed from poll set.

Added following dcb roles: DCB_ROLE_SERVICE_LISTENER for listeners of services, and DCB_ROLE_REQUEST_HANDLER for client/backend dcbs. Listeners may have state DCB_STATE_LISTENING, but not DCB_STATE_POLLING. Request handlers may have DCB_STATE_POLLING but not DCB_STATE_LISTENING. Role is passed as an argument to dcb.c:dcb_alloc.

From now on, struct check numbers of DCB are included and checked in DEBUG build only.

Added dcb_role_t dcb_role-member to DCB as well as SPINLOCK dcb_initlock, which protects state changes.

Removed extern keyword from function declarations because functions are by default externally visible if they are declared in header.

dcb.b
------
Function dcb_set_state, and dcb_set_state_nomutex provide functions for changing dcb states. Latter implements a state machine for dcb.
Function dcb_add_to_zombieslist replaces dcb_free. It adds in atomic step dcb to zombieslist and changes state to DCB_STATE_ZOMBIE.
Function dcb_final_free removes dcb from allDCBs list, terminates router and client sessions, and frees dcb and related memory.
Function dcb_process_zombies removes executing thread from dcb's bitmask, and it there are no further thread bits, moves dcb to a victim list, and finally, for each dcb on victim list, closes fd and sets state to DCB_STATE_DISCONNECTED.
Function dcb_close sets dcb state to DCB_STATE_NOPOLLIN, removes dcb from poll set and sets bit to bitmask for each server thread in an atomic step.  

poll.c
------
Function poll_add_dcb sets either DCB_STATE_LISTENING or DCB_STATE_POLLING state for newly created dcb, depending whether the role of dcb is DCB_ROLE_SERVICE_LISTENER, or DCB_ROLE_REQUEST_HANDLER, respectively. Then dcb is set to poll set.

poll_waitevents : commented out code which skipped event if dcb was added to zombieslist or if fd was closed. Added state checks.

service.c : Minor changes.
httpd.c : Removed dcb state changes. They are done in core.
mysql_backend.c : Added checks, removed dcb state changes.
mysql_client.c : Removed dcb state changes. Added checks.
mysql_common.c : Minor changes
telnetd.c : Removed state changes. Replaced some typecasts and pointer references with local variable reads.
skygw_debug.h : Removed two states, and added two to state printing macro.
This commit is contained in:
vraatikka
2013-09-05 22:00:02 +03:00
parent 17ec98fa3d
commit 66e9be814b
10 changed files with 576 additions and 384 deletions

View File

@ -124,16 +124,20 @@ typedef struct {
/* DCB states */
typedef enum {
DCB_STATE_UNDEFINED, /**< State variable with no state */
DCB_STATE_ALLOC, /**< Memory allocated but not populated */
DCB_STATE_IDLE, /**< Not yet in the poll mask */
DCB_STATE_POLLING, /**< Waiting in the poll loop */
DCB_STATE_PROCESSING, /**< Processing an event */
DCB_STATE_LISTENING, /**< The DCB is for a listening socket */
DCB_STATE_DISCONNECTED, /**< The socket is now closed */
DCB_STATE_FREED, /**< Memory freed */
DCB_STATE_NOPOLLING, /**< Removed from poll mask */
DCB_STATE_ZOMBIE /**< DCB is no longer active, waiting to free it */
} dcb_state_t;
typedef enum {
DCB_ROLE_SERVICE_LISTENER,
DCB_ROLE_REQUEST_HANDLER
} dcb_role_t;
/**
* Descriptor Control Block
@ -147,7 +151,11 @@ typedef enum {
* gateway may be selected to execute the required actions when a network event occurs.
*/
typedef struct dcb {
#if defined(SS_DEBUG)
skygw_chk_t dcb_chk_top;
#endif
dcb_role_t dcb_role;
SPINLOCK dcb_initlock;
simple_mutex_t dcb_read_lock;
simple_mutex_t dcb_write_lock;
int fd; /**< The descriptor */
@ -172,7 +180,9 @@ typedef struct dcb {
void *data; /**< Specific client data */
DCBMM memdata; /**< The data related to DCB memory management */
int command; /**< Specific client command type */
#if defined(SS_DEBUG)
skygw_chk_t dcb_chk_tail;
#endif
} DCB;
@ -181,21 +191,26 @@ typedef struct dcb {
#define DCB_PROTOCOL(x, type) (type *)((x)->protocol)
#define DCB_ISZOMBIE(x) ((x)->state == DCB_STATE_ZOMBIE)
extern DCB *dcb_alloc(); /* Allocate a DCB */
extern void dcb_free(DCB *); /* Free a DCB */
extern DCB *dcb_connect(struct server *, struct session *, const char *); /* prepare Backend connection */
extern int dcb_read(DCB *, GWBUF **); /* Generic read routine */
extern int dcb_write(DCB *, GWBUF *); /* Generic write routine */
extern int dcb_drain_writeq(DCB *); /* Generic write routine */
extern void dcb_close(DCB *); /* Generic close functionality */
extern void dcb_process_zombies(int); /* Process Zombies */
extern void printAllDCBs(); /* Debug to print all DCB in the system */
extern void printDCB(DCB *); /* Debug print routine */
extern void dprintAllDCBs(DCB *); /* Debug to print all DCB in the system */
extern void dprintDCB(DCB *, DCB *); /* Debug to print a DCB in the system */
extern const char *gw_dcb_state2string(int); /* DCB state to string */
extern void dcb_printf(DCB *, const char *, ...); /* DCB version of printf */
extern int dcb_isclient(DCB *); /* the DCB is the client of the session */
extern void dcb_hashtable_stats(DCB *, void *); /**< Print statisitics */
DCB *dcb_alloc(dcb_role_t);
void dcb_free(DCB *); /* Free a DCB */
DCB *dcb_connect(struct server *, struct session *, const char *); /* prepare Backend connection */
int dcb_read(DCB *, GWBUF **); /* Generic read routine */
int dcb_write(DCB *, GWBUF *); /* Generic write routine */
int dcb_drain_writeq(DCB *); /* Generic write routine */
void dcb_close(DCB *); /* Generic close functionality */
void dcb_process_zombies(int); /* Process Zombies */
void printAllDCBs(); /* Debug to print all DCB in the system */
void printDCB(DCB *); /* Debug print routine */
void dprintAllDCBs(DCB *); /* Debug to print all DCB in the system */
void dprintDCB(DCB *, DCB *); /* Debug to print a DCB in the system */
const char *gw_dcb_state2string(int); /* DCB state to string */
void dcb_printf(DCB *, const char *, ...); /* DCB version of printf */
int dcb_isclient(DCB *); /* the DCB is the client of the session */
void dcb_hashtable_stats(DCB *, void *); /**< Print statisitics */
void dcb_add_to_zombieslist(DCB* dcb);
#endif
bool dcb_set_state(
DCB* dcb,
dcb_state_t new_state,
dcb_state_t* old_state);
#endif /* _DCB_H */