liuqiufeng commented on code in PR #6499: URL: https://github.com/apache/incubator-seata/pull/6499#discussion_r1580511865
########## server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java: ########## @@ -488,6 +498,96 @@ private boolean isRetryTimeout(long now, long timeout, long beginTime) { return timeout >= ALWAYS_RETRY_BOUNDARY && now - beginTime > timeout; } + /** + * Handle rollbacking by scheduled. + */ + protected void handleRollbackingByScheduled() { + SessionCondition sessionCondition = new SessionCondition(rollbackingStatuses); + sessionCondition.setLazyLoadBranch(true); + List<GlobalSession> rollbackingSessions = + SessionHolder.getRootSessionManager().findGlobalSessions(sessionCondition); + if (CollectionUtils.isEmpty(rollbackingSessions)) { + rollbackingSchedule(DEFAULT_SYNC_PROCESSING_DELAY); + return; + } + rollbackingSessions.sort(Comparator.comparingLong(GlobalSession::getBeginTime)); + //The first one is the oldest one. + GlobalSession globalSession = rollbackingSessions.get(0); + if (!globalSession.isDeadSession()) { + rollbackingSchedule(System.currentTimeMillis() - globalSession.getBeginTime()); + return; + } + long now = System.currentTimeMillis(); + SessionHelper.forEach(rollbackingSessions, rollbackingSession -> { + try { + if (isRetryTimeout(now, MAX_ROLLBACK_RETRY_TIMEOUT, rollbackingSession.getBeginTime())) { + if (ROLLBACK_RETRY_TIMEOUT_UNLOCK_ENABLE) { + rollbackingSession.clean(); + } + + SessionHelper.endRollbackFailed(rollbackingSession, true, true); + + //The function of this 'return' is 'continue'. + return; + } + core.doGlobalRollback(rollbackingSession, true); + } catch (TransactionException ex) { + LOGGER.error("Failed to handle rollbacking [{}] {} {}", rollbackingSession.getXid(), ex.getCode(), ex.getMessage()); + } + }); + rollbackingSchedule(DEFAULT_SYNC_PROCESSING_DELAY); + } + + private void rollbackingSchedule(long delay) { + syncProcessing.schedule( + () -> SessionHolder.distributedLockAndExecute(ROLLBACKING, this::handleRollbackingByScheduled), + delay, TimeUnit.MILLISECONDS); + } + + /** + * Handle committing by scheduled. + */ + protected void handleCommittingByScheduled() { + SessionCondition sessionCondition = new SessionCondition(committingStatuses); + sessionCondition.setLazyLoadBranch(true); + List<GlobalSession> committingSessions = + SessionHolder.getRootSessionManager().findGlobalSessions(sessionCondition); + if (CollectionUtils.isEmpty(committingSessions)) { + committingSchedule(DEFAULT_SYNC_PROCESSING_DELAY); Review Comment: 启动时的延迟1s执行是否有必要? Is the 1s delay in execution at startup necessary? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org For additional commands, e-mail: notifications-h...@seata.apache.org