dcb.h
------- 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:
@ -71,44 +71,6 @@ return_p:
|
||||
return p;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* gw_mysql_init
|
||||
*
|
||||
* Initialize mysql protocol struct
|
||||
*
|
||||
* @param data The MySQLProtocol pointer, usually NULL
|
||||
* @return The new MySQLProtocol allocated
|
||||
*
|
||||
*/
|
||||
|
||||
MySQLProtocol *gw_mysql_init(MySQLProtocol *data) {
|
||||
MySQLProtocol *input = NULL;
|
||||
|
||||
// structure allocation
|
||||
input = calloc(1, sizeof(MySQLProtocol));
|
||||
|
||||
if (input == NULL) {
|
||||
int eno = errno;
|
||||
errno = 0;
|
||||
skygw_log_write_flush(
|
||||
LOGFILE_ERROR,
|
||||
"%lu [gw_mysql_init] failed to allocate memory for MySQL "
|
||||
"protocol object. Errno %d, %s.",
|
||||
pthread_self(),
|
||||
eno,
|
||||
strerror(eno));
|
||||
return NULL;
|
||||
}
|
||||
input->protocol_chk_top = CHK_NUM_PROTOCOL;
|
||||
input->protocol_chk_tail = CHK_NUM_PROTOCOL;
|
||||
|
||||
#ifdef MYSQL_CONN_DEBUG
|
||||
fprintf(stderr, "gw_mysql_init() called\n");
|
||||
#endif
|
||||
return input;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* gw_mysql_close
|
||||
@ -502,7 +464,10 @@ int gw_do_connect_to_backend(
|
||||
struct sockaddr_in serv_addr;
|
||||
int rv;
|
||||
int so = 0;
|
||||
DCB* dcb = conn->descriptor;
|
||||
|
||||
CHK_DCB(dcb);
|
||||
|
||||
memset(&serv_addr, 0, sizeof serv_addr);
|
||||
serv_addr.sin_family = AF_INET;
|
||||
so = socket(AF_INET,SOCK_STREAM,0);
|
||||
@ -513,8 +478,9 @@ int gw_do_connect_to_backend(
|
||||
errno = 0;
|
||||
skygw_log_write_flush(
|
||||
LOGFILE_ERROR,
|
||||
"%lu [gw_do_connect_to_backend] Establishing connection to "
|
||||
"back-end server failed. Socket creation failed due %d, %s.",
|
||||
"%lu [gw_do_connect_to_backend] Establishing connection "
|
||||
"to back-end server failed. Socket creation failed due "
|
||||
"%d, %s.",
|
||||
pthread_self(),
|
||||
eno,
|
||||
strerror(eno));
|
||||
@ -522,7 +488,7 @@ int gw_do_connect_to_backend(
|
||||
goto return_rv;
|
||||
}
|
||||
/* Assign so to the caller dcb, conn->descriptor */
|
||||
conn->descriptor->fd = so;
|
||||
dcb->fd = so;
|
||||
/* prepare for connect */
|
||||
setipaddress(&serv_addr.sin_addr, host);
|
||||
serv_addr.sin_port = htons(port);
|
||||
@ -552,7 +518,7 @@ int gw_do_connect_to_backend(
|
||||
/**
|
||||
* Add the dcb in the poll set
|
||||
*/
|
||||
poll_add_dcb(conn->descriptor);
|
||||
poll_add_dcb(dcb);
|
||||
return_rv:
|
||||
return rv;
|
||||
}
|
||||
@ -1007,7 +973,6 @@ int gw_find_mysql_user_password_sha1(char *username, uint8_t *gateway_password,
|
||||
|
||||
if (strlen(user_password))
|
||||
gw_hex2bin(gateway_password, user_password, SHA_DIGEST_LENGTH * 2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1089,4 +1054,3 @@ mysql_send_auth_error (DCB *dcb, int packet_number, int in_affected_rows, const
|
||||
|
||||
return sizeof(mysql_packet_header) + mysql_payload_size;
|
||||
}
|
||||
///
|
||||
|
Reference in New Issue
Block a user