use of com.actiontech.dble.backend.mysql.xa.CoordinatorLogEntry in project dble by actiontech.
the class XARollbackNodesHandler method executeRollback.
private boolean executeRollback(MySQLConnection mysqlCon, int position) {
if (position == 0 && participantLogEntry != null) {
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), session.getXaState());
}
if (session.getXaState() == TxState.TX_STARTED_STATE) {
if (participantLogEntry == null) {
participantLogEntry = new ParticipantLogEntry[nodeCount];
CoordinatorLogEntry coordinatorLogEntry = new CoordinatorLogEntry(session.getSessionXaID(), participantLogEntry, session.getXaState());
XAStateLog.flushMemoryRepository(session.getSessionXaID(), coordinatorLogEntry);
}
XAStateLog.initRecoveryLog(session.getSessionXaID(), position, mysqlCon);
if (mysqlCon.isClosed()) {
mysqlCon.setXaStatus(TxState.TX_CONN_QUIT);
}
endPhase(mysqlCon);
} else if (session.getXaState() == TxState.TX_PREPARED_STATE) {
if (position == 0) {
if (!XAStateLog.saveXARecoveryLog(session.getSessionXaID(), TxState.TX_ROLLBACKING_STATE)) {
this.setFail("saveXARecoveryLog error, the stage is TX_ROLLBACKING_STATE");
cleanAndFeedback();
return false;
}
this.debugRollbackDelay();
}
rollbackPhase(mysqlCon);
} else if (session.getXaState() == TxState.TX_ROLLBACK_FAILED_STATE || session.getXaState() == TxState.TX_PREPARE_UNCONNECT_STATE) {
rollbackPhase(mysqlCon);
} else if (session.getXaState() == TxState.TX_ENDED_STATE) {
if (position == 0) {
this.debugRollbackDelay();
}
rollbackPhase(mysqlCon);
}
return true;
}
use of com.actiontech.dble.backend.mysql.xa.CoordinatorLogEntry in project dble by actiontech.
the class FileSystemRepository method writeCheckpoint.
@Override
public boolean writeCheckpoint(Collection<CoordinatorLogEntry> checkpointContent) {
try {
closeOutput();
file.rotateFileVersion();
rwChannel = file.openNewVersionForNioWriting();
for (CoordinatorLogEntry coordinatorLogEntry : checkpointContent) {
write(coordinatorLogEntry, false);
}
rwChannel.force(false);
file.discardBackupVersion();
return true;
} catch (Exception e) {
LOGGER.warn(AlarmCode.CORE_FILE_WRITE_WARN + "Failed to write checkpoint", e);
return false;
}
}
use of com.actiontech.dble.backend.mysql.xa.CoordinatorLogEntry in project dble by actiontech.
the class KVStoreRepository method writeCheckpoint.
@Override
public boolean writeCheckpoint(Collection<CoordinatorLogEntry> checkpointContent) {
try {
StringBuilder sb = new StringBuilder();
for (CoordinatorLogEntry coordinatorLogEntry : checkpointContent) {
sb.append(Serializer.toJson(coordinatorLogEntry));
}
byte[] data = sb.toString().getBytes(StandardCharsets.UTF_8);
if (zkConn.checkExists().forPath(logPath) == null) {
zkConn.create().creatingParentsIfNeeded().forPath(logPath);
}
zkConn.setData().forPath(logPath, data);
return true;
} catch (Exception e) {
LOGGER.warn(AlarmCode.CORE_ZK_WARN + "Failed to write checkpoint", e);
return false;
}
}
use of com.actiontech.dble.backend.mysql.xa.CoordinatorLogEntry in project dble by actiontech.
the class XACommitNodesHandler method executeCommit.
@Override
protected boolean executeCommit(MySQLConnection mysqlCon, int position) {
TxState state = session.getXaState();
if (state == TxState.TX_STARTED_STATE) {
if (participantLogEntry == null) {
participantLogEntry = new ParticipantLogEntry[nodeCount];
CoordinatorLogEntry coordinatorLogEntry = new CoordinatorLogEntry(session.getSessionXaID(), participantLogEntry, session.getXaState());
XAStateLog.flushMemoryRepository(session.getSessionXaID(), coordinatorLogEntry);
}
XAStateLog.initRecoveryLog(session.getSessionXaID(), position, mysqlCon);
endPhase(mysqlCon);
} else if (state == TxState.TX_ENDED_STATE) {
if (position == 0) {
if (!XAStateLog.saveXARecoveryLog(session.getSessionXaID(), TxState.TX_PREPARING_STATE)) {
String errMsg = "saveXARecoveryLog error, the stage is TX_PREPARING_STATE";
this.setFail(errMsg);
sendData = makeErrorPacket(errMsg);
nextParse();
return false;
}
this.debugCommitDelay();
}
preparePhase(mysqlCon);
} else if (state == TxState.TX_PREPARED_STATE) {
if (position == 0) {
if (!XAStateLog.saveXARecoveryLog(session.getSessionXaID(), TxState.TX_COMMITTING_STATE)) {
String errMsg = "saveXARecoveryLog error, the stage is TX_COMMITTING_STATE";
this.setFail(errMsg);
sendData = makeErrorPacket(errMsg);
nextParse();
return false;
}
this.debugCommitDelay();
}
commitPhase(mysqlCon);
} else if (state == TxState.TX_COMMIT_FAILED_STATE) {
if (position == 0) {
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), TxState.TX_COMMIT_FAILED_STATE);
}
commitPhase(mysqlCon);
} else if (state == TxState.TX_PREPARE_UNCONNECT_STATE) {
final String errorMsg = this.error;
LOGGER.warn(AlarmCode.CORE_XA_WARN + "commit error and rollback the xa");
if (decrementCountBy(1)) {
DbleServer.getInstance().getComplexQueryExecutor().execute(new Runnable() {
@Override
public void run() {
ErrorPacket error = new ErrorPacket();
error.setErrNo(ER_ERROR_DURING_COMMIT);
error.setMessage(errorMsg == null ? "unknown error".getBytes() : errorMsg.getBytes());
XAAutoRollbackNodesHandler nextHandler = new XAAutoRollbackNodesHandler(session, error.toBytes(), null, null);
nextHandler.rollback();
}
});
}
}
return true;
}
use of com.actiontech.dble.backend.mysql.xa.CoordinatorLogEntry in project dble by actiontech.
the class FileSystemRepository method readContent.
private static Map<String, CoordinatorLogEntry> readContent(BufferedReader br) throws IOException {
Map<String, CoordinatorLogEntry> coordinatorLogEntries = new HashMap<>();
try {
String line;
while ((line = br.readLine()) != null) {
CoordinatorLogEntry coordinatorLogEntry = deserialize(line);
coordinatorLogEntries.put(coordinatorLogEntry.getId(), coordinatorLogEntry);
}
} catch (EOFException unexpectedEOF) {
LOGGER.info("Unexpected EOF - logfile not closed properly last time?", unexpectedEOF);
// merely return what was read so far...
} catch (ObjectStreamException unexpectedEOF) {
LOGGER.warn(AlarmCode.CORE_FILE_WRITE_WARN + "Unexpected EOF - logfile not closed properly last time?", unexpectedEOF);
// merely return what was read so far...
} catch (DeserializationException unexpectedEOF) {
LOGGER.warn(AlarmCode.CORE_FILE_WRITE_WARN + "Unexpected EOF - logfile not closed properly last time? " + unexpectedEOF);
}
return coordinatorLogEntries;
}
Aggregations