log_manager.cc:

State update for filewriter was missing and that caused Maxscale to fail if opening of any log file failed.
dcb.c:
	Added EAGAIN and EWOULDBLOCK handling to dcb_read. If dcb_close is called for freshly created dcb, dcb is only freed.
gateway.c:
	Added file_write_footer and write_footer of which the latter is called at exit time. It simply draws a line to screen.
gw_utils.c:
	Some macros for helping comparison between gw_read_gwbuff and dcb_read, which overlap.
poll.c:
	Some macros to help enable/disable mutexing in poll_waitevents
service.c:
	Check return value of listen and session_alloc and behave accordingly.

mysql_client.c:
	If ioctl returned successfully with b==0 it earlier caused closing the client and backend dcbs. Since that doesn't reliably indicate that client has closed socket on its side, Maxscale doesn't close its sockets either.
mysql_common.c:
	In gw_receive_backend_auth, if dcb_read returns n==0, it is not considered as an error anymore. The implemented behavior is not yet complete and correct. Result should be successful but the protocol state shouldn't change to MYSQL_IDLE before backend return is received.
	In gw_send_authentication_to_backend protocol state was always set to MYSQL_AUTH_RECV even if gw_rwite had failed. Now, return value is read and state is set in caller's context basen on the return value.
skygw_utils.cc:
	Removed ss_dassert from skyge_file_init because it prevented from returning meaningful error meassage to the client.:
This commit is contained in:
vraatikka 2013-10-06 22:31:32 +03:00
parent e3a4be8b9d
commit 80b67d1083
11 changed files with 318 additions and 186 deletions

View File

@ -295,7 +295,7 @@ return_succp:
if (err != 0) {
/** This releases memory of all created objects */
logmanager_done_nomutex();
fprintf(stderr, "Initializing logmanager failed.\n");
fprintf(stderr, "* Initializing logmanager failed.\n");
}
return succp;
}
@ -896,7 +896,7 @@ int skygw_log_enable(
bool err = 0;
if (!logmanager_register(true)) {
fprintf(stderr, "ERROR: Can't register to logmanager\n");
//fprintf(stderr, "ERROR: Can't register to logmanager\n");
err = -1;
goto return_err;
}
@ -918,7 +918,7 @@ int skygw_log_disable(
bool err = 0;
if (!logmanager_register(true)) {
fprintf(stderr, "ERROR: Can't register to logmanager\n");
//fprintf(stderr, "ERROR: Can't register to logmanager\n");
err = -1;
goto return_err;
}
@ -961,7 +961,7 @@ static bool logfile_set_enabled(
notused);
if (err != 0) {
fprintf(stderr,
"Writing to logfile %s failed.\n",
"* Writing to logfile %s failed.\n",
STRLOGID(LOGFILE_ERROR));
}
ss_dassert(false);
@ -1010,7 +1010,7 @@ int skygw_log_write_flush(
size_t len;
if (!logmanager_register(true)) {
fprintf(stderr, "ERROR: Can't register to logmanager\n");
//fprintf(stderr, "ERROR: Can't register to logmanager\n");
err = -1;
goto return_err;
}
@ -1063,7 +1063,7 @@ int skygw_log_write(
size_t len;
if (!logmanager_register(true)) {
fprintf(stderr, "ERROR: Can't register to logmanager\n");
//fprintf(stderr, "ERROR: Can't register to logmanager\n");
err = -1;
goto return_err;
}
@ -1629,6 +1629,7 @@ static void filewriter_done(
id = (logfile_id_t)i;
skygw_file_done(fw->fwr_file[id]);
}
fw->fwr_state = DONE;
case DONE:
case UNINIT:
default:

View File

@ -210,6 +210,7 @@ dcb_add_to_zombieslist(DCB *dcb)
}
/**
* Free a DCB and remove it from the chain of all DCBs
*
@ -221,8 +222,6 @@ dcb_add_to_zombieslist(DCB *dcb)
static void
dcb_final_free(DCB *dcb)
{
SERVICE *service;
void* rsession = NULL;
CHK_DCB(dcb);
ss_info_dassert(dcb->state == DCB_STATE_DISCONNECTED,
"dcb not in DCB_STATE_DISCONNECTED state.");
@ -542,9 +541,9 @@ int eno = 0;
while (true)
{
int bufsize;
rc = ioctl(dcb->fd, FIONREAD, &b);
if (rc == -1) {
eno = errno;
errno = 0;
@ -562,7 +561,7 @@ int eno = 0;
}
/** Nothing to read - leave */
if (b == 0) {
n = 0;
n = 0;
goto return_n;
}
bufsize = MIN(b, MAX_BUFFER_SIZE);
@ -593,20 +592,21 @@ int eno = 0;
{
int eno = errno;
errno = 0;
skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Read failed, dcb %p in state %s "
"fd %d, due %d, %s.",
dcb,
STRDCBSTATE(dcb->state),
dcb->fd,
eno,
strerror(eno));
if (eno != EAGAIN && eno != EWOULDBLOCK) {
skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Read failed, dcb %p in state "
"%s fd %d, due %d, %s.",
dcb,
STRDCBSTATE(dcb->state),
dcb->fd,
eno,
strerror(eno));
}
gwbuf_free(buffer);
goto return_n;
}
skygw_log_write(
LOGFILE_TRACE,
"%lu [dcb_read] Read %d bytes from dcb %p in state %s "
@ -638,7 +638,7 @@ int w, saved_errno = 0;
ss_dassert(queue != NULL);
spinlock_acquire(&dcb->writeqlock);
if (dcb->writeq)
if (dcb->writeq != NULL)
{
/*
* We have some queued data, so add our data to
@ -677,26 +677,24 @@ int w, saved_errno = 0;
if (dcb->dcb_role == DCB_ROLE_REQUEST_HANDLER &&
dcb->session != NULL)
{
if (dcb_isclient(dcb)) {
if (fail_next_client_fd) {
dcb_fake_write_errno[dcb->fd] = 32;
dcb_fake_write_ev[dcb->fd] = 29;
fail_next_client_fd = false;
}
} else {
if (fail_next_backend_fd) {
dcb_fake_write_errno[dcb->fd] = 32;
dcb_fake_write_ev[dcb->fd] = 29;
fail_next_backend_fd = false;
}
if (dcb_isclient(dcb) && fail_next_client_fd) {
dcb_fake_write_errno[dcb->fd] = 32;
dcb_fake_write_ev[dcb->fd] = 29;
fail_next_client_fd = false;
} else if (!dcb_isclient(dcb) &&
fail_next_backend_fd)
{
dcb_fake_write_errno[dcb->fd] = 32;
dcb_fake_write_ev[dcb->fd] = 29;
fail_next_backend_fd = false;
}
}
#endif /* SS_DEBUG */
len = GWBUF_LENGTH(queue);
GW_NOINTR_CALL(w = gw_write(dcb->fd,
GWBUF_DATA(queue),
len);
dcb->stats.n_writes++);
GW_NOINTR_CALL(
w = gw_write(dcb->fd, GWBUF_DATA(queue), len);
dcb->stats.n_writes++;
);
saved_errno = errno;
errno = 0;
@ -728,7 +726,6 @@ int w, saved_errno = 0;
}
break;
}
/*
* Pull the number of bytes we have written from
* queue with have.
@ -757,12 +754,10 @@ int w, saved_errno = 0;
{
skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Writing to dcb %p in state %s fd %d "
"failed.",
dcb,
STRDCBSTATE(dcb->state),
dcb->fd);
/* We had a real write failure that we must deal with */
"Error : Writing to %s socket failed due %d, %s.",
dcb_isclient(dcb) ? "client" : "backend server",
saved_errno,
strerror(saved_errno));
return 0;
}
return 1;
@ -859,6 +854,16 @@ dcb_close(DCB *dcb)
int rc;
CHK_DCB(dcb);
/**
* dcb_close may be called for freshly created dcb, in which case
* it only needs to be freed.
*/
if (dcb->state == DCB_STATE_ALLOC) {
dcb_set_state(dcb, DCB_STATE_DISCONNECTED, NULL);
dcb_final_free(dcb);
return;
}
ss_dassert(dcb->state == DCB_STATE_POLLING ||
dcb->state == DCB_STATE_NOPOLLING ||
dcb->state == DCB_STATE_ZOMBIE);

