use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.
the class XARollbackNodesHandler method rollbackPhase.
private void rollbackPhase(MySQLConnection mysqlCon) {
if (mysqlCon.getXaStatus() == TxState.TX_ROLLBACK_FAILED_STATE || mysqlCon.getXaStatus() == TxState.TX_PREPARE_UNCONNECT_STATE) {
MySQLConnection newConn = session.freshConn(mysqlCon, this);
if (!newConn.equals(mysqlCon)) {
mysqlCon = newConn;
String xaTxId = mysqlCon.getConnXID(session);
mysqlCon.execCmd("XA ROLLBACK " + xaTxId + ";");
} else if (decrementCountBy(1)) {
cleanAndFeedback();
}
} else if (mysqlCon.getXaStatus() == TxState.TX_ENDED_STATE || mysqlCon.getXaStatus() == TxState.TX_PREPARED_STATE) {
String xaTxId = mysqlCon.getConnXID(session);
mysqlCon.execCmd("XA ROLLBACK " + xaTxId + ";");
} else if (mysqlCon.getXaStatus() == TxState.TX_CONN_QUIT || mysqlCon.getXaStatus() == TxState.TX_ROLLBACKED_STATE) {
if (decrementCountBy(1)) {
cleanAndFeedback();
}
}
}
use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.
the class XARollbackNodesHandler method rollback.
public void rollback() {
final int initCount = session.getTargetCount();
lock.lock();
try {
reset(initCount);
} finally {
lock.unlock();
}
int position = 0;
// then the XA transaction will be not killed. if killed ,then we will not rollback
if (session.getXaState() != null && session.getXaState() == TxState.TX_ENDED_STATE) {
if (!session.cancelableStatusSet(NonBlockingSession.CANCEL_STATUS_COMMITTING)) {
return;
}
}
try {
sendFinishedFlag = false;
for (final RouteResultsetNode node : session.getTargetKeys()) {
final BackendConnection conn = session.getTarget(node);
conn.setResponseHandler(this);
if (!executeRollback((MySQLConnection) conn, position++)) {
break;
}
}
} finally {
lockForErrorHandle.lock();
try {
sendFinishedFlag = true;
sendFinished.signalAll();
} finally {
lockForErrorHandle.unlock();
}
}
}
use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.
the class XARollbackNodesHandler method connectionClose.
@Override
public void connectionClose(BackendConnection conn, String reason) {
this.waitUntilSendFinish();
this.setFail(reason);
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();
}
} else {
LOGGER.info("Wrong XA status flag!");
}
}
}
use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.
the class ShowBackendStat method stat.
private static HashMap<String, BackendStat> stat() {
HashMap<String, BackendStat> all = new HashMap<String, BackendStat>();
for (NIOProcessor p : DbleServer.getInstance().getBackendProcessors()) {
for (BackendConnection bc : p.getBackends().values()) {
if ((bc == null) || !(bc instanceof MySQLConnection)) {
break;
}
MySQLConnection con = (MySQLConnection) bc;
String host = con.getHost();
long port = con.getPort();
BackendStat info = all.get(host + Long.toString(port));
if (info == null) {
info = new BackendStat(host, port);
all.put(host + Long.toString(port), info);
}
if (con.isBorrowed()) {
info.addActive();
}
info.addTotal();
}
}
return all;
}
use of com.actiontech.dble.backend.mysql.nio.MySQLConnection 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;
}
}
}
}
}
}
}
}
Aggregations