diff --git a/server/core/dcb.c b/server/core/dcb.c index 47513e748..efaad24ae 100644 --- a/server/core/dcb.c +++ b/server/core/dcb.c @@ -106,7 +106,7 @@ static inline bool dcb_write_parameter_check(DCB *dcb, GWBUF *queue); static inline void dcb_write_fake_code(DCB *dcb); #endif static inline void dcb_write_when_already_queued(DCB *dcb, GWBUF *queue); -static void dcb_log_write_failure(DCB *dcb, GWBUF *queue, int eno); +static int dcb_log_write_failure(DCB *dcb, GWBUF *queue, int eno); static inline void dcb_write_tidy_up(DCB *dcb, bool below_water); static int dcb_write_SSL_error_report (DCB *dcb, int ret); int session_unlink_dcb(SESSION*, DCB*); @@ -1148,7 +1148,8 @@ int below_water; if (written < 0) { - dcb_log_write_failure(dcb, queue, errno); + int rv = dcb_log_write_failure(dcb, queue, errno); + /*< * What wasn't successfully written is stored to write queue * for suspended write. @@ -1157,7 +1158,11 @@ int below_water; dcb->writeq = queue; dcb->stats.n_buffered++; spinlock_release(&dcb->writeqlock); - return 0; + + /** Return 1 if the write failure was due to EWOULDBLOCK or EAGAIN. + The rest of the buffer will be written once an EPOLL_OUT event + arrives.*/ + return rv == 0 ? 1 : 0; } /* * Pull the number of bytes we have written from @@ -1307,9 +1312,10 @@ dcb_write_when_already_queued(DCB *dcb, GWBUF *queue) * @param queue Queue of buffers to write * @param eno Error number for logging */ -static void +static int dcb_log_write_failure(DCB *dcb, GWBUF *queue, int eno) { + int rval = 0; if (LOG_IS_ENABLED(LOGFILE_DEBUG)) { if (eno == EPIPE) @@ -1325,6 +1331,7 @@ dcb_log_write_failure(DCB *dcb, GWBUF *queue, int eno) dcb->fd, eno, strerror(eno)))); + rval = -1; } } @@ -1344,6 +1351,7 @@ dcb_log_write_failure(DCB *dcb, GWBUF *queue, int eno) dcb->fd, eno, strerror(eno)))); + rval = -1; } @@ -1376,8 +1384,10 @@ dcb_log_write_failure(DCB *dcb, GWBUF *queue, int eno) dcb_isclient(dcb) ? "client" : "backend server", eno, strerror(eno)))); + rval = -1; } } + return rval; } /** diff --git a/server/modules/routing/readwritesplit/readwritesplit.c b/server/modules/routing/readwritesplit/readwritesplit.c index a4bb0e1b7..db2d8a46f 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.c +++ b/server/modules/routing/readwritesplit/readwritesplit.c @@ -2493,8 +2493,8 @@ static bool route_single_stmt( rses_end_locked_router_action(rses); goto retblock; } - - if ((ret = target_dcb->func.write(target_dcb, gwbuf_clone(querybuf))) == 1) + GWBUF* wbuf = gwbuf_clone(querybuf); + if ((ret = target_dcb->func.write(target_dcb, wbuf)) == 1) { backend_ref_t* bref; @@ -2508,7 +2508,8 @@ static bool route_single_stmt( } else { - LOGIF(LE, (skygw_log_write_flush( + gwbuf_free(wbuf); + LOGIF((LE|LT), (skygw_log_write_flush( LOGFILE_ERROR, "Error : Routing query failed."))); succp = false;