use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.
the class XARollbackNodesHandler method errorResponse.
@Override
public void errorResponse(byte[] err, BackendConnection conn) {
this.waitUntilSendFinish();
if (conn instanceof MySQLConnection) {
MySQLConnection mysqlCon = (MySQLConnection) conn;
if (mysqlCon.getXaStatus() == TxState.TX_STARTED_STATE) {
mysqlCon.quit();
mysqlCon.setXaStatus(TxState.TX_ROLLBACKED_STATE);
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
if (decrementCountBy(1)) {
session.setXaState(TxState.TX_ENDED_STATE);
rollback();
}
// 'xa rollback' ok without prepared
} else if (mysqlCon.getXaStatus() == TxState.TX_ENDED_STATE) {
mysqlCon.quit();
mysqlCon.setXaStatus(TxState.TX_ROLLBACKED_STATE);
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
if (decrementCountBy(1)) {
session.setXaState(TxState.TX_INITIALIZE_STATE);
cleanAndFeedback();
}
// 'xa rollback' err
} else if (mysqlCon.getXaStatus() == TxState.TX_ROLLBACK_FAILED_STATE || mysqlCon.getXaStatus() == TxState.TX_PREPARED_STATE) {
mysqlCon.setXaStatus(TxState.TX_ROLLBACK_FAILED_STATE);
mysqlCon.quit();
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
session.setXaState(TxState.TX_ROLLBACK_FAILED_STATE);
if (decrementCountBy(1)) {
cleanAndFeedback();
}
// we don't know if the conn prepared or not
} else if (mysqlCon.getXaStatus() == TxState.TX_PREPARE_UNCONNECT_STATE) {
ErrorPacket errPacket = new ErrorPacket();
errPacket.read(err);
if (errPacket.getErrNo() == ErrorCode.ER_XAER_NOTA) {
// ERROR 1397 (XAE04): XAER_NOTA: Unknown XID, not prepared
mysqlCon.setXaStatus(TxState.TX_ROLLBACKED_STATE);
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
mysqlCon.setXaStatus(TxState.TX_INITIALIZE_STATE);
if (decrementCountBy(1)) {
if (session.getXaState() == TxState.TX_PREPARED_STATE) {
session.setXaState(TxState.TX_INITIALIZE_STATE);
}
cleanAndFeedback();
}
} else {
session.setXaState(TxState.TX_ROLLBACK_FAILED_STATE);
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
if (decrementCountBy(1)) {
cleanAndFeedback();
}
}
} else {
LOGGER.info("Wrong XA status flag!");
}
}
}
use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.
the class XARollbackNodesHandler method connectionError.
@Override
public void connectionError(Throwable e, BackendConnection conn) {
this.waitUntilSendFinish();
if (conn instanceof MySQLConnection) {
MySQLConnection mysqlCon = (MySQLConnection) conn;
if (mysqlCon.getXaStatus() == TxState.TX_STARTED_STATE) {
mysqlCon.quit();
mysqlCon.setXaStatus(TxState.TX_ROLLBACKED_STATE);
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
if (decrementCountBy(1)) {
session.setXaState(TxState.TX_ENDED_STATE);
rollback();
}
// 'xa rollback' ok without prepared
} else if (mysqlCon.getXaStatus() == TxState.TX_ENDED_STATE) {
mysqlCon.quit();
mysqlCon.setXaStatus(TxState.TX_ROLLBACKED_STATE);
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
if (decrementCountBy(1)) {
session.setXaState(TxState.TX_INITIALIZE_STATE);
cleanAndFeedback();
}
// 'xa rollback' err
} else if (mysqlCon.getXaStatus() == TxState.TX_PREPARED_STATE) {
mysqlCon.setXaStatus(TxState.TX_ROLLBACK_FAILED_STATE);
mysqlCon.quit();
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
session.setXaState(TxState.TX_ROLLBACK_FAILED_STATE);
if (decrementCountBy(1)) {
cleanAndFeedback();
}
// we don't know if the conn prepared or not
} else if (mysqlCon.getXaStatus() == TxState.TX_PREPARE_UNCONNECT_STATE) {
session.setXaState(TxState.TX_ROLLBACK_FAILED_STATE);
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
if (decrementCountBy(1)) {
cleanAndFeedback();
}
} else {
LOGGER.info("Wrong XA status flag!");
}
}
}
use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.
the class XARollbackNodesHandler method okResponse.
@Override
public void okResponse(byte[] ok, BackendConnection conn) {
this.waitUntilSendFinish();
if (conn instanceof MySQLConnection) {
MySQLConnection mysqlCon = (MySQLConnection) conn;
if (mysqlCon.getXaStatus() == TxState.TX_STARTED_STATE) {
mysqlCon.setXaStatus(TxState.TX_ENDED_STATE);
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
if (decrementCountBy(1)) {
session.setXaState(TxState.TX_ENDED_STATE);
rollback();
}
// 'xa rollback' ok without prepared
} else if (mysqlCon.getXaStatus() == TxState.TX_ENDED_STATE) {
mysqlCon.setXaStatus(TxState.TX_ROLLBACKED_STATE);
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
mysqlCon.setXaStatus(TxState.TX_INITIALIZE_STATE);
if (decrementCountBy(1)) {
session.setXaState(TxState.TX_INITIALIZE_STATE);
cleanAndFeedback();
}
// 'xa rollback' ok
} else if (mysqlCon.getXaStatus() == TxState.TX_PREPARED_STATE || mysqlCon.getXaStatus() == TxState.TX_PREPARE_UNCONNECT_STATE || mysqlCon.getXaStatus() == TxState.TX_ROLLBACK_FAILED_STATE) {
// we don't know if the conn prepared or not
mysqlCon.setXaStatus(TxState.TX_ROLLBACKED_STATE);
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
mysqlCon.setXaStatus(TxState.TX_INITIALIZE_STATE);
if (decrementCountBy(1)) {
if (session.getXaState() == TxState.TX_PREPARED_STATE) {
session.setXaState(TxState.TX_INITIALIZE_STATE);
}
cleanAndFeedback();
}
} else {
LOGGER.info("Wrong XA status flag!");
}
}
}
use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.
the class ReloadConfig method recycleOldBackendConnections.
private static void recycleOldBackendConnections(ServerConfig config, boolean closeFrontCon) {
/* 2.4 put the old connection into a queue */
Map<String, PhysicalDBPool> oldDataHosts = config.getBackupDataHosts();
for (PhysicalDBPool dbPool : oldDataHosts.values()) {
dbPool.stopHeartbeat();
for (PhysicalDatasource ds : dbPool.getAllDataSources()) {
for (NIOProcessor processor : DbleServer.getInstance().getBackendProcessors()) {
for (BackendConnection con : processor.getBackends().values()) {
if (con instanceof MySQLConnection) {
MySQLConnection mysqlCon = (MySQLConnection) con;
if (mysqlCon.getPool() == ds) {
if (con.isBorrowed()) {
if (closeFrontCon) {
findAndcloseFrontCon(con);
} else {
NIOProcessor.BACKENDS_OLD.add(con);
}
} else {
con.close("old idle conn for reload");
}
}
}
}
}
}
}
LOGGER.info("the size of old backend connection to be recycled is: " + NIOProcessor.BACKENDS_OLD.size());
}
use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.
the class ShowBackend method getRow.
private static RowDataPacket getRow(BackendConnection c, String charset) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
if (!(c instanceof MySQLConnection)) {
return null;
}
MySQLConnection conn = (MySQLConnection) c;
row.add(conn.getProcessor().getName().getBytes());
row.add(LongUtil.toBytes(c.getId()));
row.add(LongUtil.toBytes(conn.getThreadId()));
row.add(StringUtil.encode(c.getHost(), charset));
row.add(IntegerUtil.toBytes(c.getPort()));
row.add(IntegerUtil.toBytes(c.getLocalPort()));
row.add(LongUtil.toBytes(c.getNetInBytes()));
row.add(LongUtil.toBytes(c.getNetOutBytes()));
row.add(LongUtil.toBytes((TimeUtil.currentTimeMillis() - c.getStartupTime()) / 1000L));
row.add(c.isClosed() ? "true".getBytes() : "false".getBytes());
row.add(c.isBorrowed() ? "true".getBytes() : "false".getBytes());
row.add(IntegerUtil.toBytes(conn.getWriteQueue().size()));
row.add(conn.getSchema().getBytes());
row.add(conn.getCharset().getClient().getBytes());
row.add(conn.getCharset().getCollation().getBytes());
row.add(conn.getCharset().getResults().getBytes());
row.add((conn.getTxIsolation() + "").getBytes());
row.add((conn.isAutocommit() + "").getBytes());
row.add(StringUtil.encode(conn.getStringOfSysVariables(), charset));
row.add(StringUtil.encode(conn.getStringOfUsrVariables(), charset));
row.add(StringUtil.encode(conn.getXaStatus().toString(), charset));
return row;
}
Aggregations