View File

@ -98,6 +98,9 @@ static void log_flush_shutdown(void);
static void log_flush_cb(void* arg);
static void libmysqld_done(void);
static bool file_write_header(FILE* outfile);
static bool file_write_footer(FILE* outfile);
static void write_footer(void);
/**
* Handler for SIGHUP signal. Reload the configuration for the
* gateway.
@ -211,7 +214,28 @@ return_home:
}
#endif
static void write_footer(void)
{
file_write_footer(stdout);
}
static bool file_write_footer(
FILE* outfile)
{
bool succp = false;
size_t wbytes1;
size_t len1;
const char* header_buf1;
header_buf1 = "------------------------------------------------------"
"\n\n";
len1 = strlen(header_buf1);
wbytes1=fwrite((void*)header_buf1, len1, 1, outfile);
succp = true;
return succp;
}
static bool file_write_header(
FILE* outfile)
{
@ -303,10 +327,11 @@ main(int argc, char **argv)
l = atexit(skygw_logmanager_exit);
if (l != 0) {
fprintf(stderr, "Couldn't register exit function.\n");
fprintf(stderr, "* Couldn't register exit function.\n");
}
atexit(datadir_cleanup);
atexit(write_footer);
for (n = 0; n < argc; n++)
{
if (strcmp(argv[n], "-d") == 0)
@ -327,8 +352,8 @@ main(int argc, char **argv)
skygw_log_write_flush(
LOGFILE_ERROR,
"Fatal : Unable to find a MaxScale "
"configuration file, either install one in "
"/etc/MaxScale.cnf, "
"configuration file, either install one "
"in /etc/MaxScale.cnf, "
"$MAXSCALE_HOME/etc/MaxScale.cnf "
"or use the -c option. Exiting.");
}
@ -469,7 +494,7 @@ main(int argc, char **argv)
"file, either install one in /etc/MaxScale.cnf, "
"$MAXSCALE_HOME/etc/MaxScale.cnf "
"or use the -c option. Exiting.");
fprintf(stderr, "Unable to find MaxScale configuration file. "
fprintf(stderr, "* Unable to find MaxScale configuration file. "
"Exiting.\n");
exit(1);
}
@ -483,7 +508,7 @@ main(int argc, char **argv)
server_options[i] = ddopt;
}
}
if (mysql_library_init(num_elements, server_options, server_groups))
{
skygw_log_write_flush(
@ -499,20 +524,20 @@ main(int argc, char **argv)
exit(1);
}
libmysqld_started = TRUE;
if (!config_load(cnf_file))
{
skygw_log_write_flush(
LOGFILE_ERROR,
"Fatal : Failed to load MaxScale configuration file %s. "
"Error : Failed to load MaxScale configuration file %s. "
"Exiting.",
cnf_file);
fprintf(stderr,
"Failed to load MaxScale configuration file. "
"* Failed to load MaxScale configuration file. "
"Exiting.\n");
exit(1);
}
skygw_log_write(
LOGFILE_MESSAGE,
"SkySQL MaxScale (C) SkySQL Ab 2013");
@ -534,7 +559,7 @@ main(int argc, char **argv)
"Fatal : Failed to start any MaxScale services. "
"Exiting.");
fprintf(stderr,
"Failed to start any MaxScale services. Exiting.\n");
"* Failed to start any MaxScale services. Exiting.\n");
exit(1);
}
skygw_log_write(

View File

@ -135,7 +135,9 @@ int gw_read_gwbuff(DCB *dcb, GWBUF **head, int b) {
if (b <= 0) {
//fprintf(stderr, "||| read_gwbuff called with 0 bytes for %i, closing\n", dcb->fd);
#if 0
dcb->func.close(dcb);
#endif
return 1;
}
@ -152,11 +154,11 @@ int gw_read_gwbuff(DCB *dcb, GWBUF **head, int b) {
if (n < 0) {
if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
fprintf(stderr, "Client connection %i: continue for %i, %s\n", dcb->fd, errno, strerror(errno));
/* fprintf(stderr, "Client connection %i: continue for %i, %s\n", dcb->fd, errno, strerror(errno)); */
gwbuf_free(buffer);
return 1;
} else {
fprintf(stderr, "Client connection %i error: %i, %s\n", dcb->fd, errno, strerror(errno));;
/* fprintf(stderr, "Client connection %i error: %i, %s\n", dcb->fd, errno, strerror(errno)); */
gwbuf_free(buffer);
(dcb->func).close(dcb);
return 1;
@ -165,9 +167,11 @@ int gw_read_gwbuff(DCB *dcb, GWBUF **head, int b) {
if (n == 0) {
// socket closed
fprintf(stderr, "Client connection %i closed: %i, %s\n", dcb->fd, errno, strerror(errno));
/* fprintf(stderr, "Client connection %i closed: %i, %s\n", dcb->fd, errno, strerror(errno)); */
gwbuf_free(buffer);
#if 1
(dcb->func).close(dcb);
#endif
return 1;
}

View File

@ -397,6 +397,7 @@ poll_waitevents(void *arg)
eno = gw_getsockerrno(dcb->fd);
if (eno == 0) {
#if 1
simple_mutex_lock(
&dcb->dcb_write_lock,
true);
@ -404,11 +405,14 @@ poll_waitevents(void *arg)
!dcb->dcb_write_active,
"Write already active");
dcb->dcb_write_active = TRUE;
#endif
atomic_add(&pollStats.n_write, 1);
dcb->func.write_ready(dcb);
#if 1
dcb->dcb_write_active = FALSE;
simple_mutex_unlock(
&dcb->dcb_write_lock);
#endif
} else {
skygw_log_write(
LOGFILE_TRACE,
@ -424,12 +428,13 @@ poll_waitevents(void *arg)
}
if (ev & EPOLLIN)
{
#if 1
simple_mutex_lock(&dcb->dcb_read_lock,
true);
ss_info_dassert(!dcb->dcb_read_active,
"Read already active");
dcb->dcb_read_active = TRUE;
#endif
if (dcb->state == DCB_STATE_LISTENING)
{
skygw_log_write(
@ -454,9 +459,11 @@ poll_waitevents(void *arg)
atomic_add(&pollStats.n_read, 1);
dcb->func.read(dcb);
}
#if 1
dcb->dcb_read_active = FALSE;
simple_mutex_unlock(
&dcb->dcb_read_lock);
#endif
}
} /**< for */
no_op = FALSE;

View File

@ -112,7 +112,7 @@ GWPROTOCOL *funcs;
int loaded = load_mysql_users(service);
skygw_log_write(
LOGFILE_MESSAGE,
"MySQL Users loaded: %i.",
"Loaded %d MySQL Users.",
loaded);
}
@ -132,11 +132,26 @@ GWPROTOCOL *funcs;
memcpy(&(port->listener->func), funcs, sizeof(GWPROTOCOL));
port->listener->session = NULL;
sprintf(config_bind, "0.0.0.0:%d", port->port);
if (port->listener->func.listen(port->listener, config_bind))
listeners++;
port->listener->session = session_alloc(service, port->listener);
port->listener->session->state = SESSION_STATE_LISTENER;
if (port->listener->func.listen(port->listener, config_bind)) {
port->listener->session = session_alloc(service, port->listener);
if (port->listener->session != NULL) {
port->listener->session->state = SESSION_STATE_LISTENER;
listeners += 1;
} else {
dcb_close(port->listener);
}
} else {
dcb_close(port->listener);
skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Unable to start to listen port %d for %s %s.",
port->port,
port->protocol,
service->name);
}
return listeners;
}

