use of com.actiontech.dble.server.ServerConnection in project dble by actiontech.
the class ReloadConfig method findAndcloseFrontCon.
private static void findAndcloseFrontCon(BackendConnection con) {
if (con instanceof MySQLConnection) {
MySQLConnection mcon1 = (MySQLConnection) con;
for (NIOProcessor processor : DbleServer.getInstance().getFrontProcessors()) {
for (FrontendConnection fcon : processor.getFrontends().values()) {
if (fcon instanceof ServerConnection) {
ServerConnection scon = (ServerConnection) fcon;
Map<RouteResultsetNode, BackendConnection> bons = scon.getSession2().getTargetMap();
for (BackendConnection bcon : bons.values()) {
if (bcon instanceof MySQLConnection) {
MySQLConnection mcon2 = (MySQLConnection) bcon;
if (mcon1 == mcon2) {
scon.killAndClose("reload config all");
return;
}
}
}
}
}
}
}
}
use of com.actiontech.dble.server.ServerConnection in project dble by actiontech.
the class NIOProcessor method frontendCheck.
private void frontendCheck() {
Iterator<Entry<Long, FrontendConnection>> it = frontends.entrySet().iterator();
while (it.hasNext()) {
FrontendConnection c = it.next().getValue();
// remove empty conn
if (c == null) {
it.remove();
this.frontEndsLength.decrementAndGet();
continue;
}
// clean closed conn or check timeout
if (c.isClosed()) {
c.cleanup();
it.remove();
this.frontEndsLength.decrementAndGet();
} else {
// very important ,for some data maybe not sent
checkConSendQueue(c);
if (c instanceof ServerConnection && c.isIdleTimeout()) {
ServerConnection s = (ServerConnection) c;
TxState state = s.getSession2().getXaState();
if (state != null && state != TxState.TX_INITIALIZE_STATE) {
if (state != TxState.TX_COMMIT_FAILED_STATE && state != TxState.TX_ROLLBACK_FAILED_STATE) {
// Active/IDLE/PREPARED XA FrontendS will be rollbacked
s.close("Idle Timeout");
DbleServer.getInstance().getXaSessionCheck().addRollbackSession(s.getSession2());
}
continue;
}
}
c.idleCheck();
}
}
}
use of com.actiontech.dble.server.ServerConnection in project dble by actiontech.
the class MultiNodeQueryHandler method rowEofResponse.
@Override
public void rowEofResponse(final byte[] eof, boolean isLeft, BackendConnection conn) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("on row end response " + conn);
}
this.netOutBytes += eof.length;
if (errorResponse.get()) {
return;
}
final ServerConnection source = session.getSource();
if (!rrs.isCallStatement()) {
if (clearIfSessionClosed(session)) {
return;
} else {
session.releaseConnectionIfSafe(conn, false);
}
}
if (decrementCountBy(1)) {
if (!rrs.isCallStatement() || (rrs.isCallStatement() && rrs.getProcedure().isResultSimpleValue())) {
if (this.sessionAutocommit && !session.getSource().isTxStart() && !session.getSource().isLocked()) {
// clear all connections
session.releaseConnections(false);
}
if (this.isFail() || session.closed()) {
tryErrorFinished(true);
return;
}
}
session.setResponseTime();
writeEofResult(eof, source);
doSqlStat(source);
}
}
use of com.actiontech.dble.server.ServerConnection in project dble by actiontech.
the class MultiNodeQueryHandler method handleEndPacket.
protected void handleEndPacket(byte[] data, AutoTxOperation txOperation, BackendConnection conn) {
ServerConnection source = session.getSource();
if (source.isAutocommit() && !source.isTxStart() && conn.isModifiedSQLExecuted()) {
if (nodeCount < 0) {
return;
}
// Implicit Distributed Transaction,send commit or rollback automatically
if (txOperation == AutoTxOperation.COMMIT) {
if (!conn.isDDL()) {
session.checkBackupStatus();
}
if (session.getXaState() == null) {
NormalAutoCommitNodesHandler autoHandler = new NormalAutoCommitNodesHandler(session, data);
autoHandler.commit();
} else {
XAAutoCommitNodesHandler autoHandler = new XAAutoCommitNodesHandler(session, data, rrs.getNodes());
autoHandler.commit();
}
} else {
if (session.getXaState() == null) {
NormalAutoRollbackNodesHandler autoHandler = new NormalAutoRollbackNodesHandler(session, data, rrs.getNodes(), errConnection);
autoHandler.rollback();
} else {
XAAutoRollbackNodesHandler autoHandler = new XAAutoRollbackNodesHandler(session, data, rrs.getNodes(), errConnection);
autoHandler.rollback();
}
}
} else {
boolean inTransaction = !source.isAutocommit() || source.isTxStart();
if (!inTransaction) {
session.releaseConnection(conn);
}
// Explicit Distributed Transaction
if (inTransaction && (AutoTxOperation.ROLLBACK == txOperation)) {
source.setTxInterrupt("ROLLBACK");
}
if (nodeCount == 0) {
session.setResponseTime();
session.getSource().write(data);
}
}
}
use of com.actiontech.dble.server.ServerConnection in project dble by actiontech.
the class MultiNodeQueryHandler method executeFieldEof.
private void executeFieldEof(byte[] header, List<byte[]> fields, byte[] eof) {
ServerConnection source = session.getSource();
fieldCount = fields.size();
header[3] = ++packetId;
byteBuffer = source.writeToBuffer(header, byteBuffer);
String primaryKey = null;
if (rrs.hasPrimaryKeyToCache()) {
String[] items = rrs.getPrimaryKeyItems();
primaryKeyTable = items[0];
primaryKey = items[1];
}
for (int i = 0, len = fieldCount; i < len; ++i) {
byte[] field = fields.get(i);
FieldPacket fieldPkg = new FieldPacket();
fieldPkg.read(field);
if (rrs.getSchema() != null) {
fieldPkg.setDb(rrs.getSchema().getBytes());
}
if (rrs.getTableAlias() != null) {
fieldPkg.setTable(rrs.getTableAlias().getBytes());
}
if (rrs.getTable() != null) {
fieldPkg.setOrgTable(rrs.getTable().getBytes());
}
fieldPackets.add(fieldPkg);
fieldCount = fields.size();
if (primaryKey != null && primaryKeyIndex == -1) {
// find primary key index
String fieldName = new String(fieldPkg.getName());
if (primaryKey.equalsIgnoreCase(fieldName)) {
primaryKeyIndex = i;
}
}
fieldPkg.setPacketId(++packetId);
byteBuffer = fieldPkg.write(byteBuffer, source, false);
}
eof[3] = ++packetId;
byteBuffer = source.writeToBuffer(eof, byteBuffer);
}
Aggregations