use of io.mycat.backend.BackendConnection in project Mycat-Server by MyCATApache.
the class NIOProcessor method backendCheck.
// 后端连接检查
private void backendCheck() {
long sqlTimeout = MycatServer.getInstance().getConfig().getSystem().getSqlExecuteTimeout() * 1000L;
Iterator<Entry<Long, BackendConnection>> it = backends.entrySet().iterator();
while (it.hasNext()) {
BackendConnection c = it.next().getValue();
// 删除空连接
if (c == null) {
it.remove();
continue;
}
// SQL执行超时的连接关闭
if (c.isBorrowed() && c.getLastTime() < TimeUtil.currentTimeMillis() - sqlTimeout) {
LOGGER.warn("found backend connection SQL timeout ,close it " + c);
c.close("sql timeout");
}
// 清理已关闭连接,否则空闲检查。
if (c.isClosed()) {
it.remove();
} else {
// very important ,for some data maybe not sent
if (c instanceof AbstractConnection) {
checkConSendQueue((AbstractConnection) c);
}
c.idleCheck();
}
}
}
use of io.mycat.backend.BackendConnection in project Mycat-Server by MyCATApache.
the class NonBlockingSession method closeAndClearResources.
public void closeAndClearResources(String reason) {
for (BackendConnection node : target.values()) {
node.close(reason);
}
target.clear();
clearHandlesResources();
}
use of io.mycat.backend.BackendConnection in project Mycat-Server by MyCATApache.
the class NonBlockingSession method releaseConnection.
public void releaseConnection(RouteResultsetNode rrn, boolean debug, final boolean needRollback) {
BackendConnection c = target.remove(rrn);
if (c != null) {
if (debug) {
LOGGER.debug("release connection " + c);
}
if (c.getAttachment() != null) {
c.setAttachment(null);
}
if (!c.isClosedOrQuit()) {
if (c.isAutocommit()) {
c.release();
} else //if (needRollback)
{
c.setResponseHandler(new RollbackReleaseHandler());
c.rollback();
}
//else {
// c.release();
//}
}
}
}
use of io.mycat.backend.BackendConnection in project Mycat-Server by MyCATApache.
the class NonBlockingSession method releaseConnection.
public void releaseConnection(BackendConnection con) {
Iterator<Entry<RouteResultsetNode, BackendConnection>> itor = target.entrySet().iterator();
while (itor.hasNext()) {
BackendConnection theCon = itor.next().getValue();
if (theCon == con) {
itor.remove();
con.release();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("realse connection " + con);
}
break;
}
}
}
use of io.mycat.backend.BackendConnection in project Mycat-Server by MyCATApache.
the class NonBlockingSession method commit.
public void commit() {
final int initCount = target.size();
if (initCount <= 0) {
ByteBuffer buffer = source.allocate();
buffer = source.writeToBuffer(OkPacket.OK, buffer);
source.write(buffer);
return;
} else if (initCount == 1) {
BackendConnection con = target.elements().nextElement();
commitHandler.commit(con);
} else {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("multi node commit to send ,total " + initCount);
}
checkDistriTransaxAndExecute();
}
}
Aggregations