Added closeSession to gw_error_backend_event: the backend failure is handled without faults

Modified gw_send_change_user_to_backend ret code
This commit is contained in:
Massimiliano Pinto
2013-09-18 11:50:19 +02:00
parent 4321861ed8
commit ace4252832
2 changed files with 55 additions and 23 deletions

View File

@ -450,35 +450,67 @@ gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue)
} }
/** /**
* Backend Error Handling * Backend Error Handling for EPOLLER
* *
*/ */
static int gw_error_backend_event(DCB *dcb) { static int gw_error_backend_event(DCB *dcb) {
/* SESSION *session = dcb->session;
fprintf(stderr, ">>> Handle Backend error function for %i\n", dcb->fd); void *rsession;
*/ ROUTER_OBJECT *router;
ROUTER *router_instance;
int rc = 0;
CHK_DCB(dcb);
session = dcb->session;
CHK_SESSION(session);
router = session->service->router;
router_instance = session->service->router_instance;
if (dcb->state != DCB_STATE_POLLING) { if (dcb->state != DCB_STATE_POLLING) {
/**
* if client is not available it needs to be handled in send
* function. Session != NULL, that is known.
*/
mysql_send_custom_error( mysql_send_custom_error(
dcb->session->client, dcb->session->client,
1, 1,
0, 0,
"Writing to backend failed."); "Writing to backend failed.");
return 0; rc = 0;
} } else {
skygw_log_write_flush( mysql_send_custom_error(
LOGFILE_ERROR, dcb->session->client,
"%lu [gw_error_backend_event] Some error occurred in backend.", 1,
pthread_self()); 0,
"Closed backend connection.");
rc = 1;
}
mysql_send_custom_error( skygw_log_write_flush(
dcb->session->client, LOGFILE_ERROR,
1, "%lu [gw_error_backend_event] Some error occurred in backend. rc = %d",
0, pthread_self(), rc);
"Closed backend connection.");
dcb_close(dcb); /* close the active session */
spinlock_acquire(&session->ses_lock);
return 1; rsession = session->router_session;
session->router_session = NULL;
spinlock_release(&session->ses_lock);
if (rsession != NULL) {
skygw_log_write_flush(
LOGFILE_TRACE,
"%lu [gw_read_backend_event] "
"Call closeSession for backend "
"session.",
pthread_self());
router->closeSession(router_instance, rsession);
}
return rc;
} }
/* /*
@ -744,7 +776,7 @@ static int gw_change_user(DCB *backend, SERVER *server, SESSION *in_session, GWB
* in the gw_read_backend_event checking the ROUTER_CHANGE_SESSION command in dcb->command * in the gw_read_backend_event checking the ROUTER_CHANGE_SESSION command in dcb->command
* *
* @param * @param
* @return * @return always 1
*/ */
static int gw_session(DCB *backend_dcb, void *data) { static int gw_session(DCB *backend_dcb, void *data) {
@ -754,5 +786,5 @@ static int gw_session(DCB *backend_dcb, void *data) {
queue->command = ROUTER_CHANGE_SESSION; queue->command = ROUTER_CHANGE_SESSION;
backend_dcb->func.write(backend_dcb, queue); backend_dcb->func.write(backend_dcb, queue);
return 0; return 1;
} }

View File

@ -746,7 +746,7 @@ mysql_send_custom_error (DCB *dcb, int packet_number, int in_affected_rows, cons
* @param dbname The selected database * @param dbname The selected database
* @param user The selected user * @param user The selected user
* @param passwd The SHA1(real_password): Note real_password is unknown * @param passwd The SHA1(real_password): Note real_password is unknown
* @return 0 on success, 1 on failure * @return 1 on success, 0 on failure
*/ */
int gw_send_change_user_to_backend(char *dbname, char *user, uint8_t *passwd, MySQLProtocol *conn) { int gw_send_change_user_to_backend(char *dbname, char *user, uint8_t *passwd, MySQLProtocol *conn) {
int compress = 0; int compress = 0;
@ -918,9 +918,9 @@ int gw_send_change_user_to_backend(char *dbname, char *user, uint8_t *passwd, My
rv = dcb->func.write(dcb, buffer); rv = dcb->func.write(dcb, buffer);
if (rv < 0) if (rv < 0)
return rv;
else
return 0; return 0;
else
return 1;
} }
/** /**