View File

@ -76,8 +76,10 @@ version()
void
ModuleInit()
{
skygw_log_write( LOGFILE_MESSAGE, "Initialise the MySQL Monitor module %s.\n",
version_str);
skygw_log_write(
LOGFILE_MESSAGE,
"Initialise the MySQL Monitor module %s.",
version_str);
}
/**
@ -260,7 +262,11 @@ char *sep;
sep = "";
while (db)
{
dcb_printf(dcb, "%s%s:%d", sep, db->server->name, db->server->port);
dcb_printf(dcb,
"%s%s:%d",
sep,
db->server->name,
db->server->port);
sep = ", ";
db = db->next;
}
@ -294,8 +300,14 @@ char *uname = defaultUser, *passwd = defaultPasswd;
{
char *dpwd = decryptPassword(passwd);
database->con = mysql_init(NULL);
if (mysql_real_connect(database->con, database->server->name,
uname, dpwd, NULL, database->server->port, NULL, 0) == NULL)
if (mysql_real_connect(database->con,
database->server->name,
uname,
dpwd,
NULL,
database->server->port,
NULL,
0) == NULL)
{
free(dpwd);
server_clear_status(database->server, SERVER_RUNNING);

View File

@ -181,16 +181,10 @@ static int gw_read_backend_event(DCB *dcb) {
current_session->client_sha1,
backend_protocol) != 0)
{
ss_dassert(backend_protocol->state ==
MYSQL_AUTH_FAILED);
backend_protocol->state = MYSQL_AUTH_FAILED;
rc = 1;
} else {
/**
* next step is to wait server's response with
* a new EPOLLIN event
*/
ss_dassert(backend_protocol->state ==
MYSQL_AUTH_RECV);
backend_protocol->state = MYSQL_AUTH_RECV;
rc = 0;
goto return_rc;
}
@ -219,23 +213,24 @@ static int gw_read_backend_event(DCB *dcb) {
/**
* Read backed auth reply
*/
if (!gw_receive_backend_auth(backend_protocol)) {
if (gw_receive_backend_auth(backend_protocol)) {
backend_protocol->state = MYSQL_IDLE;
} else {
backend_protocol->state = MYSQL_AUTH_FAILED;
skygw_log_write_flush(
LOGFILE_ERROR,
"%lu [gw_read_backend_event] "
"gw_receive_backend_auth failed. dcb "
"%p fd %d, user %s.",
pthread_self(),
dcb,
dcb->fd,
current_session->user);
}
}
if (backend_protocol->state == MYSQL_AUTH_FAILED) {
skygw_log_write_flush(
LOGFILE_ERROR,
"%lu [gw_read_backend_event] "
"gw_receive_backend_auth failed. dcb %p fd %d, "
"user %s.",
pthread_self(),
dcb,
dcb->fd,
current_session->user);
/* check the delayq before the reply */
if (dcb->delayq) {
/* send an error to the client */
@ -243,7 +238,7 @@ static int gw_read_backend_event(DCB *dcb) {
dcb->session->client,
1,
0,
"Connection to backend lost right now");
"Connection to backend lost.");
}
/**
* Protect call of closeSession.
@ -273,7 +268,7 @@ static int gw_read_backend_event(DCB *dcb) {
rc = 1;
goto return_rc;
} else {
ss_dassert(backend_protocol->state == MYSQL_AUTH_RECV);
ss_dassert(backend_protocol->state == MYSQL_IDLE);
skygw_log_write_flush(
LOGFILE_DEBUG,
"%lu [gw_read_backend_event] "
@ -284,7 +279,6 @@ static int gw_read_backend_event(DCB *dcb) {
current_session->user);
spinlock_acquire(&dcb->authlock);
backend_protocol->state = MYSQL_IDLE;
/* check the delay queue and flush the data */
if(dcb->delayq) {
backend_write_delayqueue(dcb);
@ -312,8 +306,9 @@ static int gw_read_backend_event(DCB *dcb) {
if (rc < 0) {
/**
* Backend generated EPOLLIN event and if backend has failed, connection
* must be closed to avoid backend dcb from getting hanged.
* Backend generated EPOLLIN event and if backend has
* failed, connection must be closed to avoid backend
* dcb from getting hanged.
*/
(dcb->func).close(dcb);
rc = 0;
@ -335,7 +330,8 @@ static int gw_read_backend_event(DCB *dcb) {
* If dcb->session->client is freed already it may be NULL.
*/
if (dcb->session->client != NULL) {
client_protocol = SESSION_PROTOCOL(dcb->session, MySQLProtocol);
client_protocol = SESSION_PROTOCOL(dcb->session,
MySQLProtocol);
}
if (client_protocol != NULL) {
@ -448,26 +444,28 @@ gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue)
skygw_log_write_flush(
LOGFILE_ERROR,
"%lu [gw_MySQLWrite_backend] Write to backend failed. "
"Backend dcb is %s.",
"Backend dcb %p fd %d is %s.",
pthread_self(),
dcb,
dcb->fd,
STRDCBSTATE(dcb->state));
return 0;
}
spinlock_acquire(&dcb->authlock);
/**
* Now put the incoming data to the delay queue unless backend is connected with auth ok
* Now put the incoming data to the delay queue unless backend is
* connected with auth ok
*/
if (backend_protocol->state != MYSQL_IDLE) {
skygw_log_write(
LOGFILE_DEBUG,
"%lu [gw_MySQLWrite_backend] dcb %p fd %d protocol state %s.",
"%lu [gw_MySQLWrite_backend] dcb %p fd %d protocol "
"state %s.",
pthread_self(),
dcb,
dcb->fd,
STRPROTOCOLSTATE(backend_protocol->state));
//fprintf(stderr, ">>> Writing in the backend %i delay queue: last dcb command %i, queue command %i, protocol state [%s]\n", dcb->fd, dcb->command, queue->command, gw_mysql_protocol_state2string(dcb->state));
backend_set_delayqueue(dcb, queue);
spinlock_release(&dcb->authlock);
return 1;
@ -640,7 +638,7 @@ return_fd:
/**
* Hangup routine the backend dcb: it does nothing right now
* Hangup routine the backend dcb: it does nothing
*
* @param dcb The current Backend DCB
* @return 1 always
@ -726,7 +724,8 @@ static int backend_write_delayqueue(DCB *dcb)
dcb->session->client,
1,
0,
"Closed backend connection.");
"Unable to write to backend server. Connection was "
"closed.");
dcb_close(dcb);
}
return rc;

View File

@ -521,7 +521,7 @@ int gw_read_client_event(DCB* dcb) {
/**
* Check how many bytes are readable in dcb->fd.
*/
if (ioctl(dcb->fd, FIONREAD, &b)) {
if (ioctl(dcb->fd, FIONREAD, &b) != 0) {
int eno = errno;
errno = 0;
skygw_log_write(
@ -538,9 +538,13 @@ int gw_read_client_event(DCB* dcb) {
}
/**
* The client socket was closed.
* Note that earlier b==0 was translated to closed client socket.
* It may, however, happen in other cases too. Besides, if socket
* was closed, next write will tell, thus, with b==0 routine can
* simply return.
*/
if (b == 0) {
#if 0
if (b == 0) {
skygw_log_write(
LOGFILE_TRACE,
"%lu [gw_read_client_event] Dcb %p fd %d was closed. "
@ -568,7 +572,12 @@ int gw_read_client_event(DCB* dcb) {
goto return_rc;
}
#else
if (b == 0) {
rc = 0;
goto return_rc;
}
#endif
switch (protocol->state) {
case MYSQL_AUTH_SENT:
/*
@ -594,7 +603,6 @@ int gw_read_client_event(DCB* dcb) {
// example with consume, assuming one buffer only ...
queue = gw_buffer;
len = GWBUF_LENGTH(queue);
//fprintf(stderr, "<<< Reading from Client %i bytes: [%s]\n", len, GWBUF_DATA(queue));
auth_val = gw_mysql_do_authentication(dcb, queue);
// Data handled withot the dcb->func.write
// so consume it now
@ -690,7 +698,6 @@ int gw_read_client_event(DCB* dcb) {
"client dcb %p.",
pthread_self(),
dcb);
(dcb->func).close(dcb);
} else {
/* Send a custom error as MySQL command reply */
@ -724,7 +731,9 @@ int gw_read_client_event(DCB* dcb) {
else
{
/** Route other commands to backend */
rc = router->routeQuery(router_instance, rsession, queue);
rc = router->routeQuery(router_instance,
rsession,
queue);
/** succeed */
if (rc == 1) {
rc = 0; /**< here '0' means success */
@ -1068,7 +1077,6 @@ int gw_MySQLAccept(DCB *listener)
if (protocol == NULL) {
/** delete client_dcb */
dcb_close(client_dcb);
skygw_log_write_flush(
LOGFILE_ERROR,
"%lu [gw_MySQLAccept] Failed to create "
@ -1093,6 +1101,13 @@ int gw_MySQLAccept(DCB *listener)
*/
if (poll_add_dcb(client_dcb) == -1)
{
/* Send a custom error as MySQL command reply */
mysql_send_custom_error(
client_dcb,
1,
0,
"MaxScale internal error.");
/** delete client_dcb */
dcb_close(client_dcb);
@ -1161,7 +1176,6 @@ gw_client_close(DCB *dcb)
CHK_PROTOCOL(protocol);
}
#endif
dcb_close(dcb);
return 1;
}

View File

@ -166,8 +166,8 @@ int gw_read_backend_handshake(MySQLProtocol *conn) {
if (h_len < (packet_len + 4)) {
/*
* data in buffer less than expected in the packet
* log error this exit point
* data in buffer less than expected in the
* packet. Log error this exit point
*/
conn->state = MYSQL_AUTH_FAILED;
return 1;
@ -177,7 +177,8 @@ int gw_read_backend_handshake(MySQLProtocol *conn) {
payload += 4;
//Now decode mysql handshake
success = gw_decode_mysql_server_handshake(conn, payload);
success = gw_decode_mysql_server_handshake(conn,
payload);
if (success < 0) {
/* MySQL handshake has not been properly decoded
@ -308,7 +309,10 @@ bool gw_receive_backend_auth(
n = dcb_read(dcb, &head);
if (n != -1 &&
/**
* Read didn't fail and there is enough data for mysql packet.
*/
if (n != -1 &&
head != NULL &&
GWBUF_LENGTH(head) >= 5)
{
@ -318,11 +322,52 @@ bool gw_receive_backend_auth(
*/
if (ptr[4] == '\x00') {
succp = true;
} else {
uint8_t* tmpbuf =
(uint8_t *)calloc(1, GWBUF_LENGTH(head)+1);
memcpy(tmpbuf, ptr, GWBUF_LENGTH(head));
skygw_log_write(
LOGFILE_TRACE,
"%lu [gw_receive_backend_auth] Invalid "
"authentication message from backend dcb %p "
"fd %d, ptr[4] = %p, msg %s.",
pthread_self(),
dcb,
dcb->fd,
tmpbuf[4],
tmpbuf);
skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Invalid authentication message from "
"backend server. Authentication failed.");
free(tmpbuf);
}
/**
* Remove data from buffer.
*/
head = gwbuf_consume(head, gwbuf_length(head));
} else {
#if 1
/**
* This is considered as success because call didn't fail,
* although no bytes was read.
*/
if (n == 0) {
succp = true;
}
#endif
skygw_log_write(
LOGFILE_TRACE,
"%lu [gw_receive_backend_auth] Reading from backend dcb "
"%p fd %d in state %s failed. n %d, head %p, len %d",
pthread_self(),
dcb,
dcb->fd,
STRDCBSTATE(dcb->state),
n,
head,
(head == NULL) ? 0 : GWBUF_LENGTH(head));
}
return succp;
}
@ -506,27 +551,22 @@ int gw_send_authentication_to_backend(
payload++;
}
memcpy(payload, "mysql_native_password", strlen("mysql_native_password"));
memcpy(payload,
"mysql_native_password",
strlen("mysql_native_password"));
payload += strlen("mysql_native_password");
payload++;
// put here the paylod size: bytes to write - 4 bytes packet header
gw_mysql_set_byte3(payload_start, (bytes-4));
// write to backend dcb
// ToDO: handle the EAGAIN | EWOULDBLOCK
rv = gw_write(dcb->fd, GWBUF_DATA(buffer), bytes);
rv = dcb_write(dcb, buffer);
gwbuf_consume(buffer, bytes);
/* Set the new state, next would be MYSQL_IDLE or MYSQL_AUTH_FAILED */
conn->state = MYSQL_AUTH_RECV;
if (rv < 0)
return rv;
else
return 0;
if (rv < 0) {
return rv;
} else {
return 0;
}
}
/**

View File

@ -159,7 +159,9 @@ int skygw_rwlock_rdlock(
rwlock->srw_rwlock_thr = pthread_self();
} else {
rwlock->srw_rwlock_thr = 0;
ss_dfprintf(stderr, "pthread_rwlock_rdlock : %s\n", strerror(err));
ss_dfprintf(stderr,
"* pthread_rwlock_rdlock : %s\n",
strerror(err));
}
return err;
}
@ -173,7 +175,9 @@ int skygw_rwlock_wrlock(
rwlock->srw_rwlock_thr = pthread_self();
} else {
rwlock->srw_rwlock_thr = 0;
ss_dfprintf(stderr, "pthread_rwlock_wrlock : %s\n", strerror(err));
ss_dfprintf(stderr,
"* pthread_rwlock_wrlock : %s\n",
strerror(err));
}
return err;
}
@ -186,7 +190,9 @@ int skygw_rwlock_unlock(
if (err == 0) {
rwlock->srw_rwlock_thr = 0;
} else {
ss_dfprintf(stderr, "pthread_rwlock_unlock : %s\n", strerror(err));
ss_dfprintf(stderr,
"* pthread_rwlock_unlock : %s\n",
strerror(err));
}
return err;
}
@ -202,7 +208,9 @@ int skygw_rwlock_destroy(
rwlock->srw_rwlock_thr = 0;
rwlock->srw_rwlock = NULL;
} else {
ss_dfprintf(stderr, "pthread_rwlock_destroy : %s\n", strerror(err));
ss_dfprintf(stderr,
"* pthread_rwlock_destroy : %s\n",
strerror(err));
}
return err;
}
@ -221,7 +229,7 @@ int skygw_rwlock_init(
if (err != 0) {
ss_dfprintf(stderr,
"Creating pthread_rwlock failed : %s\n",
"* Creating pthread_rwlock failed : %s\n",
strerror(err));
goto return_err;
}
@ -299,7 +307,7 @@ mlist_t* mlist_init(
ss_dassert(list != NULL);
if (list == NULL) {
fprintf(stderr, "Allocating memory for mlist failed\n");
fprintf(stderr, "* Allocating memory for mlist failed\n");
mlist_free_memory(list, name);
goto return_list;
}
@ -317,7 +325,7 @@ mlist_t* mlist_init(
&list->mlist_mutex,
strdup("writebuf mutex")) == NULL)
{
ss_dfprintf(stderr, "Creating rwlock for mlist failed\n");
ss_dfprintf(stderr, "* Creating rwlock for mlist failed\n");
mlist_free_memory(list, name);
list = NULL;
goto return_list;
@ -989,7 +997,7 @@ skygw_thread_t* skygw_thread_init(
(skygw_thread_t *)calloc(1, sizeof(skygw_thread_t));
if (th == NULL) {
fprintf(stderr, "FATAL: memory allocation for thread failed\n");
fprintf(stderr, "* Memory allocation for thread failed\n");
goto return_th;
}
ss_dassert(th != NULL);
@ -1070,13 +1078,12 @@ int skygw_thread_start(
if (err != 0) {
fprintf(stderr,
"FATAL: starting file writer thread failed, "
"errno %d : %s\n",
"* Starting file writer thread failed due error, "
"%d, %s\n",
err,
strerror(errno));
goto return_err;
}
ss_dfprintf(stderr, "Started %s thread\n", thr->sth_name);
return_err:
return err;
@ -1242,8 +1249,8 @@ simple_mutex_t* simple_mutex_init(
if (err != 0) {
fprintf(stderr,
"FATAL : initializing simple mutex %s failed, "
"errno %d : %s\n",
"* Initializing simple mutex %s failed due error "
"%d, %s\n",
name,
err,
strerror(errno));
@ -1260,7 +1267,6 @@ simple_mutex_t* simple_mutex_init(
}
sm->sm_enabled = true;
CHK_SIMPLE_MUTEX(sm);
ss_dfprintf(stderr, "Initialized simple mutex %s.\n", name);
return_sm:
return sm;
@ -1282,8 +1288,8 @@ int simple_mutex_done(
if (err != 0) {
perror("simple_mutex : ");
fprintf(stderr,
"FATAL : destroying simple mutex %s failed, "
"errno %d : %s\n",
"* Destroying simple mutex %s failed due "
"%d, %s\n",
sm->sm_name,
err,
strerror(errno));
@ -1323,8 +1329,8 @@ int simple_mutex_lock(
if (err != 0) {
fprintf(stderr,
"INFO : Locking simple mutex %s failed, "
"errno %d : %s\n",
"* Locking simple mutex %s failed due error, "
"%d, %s\n",
sm->sm_name,
err,
strerror(errno));
@ -1345,8 +1351,8 @@ int simple_mutex_unlock(
if (err != 0) {
fprintf(stderr,
"INFO : locking simple mutex %s failed, "
"errno %d : %s\n",
"* Locking simple mutex %s failed due error "
"%d, %s\n",
sm->sm_name,
err,
strerror(errno));
@ -1370,8 +1376,8 @@ skygw_message_t* skygw_message_init(void)
if (err != 0) {
fprintf(stderr,
"FATAL : initializing pthread mutex failed, "
"errno %d : %s\n",
"* Initializing pthread mutex failed due error "
"%d, %s\n",
err,
strerror(errno));
mes = NULL;
@ -1381,8 +1387,8 @@ skygw_message_t* skygw_message_init(void)
if (err != 0) {
fprintf(stderr,
"FATAL : initializing pthread cond var failed, "
"errno %d : %s\n",
"* Initializing pthread cond var failed, "
"due error %d, %s\n",
err,
strerror(errno));
mes = NULL;
@ -1409,8 +1415,7 @@ void skygw_message_done(
if (err != 0) {
fprintf(stderr,
"FATAL : destroying cond var failed, "
"errno %d : %s\n",
"* Destroying cond var failed due error %d, %s\n",
err,
strerror(errno));
}
@ -1419,8 +1424,8 @@ void skygw_message_done(
if (err != 0) {
fprintf(stderr,
"FATAL : destroying pthread mutex failed, "
"errno %d : %s\n",
"* Destroying pthread mutex failed, "
"due error %d, %s\n",
err,
strerror(errno));
}
@ -1439,8 +1444,8 @@ skygw_mes_rc_t skygw_message_send(
if (err != 0) {
fprintf(stderr,
"INFO : Locking pthread mutex failed, "
"errno %d : %s\n",
"* Locking pthread mutex failed, "
"due error %d, %s\n",
err,
strerror(errno));
goto return_mes_rc;
@ -1450,8 +1455,8 @@ skygw_mes_rc_t skygw_message_send(
if (err != 0) {
fprintf(stderr,
"INFO : Signaling pthread cond var failed, "
"errno %d : %s\n",
"* Signaling pthread cond var failed, "
"due error %d, %s\n",
err,
strerror(errno));
goto return_mes_rc;
@ -1460,8 +1465,8 @@ skygw_mes_rc_t skygw_message_send(
if (err != 0) {
fprintf(stderr,
"INFO : Unlocking pthread mutex failed, "
"errno %d : %s\n",
"* Unlocking pthread mutex failed, "
"due error %d, %s\n",
err,
strerror(errno));
goto return_mes_rc;
@ -1482,8 +1487,8 @@ void skygw_message_wait(
if (err != 0) {
fprintf(stderr,
"INFO : Locking pthread mutex failed, "
"errno %d : %s\n",
"* Locking pthread mutex failed, "
"due error %d, %s\n",
err,
strerror(errno));
}
@ -1494,8 +1499,8 @@ void skygw_message_wait(
if (err != 0) {
fprintf(stderr,
"INFO : Locking pthread cond wait failed, "
"errno %d : %s\n",
"* Locking pthread cond wait failed, "
"due error %d, %s\n",
err,
strerror(errno));
}
@ -1505,8 +1510,8 @@ void skygw_message_wait(
if (err != 0) {
fprintf(stderr,
"INFO : Unlocking pthread mutex failed, "
"errno %d : %s\n",
"* Unlocking pthread mutex failed, "
"due error %d, %s\n",
err,
strerror(errno));
}
@ -1524,8 +1529,8 @@ void skygw_message_reset(
if (err != 0) {
fprintf(stderr,
"INFO : Locking pthread mutex failed, "
"errno %d : %s\n",
"* Locking pthread mutex failed, "
"due error %d, %s\n",
err,
strerror(errno));
goto return_mes_rc;
@ -1536,8 +1541,8 @@ void skygw_message_reset(
if (err != 0) {
fprintf(stderr,
"INFO : Unlocking pthread mutex failed, "
"errno %d : %s\n",
"* Unlocking pthread mutex failed, "
"due error %d, %s\n",
err,
strerror(errno));
goto return_mes_rc;
@ -1599,7 +1604,7 @@ static bool file_write_header(
if (wbytes1 != 1 || wbytes2 != 1 || wbytes3 != 1 || wbytes4 != 1) {
fprintf(stderr,
"Writing header %s %s %s to %s failed.\n",
"* Writing header %s %s %s to %s failed.\n",
header_buf1,
header_buf2,
header_buf3,
@ -1659,7 +1664,7 @@ static bool file_write_footer(
if (wbytes1 != 1 || wbytes3 != 1 || wbytes4 != 1) {
fprintf(stderr,
"Writing header %s %s to %s failed.\n",
"* Writing header %s %s to %s failed.\n",
header_buf1,
header_buf3,
header_buf4);
@ -1701,7 +1706,7 @@ bool skygw_file_write(
if (nwritten != 1) {
perror("Logfile write.\n");
fprintf(stderr,
"Writing %ld bytes, %s to %s failed.\n",
"* Writing %ld bytes, %s to %s failed.\n",
nbytes,
(char *)data,
file->sf_fname);
@ -1731,7 +1736,8 @@ skygw_file_t* skygw_file_init(
file = (skygw_file_t *)calloc(1, sizeof(skygw_file_t));
if (file == NULL) {
fprintf(stderr, "Memory allocation for skygw file failed.\n");
fprintf(stderr,
"* Memory allocation for skygw file failed.\n");
perror("SkyGW file allocation\n");
}
ss_dassert(file != NULL);
@ -1742,8 +1748,13 @@ skygw_file_t* skygw_file_init(
file->sf_file = fopen(file->sf_fname, "a");
if (file->sf_file == NULL) {
fprintf(stderr, "Opening file %s failed.\n", file->sf_fname);
perror("SkyGW file open\n");
int eno = errno;
errno = 0;
fprintf(stderr,
"* Opening file %s failed due %d, %s.\n",
file->sf_fname,
eno,
strerror(eno));
free(file);
file = NULL;
goto return_file;
@ -1752,7 +1763,7 @@ skygw_file_t* skygw_file_init(
if (!file_write_header(file)) {
fprintf(stderr,
"Writing header of log file %s failed.\n",
"* Writing header of log file %s failed.\n",
file->sf_fname);
perror("SkyGW file open\n");
free(file);
@ -1761,9 +1772,8 @@ skygw_file_t* skygw_file_init(
}
CHK_FILE(file);
ss_dfprintf(stderr, "Opened %s\n", file->sf_fname);
return_file:
ss_dassert(file->sf_file != NULL);
return_file:
return file;
}
@ -1779,7 +1789,7 @@ void skygw_file_done(
if (!file_write_footer(file)) {
fprintf(stderr,
"Writing header of log file %s failed.\n",
"* Writing header of log file %s failed.\n",
file->sf_fname);
perror("SkyGW file open\n");
}
@ -1790,7 +1800,7 @@ void skygw_file_done(
if (err != 0) {
fprintf(stderr,
"Closing file %s failed : %s.\n",
"* Closing file %s failed : %s.\n",
file->sf_fname,
strerror(err));
}