You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@seata.apache.org by "YongGoose (via GitHub)" <gi...@apache.org> on 2025/01/31 05:39:18 UTC
[PR] Add compensation handling for TimeoutRollbacked and Rollbacked states [incubator-seata]
YongGoose opened a new pull request, #7133:
URL: https://github.com/apache/incubator-seata/pull/7133
…tates
<!-- Please make sure you have read and understood the contributing guidelines -->
- [x] I have registered the PR [changes](../changes).
### Ⅰ. Describe what this PR did
- Add compensation handling for TimeoutRollbacked and Rollbacked states
### Ⅱ. Does this pull request fix one issue?
<!-- If that, add "fixes #xxx" below in the next line, for example, fixes #97. -->
fixes #6875
### Ⅲ. Why don't you add test cases (unit test/integration test)?
### Ⅳ. Describe how to verify it
### Ⅴ. Special notes for reviews
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement scheduled handling for end status transaction [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1958922216
##########
server/src/main/java/org/apache/seata/server/session/SessionHelper.java:
##########
@@ -454,6 +454,25 @@ public static void removeAllBranch(GlobalSession globalSession, boolean isAsync)
}
}
+ public static void processEndState(GlobalSession globalSession) throws TransactionException {
+ GlobalStatus globalStatus = globalSession.getStatus();
+
+ switch (globalStatus) {
+ case CommitFailed:
Review Comment:
```suggestion
case Committed:
```
##########
server/src/main/java/org/apache/seata/server/session/SessionHelper.java:
##########
@@ -454,6 +454,25 @@ public static void removeAllBranch(GlobalSession globalSession, boolean isAsync)
}
}
+ public static void processEndState(GlobalSession globalSession) throws TransactionException {
+ GlobalStatus globalStatus = globalSession.getStatus();
+
+ switch (globalStatus) {
+ case CommitFailed:
+ case Finished:
+ endCommitted(globalSession, true);
+ return;
+ case Rollbacked:
+ case TimeoutRollbacked:
+ case RollbackFailed:
+ case TimeoutRollbackFailed:
Review Comment:
```suggestion
```
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -189,12 +197,16 @@ public class DefaultCoordinator extends AbstractTCInboundHandler implements Tran
private final GlobalStatus[] retryRollbackingStatuses = new GlobalStatus[] {
GlobalStatus.TimeoutRollbacking,
- GlobalStatus.TimeoutRollbackRetrying, GlobalStatus.RollbackRetrying};
+ GlobalStatus.TimeoutRollbackRetrying,
+ GlobalStatus.RollbackRetrying
+ };
private final GlobalStatus[] retryCommittingStatuses = new GlobalStatus[] {GlobalStatus.CommitRetrying, GlobalStatus.Committed};
private final GlobalStatus[] rollbackingStatuses = new GlobalStatus[] {GlobalStatus.Rollbacking};
private final GlobalStatus[] committingStatuses = new GlobalStatus[] {GlobalStatus.Committing};
+ private final GlobalStatus[] endStatuses = new GlobalStatus[] {GlobalStatus.Rollbacked, GlobalStatus.TimeoutRollbacked,
+ GlobalStatus.CommitFailed, GlobalStatus.RollbackFailed, GlobalStatus.TimeoutRollbackFailed, GlobalStatus.Finished};
Review Comment:
```suggestion
private final GlobalStatus[] endStatuses = new GlobalStatus[] {GlobalStatus.Rollbacked, GlobalStatus.Committed, GlobalStatus.Finished};
```
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -189,12 +197,16 @@ public class DefaultCoordinator extends AbstractTCInboundHandler implements Tran
private final GlobalStatus[] retryRollbackingStatuses = new GlobalStatus[] {
GlobalStatus.TimeoutRollbacking,
- GlobalStatus.TimeoutRollbackRetrying, GlobalStatus.RollbackRetrying};
+ GlobalStatus.TimeoutRollbackRetrying,
+ GlobalStatus.RollbackRetrying
+ };
private final GlobalStatus[] retryCommittingStatuses = new GlobalStatus[] {GlobalStatus.CommitRetrying, GlobalStatus.Committed};
Review Comment:
```suggestion
private final GlobalStatus[] retryCommittingStatuses = new GlobalStatus[] {GlobalStatus.CommitRetrying};
```
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement Scheduled Handling for Rollbacked and TimeoutRollbacked Transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1955426063
##########
server/src/main/java/org/apache/seata/server/session/GlobalSession.java:
##########
@@ -204,9 +204,17 @@ public boolean isTimeout() {
/**
* prevent could not handle committing and rollbacking transaction
+ *
+ * If the global session's status is "Rollbacked" or "TimeoutRollbacked", it returns the negative time since the session began,
+ * indicating that the session is already dead.
+ * For other statuses, it returns the remaining time until the session reaches the retry dead threshold.
+ *
* @return time to dead session. if not greater than 0, then deadSession
*/
public long timeToDeadSession() {
+ if (this.status == GlobalStatus.Rollbacked || this.status == GlobalStatus.TimeoutRollbacked) {
+ return beginTime - System.currentTimeMillis();
Review Comment:
> The beginTime is set when the transaction is created. When the Seata server's business thread changes the transaction status from "Rollbacking" to "Rollbacked," your timeToDeadSession method directly subtracts the current timestamp from beginTime, which will inevitably result in a negative value. As a result, the business thread will delete the transaction, and your scheduled task will also delete the transaction, leading to a concurrency issue and thread safety problem. I believe that beginTime should be increased by the corresponding transaction timeout, plus an additional buffer time to ensure thread safety.
Since our comments were written at the same time, I didn’t see yours when I was writing mine. 😅
Thank you for the additional explanation!
In that case, I will adjust the execution interval for sessions in the `end state` to be shorter using an `if` condition.
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement Scheduled Handling for Rollbacked and TimeoutRollbacked Transaction [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1955476849
##########
server/src/main/java/org/apache/seata/server/session/GlobalSession.java:
##########
@@ -204,9 +204,17 @@ public boolean isTimeout() {
/**
* prevent could not handle committing and rollbacking transaction
+ *
+ * If the global session's status is "Rollbacked" or "TimeoutRollbacked", it returns the negative time since the session began,
+ * indicating that the session is already dead.
+ * For other statuses, it returns the remaining time until the session reaches the retry dead threshold.
+ *
* @return time to dead session. if not greater than 0, then deadSession
*/
public long timeToDeadSession() {
+ if (this.status == GlobalStatus.Rollbacked || this.status == GlobalStatus.TimeoutRollbacked) {
+ return beginTime - System.currentTimeMillis();
Review Comment:
Create a corresponding RETRY_DEAD_THRESHOLD for the end state
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement Scheduled Handling for Rollbacked and TimeoutRollbacked Transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1955423749
##########
server/src/main/java/org/apache/seata/server/session/GlobalSession.java:
##########
@@ -204,9 +204,17 @@ public boolean isTimeout() {
/**
* prevent could not handle committing and rollbacking transaction
+ *
+ * If the global session's status is "Rollbacked" or "TimeoutRollbacked", it returns the negative time since the session began,
+ * indicating that the session is already dead.
+ * For other statuses, it returns the remaining time until the session reaches the retry dead threshold.
+ *
* @return time to dead session. if not greater than 0, then deadSession
*/
public long timeToDeadSession() {
+ if (this.status == GlobalStatus.Rollbacked || this.status == GlobalStatus.TimeoutRollbacked) {
+ return beginTime - System.currentTimeMillis();
Review Comment:
Then, would it be appropriate to create a `RETRY_DEAD_THRESHOLD` specifically for the end state?
> Of course, this timeToDeadSession method is more relevant for ongoing statuses like "rollbacking" or "committing." For transactions in the "end" status, I believe the interval can be shortened.
As suggested in the discussion, since we can reduce the interval in the end state, I believe decreasing the size of `RETRY_DEAD_THRESHOLD` could be a reasonable approach.
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] Add compensation handling for TimeoutRollbacked and Rollbacked states [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1952352985
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -189,7 +189,11 @@ public class DefaultCoordinator extends AbstractTCInboundHandler implements Tran
private final GlobalStatus[] retryRollbackingStatuses = new GlobalStatus[] {
GlobalStatus.TimeoutRollbacking,
- GlobalStatus.TimeoutRollbackRetrying, GlobalStatus.RollbackRetrying};
+ GlobalStatus.TimeoutRollbackRetrying,
+ GlobalStatus.RollbackRetrying,
+ GlobalStatus.TimeoutRollbacked,
+ GlobalStatus.Rollbacked
Review Comment:
@funky-eyes
Done in https://github.com/apache/incubator-seata/pull/7133/commits/fc28796f8009fdecb1dd554c91d461a623d1a050 !
PTAL ⚡️
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement scheduled handling for end status transaction [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1958982626
##########
server/src/main/java/org/apache/seata/server/session/GlobalSession.java:
##########
@@ -203,13 +211,33 @@ public boolean isTimeout() {
}
/**
- * prevent could not handle committing and rollbacking transaction
+ * prevent could not handle committing, rollbacking and rollbacked transaction
+ *
+ * If the global session's status is in end status, it returns the remaining time until the session reaches
+ * the end state retry dead threshold.
+ * For other statuses, it returns the remaining time until the session reaches the retry dead threshold.
+ *
* @return time to dead session. if not greater than 0, then deadSession
*/
public long timeToDeadSession() {
+ if (isEndStatus()) {
+ return beginTime + END_STATE_RETRY_DEAD_THRESHOLD - System.currentTimeMillis();
+ }
return beginTime + RETRY_DEAD_THRESHOLD - System.currentTimeMillis();
}
+ private boolean isEndStatus() {
+ EnumSet<GlobalStatus> deadStatuses = EnumSet.of(
+ GlobalStatus.Rollbacked,
+ GlobalStatus.TimeoutRollbacked,
+ GlobalStatus.CommitFailed,
+ GlobalStatus.RollbackFailed,
+ GlobalStatus.TimeoutRollbackFailed,
+ GlobalStatus.Finished
+ );
Review Comment:
Sorry, I think I missed TimeoutRollbacked. Since TimeoutRollbacked is not a failed end state, it should be handled by scheduled tasks.
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] Add compensation handling for TimeoutRollbacked and Rollbacked states [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#issuecomment-2635579685
@funky-eyes
In the issue description, it was mentioned that the state remains unchanged unless the server is `restarted`.
This means that the data will persist unless the server is restarted.
So, aside from handling it specifically during a server restart, I believe additional measures should be taken.
WDYT?
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement Scheduled Handling for Rollbacked and TimeoutRollbacked Transaction [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1957079692
##########
server/src/main/java/org/apache/seata/server/session/GlobalSession.java:
##########
@@ -203,13 +211,35 @@ public boolean isTimeout() {
}
/**
- * prevent could not handle committing and rollbacking transaction
+ * prevent could not handle committing, rollbacking and rollbacked transaction
+ *
+ * If the global session's status is in end status, it returns the remaining time until the session reaches
+ * the end state retry dead threshold.
+ * For other statuses, it returns the remaining time until the session reaches the retry dead threshold.
+ *
* @return time to dead session. if not greater than 0, then deadSession
*/
public long timeToDeadSession() {
+ if (isEndStatus()) {
+ return beginTime + END_STATE_RETRY_DEAD_THRESHOLD - System.currentTimeMillis();
+ }
return beginTime + RETRY_DEAD_THRESHOLD - System.currentTimeMillis();
}
+ private boolean isEndStatus() {
+ EnumSet<GlobalStatus> deadStatuses = EnumSet.of(
+ GlobalStatus.Rollbacked,
+ GlobalStatus.TimeoutRollbacked,
+ GlobalStatus.CommitFailed,
+ GlobalStatus.RollbackFailed,
+ GlobalStatus.TimeoutRollbackFailed,
+ GlobalStatus.Finished,
+ GlobalStatus.CommitRetryTimeout,
+ GlobalStatus.RollbackRetryTimeout
Review Comment:
```suggestion
GlobalStatus.Finished
```
##########
common/src/main/java/org/apache/seata/common/ConfigurationKeys.java:
##########
@@ -475,6 +475,11 @@ public interface ConfigurationKeys {
*/
String ROLLBACKING_RETRY_PERIOD = RECOVERY_PREFIX + "rollbackingRetryPeriod";
+ /**
+ * The constant ROLLBACKED_RETRY_PERIOD.
+ */
+ String ROLLBACKED_RETRY_PERIOD = RECOVERY_PREFIX + "rollbackedRetryPeriod";
Review Comment:
https://github.com/apache/incubator-seata/blob/2.x/script/config-center/config.txt
https://github.com/apache/incubator-seata/blob/2.x/server/src/main/resources/application.example.yml
https://github.com/apache/incubator-seata/blob/2.x/server/src/main/resources/application.raft.example.yml
https://github.com/apache/incubator-seata/blob/2.x/seata-spring-autoconfigure/seata-spring-autoconfigure-server/src/main/java/org/apache/seata/spring/boot/autoconfigure/properties/server/ServerProperties.java
This configuration item needs to be supplemented in the above file, and I think it is no longer appropriate to name this configuration starting with `rollback`, because it is a configuration name for handling transactions in the `end` state..
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -189,12 +197,17 @@ public class DefaultCoordinator extends AbstractTCInboundHandler implements Tran
private final GlobalStatus[] retryRollbackingStatuses = new GlobalStatus[] {
GlobalStatus.TimeoutRollbacking,
- GlobalStatus.TimeoutRollbackRetrying, GlobalStatus.RollbackRetrying};
+ GlobalStatus.TimeoutRollbackRetrying,
+ GlobalStatus.RollbackRetrying
+ };
private final GlobalStatus[] retryCommittingStatuses = new GlobalStatus[] {GlobalStatus.CommitRetrying, GlobalStatus.Committed};
private final GlobalStatus[] rollbackingStatuses = new GlobalStatus[] {GlobalStatus.Rollbacking};
private final GlobalStatus[] committingStatuses = new GlobalStatus[] {GlobalStatus.Committing};
+ private final GlobalStatus[] rollbackedStatuses = new GlobalStatus[] {GlobalStatus.Rollbacked, GlobalStatus.TimeoutRollbacked,
Review Comment:
```suggestion
private final GlobalStatus[] endStatuses = new GlobalStatus[] {GlobalStatus.Rollbacked, GlobalStatus.TimeoutRollbacked,
```
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -631,6 +645,60 @@ private void committingSchedule(long delay) {
delay, TimeUnit.MILLISECONDS);
}
+ /**
+ * Handle rollbacked by scheduled.
+ */
+ protected void handleRollbackedByScheduled() {
+ SessionCondition sessionCondition = new SessionCondition(rollbackedStatuses);
+ sessionCondition.setLazyLoadBranch(true);
+ List<GlobalSession> rollbackedSessions =
+ SessionHolder.getRootSessionManager().findGlobalSessions(sessionCondition);
+ if (CollectionUtils.isEmpty(rollbackedSessions)) {
+ rollbackedSchedule(RETRY_DEAD_THRESHOLD);
+ return;
+ }
+ long delay = ROLLBACKED_RETRY_PERIOD;
+ rollbackedSessions.sort(Comparator.comparingLong(GlobalSession::getBeginTime));
+ List<GlobalSession> needDoRollbackedSessions = new ArrayList<>();
+ for (GlobalSession rollbackedSession : rollbackedSessions) {
+ long time = rollbackedSession.timeToDeadSession();
+ if (time <= 0) {
+ needDoRollbackedSessions.add(rollbackedSession);
+ } else {
+ delay = Math.max(time, ROLLBACKED_RETRY_PERIOD);
+ break;
+ }
+ }
+ long now = System.currentTimeMillis();
+ SessionHelper.forEach(needDoRollbackedSessions, rollbackedSession -> {
+ try {
+ if (isRetryTimeout(now, MAX_ROLLBACK_RETRY_TIMEOUT, rollbackedSession.getBeginTime())) {
+
+ // commit retry timeout event
+ SessionHelper.endRollbackFailed(rollbackedSession, true, true);
+
+ //The function of this 'return' is 'continue'.
+ return;
+ }
+ core.doGlobalRollback(rollbackedSession, true);
Review Comment:
It should no longer perform rollback processing. For different states of transactions in the end phase, call the `SessionHelper.endRollbacked` and `SessionHelper.endCommitted` methods respectively.
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -631,6 +645,60 @@ private void committingSchedule(long delay) {
delay, TimeUnit.MILLISECONDS);
}
+ /**
+ * Handle rollbacked by scheduled.
+ */
+ protected void handleRollbackedByScheduled() {
Review Comment:
```suggestion
protected void handleEndStatesByScheduled() {
```
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement Scheduled Handling for Rollbacked and TimeoutRollbacked Transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1955460898
##########
server/src/main/java/org/apache/seata/server/session/GlobalSession.java:
##########
@@ -204,9 +204,17 @@ public boolean isTimeout() {
/**
* prevent could not handle committing and rollbacking transaction
+ *
+ * If the global session's status is "Rollbacked" or "TimeoutRollbacked", it returns the negative time since the session began,
+ * indicating that the session is already dead.
+ * For other statuses, it returns the remaining time until the session reaches the retry dead threshold.
+ *
* @return time to dead session. if not greater than 0, then deadSession
*/
public long timeToDeadSession() {
+ if (this.status == GlobalStatus.Rollbacked || this.status == GlobalStatus.TimeoutRollbacked) {
+ return beginTime - System.currentTimeMillis();
Review Comment:
> > RETRY_DEAD_THRESHOLD
>
> I think this can be done this way
Then no changes required?
> Then, would it be appropriate to create a RETRY_DEAD_THRESHOLD specifically for the end state?
or you mean this way?
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement Scheduled Handling for Rollbacked and TimeoutRollbacked Transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1955460898
##########
server/src/main/java/org/apache/seata/server/session/GlobalSession.java:
##########
@@ -204,9 +204,17 @@ public boolean isTimeout() {
/**
* prevent could not handle committing and rollbacking transaction
+ *
+ * If the global session's status is "Rollbacked" or "TimeoutRollbacked", it returns the negative time since the session began,
+ * indicating that the session is already dead.
+ * For other statuses, it returns the remaining time until the session reaches the retry dead threshold.
+ *
* @return time to dead session. if not greater than 0, then deadSession
*/
public long timeToDeadSession() {
+ if (this.status == GlobalStatus.Rollbacked || this.status == GlobalStatus.TimeoutRollbacked) {
+ return beginTime - System.currentTimeMillis();
Review Comment:
> > RETRY_DEAD_THRESHOLD
>
> I think this can be done this way
Then no changes required?
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement Scheduled Handling for Rollbacked and TimeoutRollbacked Transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1955426654
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -658,6 +724,8 @@ public void init() {
rollbackingSchedule(0);
committingSchedule(0);
+
+ rollbackedSchedule(0);
Review Comment:
> Sorry, I misread it. The issue I mentioned does not exist.
No worries! 🙂
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement Scheduled Handling for Rollbacked and TimeoutRollbacked Transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1953809604
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -189,12 +197,15 @@ public class DefaultCoordinator extends AbstractTCInboundHandler implements Tran
private final GlobalStatus[] retryRollbackingStatuses = new GlobalStatus[] {
GlobalStatus.TimeoutRollbacking,
- GlobalStatus.TimeoutRollbackRetrying, GlobalStatus.RollbackRetrying};
+ GlobalStatus.TimeoutRollbackRetrying,
+ GlobalStatus.RollbackRetrying
+ };
private final GlobalStatus[] retryCommittingStatuses = new GlobalStatus[] {GlobalStatus.CommitRetrying, GlobalStatus.Committed};
private final GlobalStatus[] rollbackingStatuses = new GlobalStatus[] {GlobalStatus.Rollbacking};
private final GlobalStatus[] committingStatuses = new GlobalStatus[] {GlobalStatus.Committing};
+ private final GlobalStatus[] rollbackedStatuses = new GlobalStatus[] {GlobalStatus.Rollbacked, GlobalStatus.TimeoutRollbacked};
Review Comment:
I will include the `CommitFailed`, `RollbackFailed`, `TimeoutRollbackFailed`, `Finished`, `CommitRetryTimeout`, and `RollbackRetryTimeout` states :)
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement scheduled handling for end status transaction [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1957743675
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -631,6 +644,64 @@ private void committingSchedule(long delay) {
delay, TimeUnit.MILLISECONDS);
}
+ /**
+ * Handle rollbacked by scheduled.
+ */
+ protected void handleEndStatesByScheduled() {
+ SessionCondition sessionCondition = new SessionCondition(endStatuses);
+ sessionCondition.setLazyLoadBranch(true);
+ List<GlobalSession> rollbackedSessions =
+ SessionHolder.getRootSessionManager().findGlobalSessions(sessionCondition);
+ if (CollectionUtils.isEmpty(rollbackedSessions)) {
+ rollbackedSchedule(RETRY_DEAD_THRESHOLD);
+ return;
+ }
+ long delay = END_STATUS_RETRY_PERIOD;
+ rollbackedSessions.sort(Comparator.comparingLong(GlobalSession::getBeginTime));
+ List<GlobalSession> needDoRollbackedSessions = new ArrayList<>();
+ for (GlobalSession rollbackedSession : rollbackedSessions) {
+ long time = rollbackedSession.timeToDeadSession();
+ if (time <= 0) {
+ needDoRollbackedSessions.add(rollbackedSession);
+ } else {
+ delay = Math.max(time, END_STATUS_RETRY_PERIOD);
+ break;
+ }
+ }
+ long now = System.currentTimeMillis();
+ SessionHelper.forEach(needDoRollbackedSessions, rollbackedSession -> {
+ try {
+ if (isRetryTimeout(now, MAX_ROLLBACK_RETRY_TIMEOUT, rollbackedSession.getBeginTime())) {
+ handleEndStateSession(rollbackedSession);
+ }
+ } catch (TransactionException ex) {
+ LOGGER.error("Failed to handle rollbacked [{}] {} {}", rollbackedSession.getXid(), ex.getCode(), ex.getMessage());
+ }
+ });
+ rollbackedSchedule(delay);
+ }
+
+ private void handleEndStateSession(GlobalSession globalSession) throws TransactionException {
+ GlobalStatus status = globalSession.getStatus();
+
+ if (status == GlobalStatus.CommitFailed) {
Review Comment:
Yes, I think it should be this way, encapsulating the processing logic in the SessionHelper to hide the internal implementation from the outside.
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] Add compensation handling for TimeoutRollbacked and Rollbacked states [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#issuecomment-2641736793
> > Do you use the DingTalk app?
>
> Unfortunately, no..
>
> However, if using DingTalk allows for better communication, I’m willing to install it!
Of course, email is also a great communication channel, but I would like to invite you to join the Seata contributors' DingTalk group if you're willing to install it. If you install it, please send your DingTalk ID to my email, and I will invite you to join the Seata contributors' group.
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] Add compensation handling for TimeoutRollbacked and Rollbacked states [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1942132868
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -189,7 +189,11 @@ public class DefaultCoordinator extends AbstractTCInboundHandler implements Tran
private final GlobalStatus[] retryRollbackingStatuses = new GlobalStatus[] {
GlobalStatus.TimeoutRollbacking,
- GlobalStatus.TimeoutRollbackRetrying, GlobalStatus.RollbackRetrying};
+ GlobalStatus.TimeoutRollbackRetrying,
+ GlobalStatus.RollbackRetrying,
+ GlobalStatus.TimeoutRollbacked,
+ GlobalStatus.Rollbacked
Review Comment:
> 由于rollback的概率是非常小的,并且rollbacked和TimeoutRollbacked的状态残留的概率更低,故这两种状态是特意放置在server重启时进行处理。 Since the probability of rollback is very low, and the chances of the rollbacked and TimeoutRollbacked states persisting are even lower, these two states are specifically handled during server restart.
Thank you for your comment :)
I didn’t fully understand.
```
Currently, in DefaultCoordinator, there is compensation handling for the committed state, but there is no compensation handling for the TimeoutRollbacked and Rollbacked states.
```
Based on the comment above, I added these two cases to the array for management.
If any changes are needed, could you please provide additional explanations?
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement Scheduled Handling for end status Transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1957088495
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -631,6 +645,60 @@ private void committingSchedule(long delay) {
delay, TimeUnit.MILLISECONDS);
}
+ /**
+ * Handle rollbacked by scheduled.
+ */
+ protected void handleRollbackedByScheduled() {
+ SessionCondition sessionCondition = new SessionCondition(rollbackedStatuses);
+ sessionCondition.setLazyLoadBranch(true);
+ List<GlobalSession> rollbackedSessions =
+ SessionHolder.getRootSessionManager().findGlobalSessions(sessionCondition);
+ if (CollectionUtils.isEmpty(rollbackedSessions)) {
+ rollbackedSchedule(RETRY_DEAD_THRESHOLD);
+ return;
+ }
+ long delay = ROLLBACKED_RETRY_PERIOD;
+ rollbackedSessions.sort(Comparator.comparingLong(GlobalSession::getBeginTime));
+ List<GlobalSession> needDoRollbackedSessions = new ArrayList<>();
+ for (GlobalSession rollbackedSession : rollbackedSessions) {
+ long time = rollbackedSession.timeToDeadSession();
+ if (time <= 0) {
+ needDoRollbackedSessions.add(rollbackedSession);
+ } else {
+ delay = Math.max(time, ROLLBACKED_RETRY_PERIOD);
+ break;
+ }
+ }
+ long now = System.currentTimeMillis();
+ SessionHelper.forEach(needDoRollbackedSessions, rollbackedSession -> {
+ try {
+ if (isRetryTimeout(now, MAX_ROLLBACK_RETRY_TIMEOUT, rollbackedSession.getBeginTime())) {
+
+ // commit retry timeout event
+ SessionHelper.endRollbackFailed(rollbackedSession, true, true);
+
+ //The function of this 'return' is 'continue'.
+ return;
+ }
+ core.doGlobalRollback(rollbackedSession, true);
Review Comment:
Done in https://github.com/apache/incubator-seata/pull/7133/commits/a7a9e5255b8f235758e9397ef29872f2386735d0 !
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement Scheduled Handling for Rollbacked and TimeoutRollbacked Transaction [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1955424099
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -658,6 +724,8 @@ public void init() {
rollbackingSchedule(0);
committingSchedule(0);
+
+ rollbackedSchedule(0);
Review Comment:
Sorry, I misread it. The issue I mentioned does not exist.
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement Scheduled Handling for end status Transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1957082838
##########
common/src/main/java/org/apache/seata/common/ConfigurationKeys.java:
##########
@@ -475,6 +475,11 @@ public interface ConfigurationKeys {
*/
String ROLLBACKING_RETRY_PERIOD = RECOVERY_PREFIX + "rollbackingRetryPeriod";
+ /**
+ * The constant ROLLBACKED_RETRY_PERIOD.
+ */
+ String ROLLBACKED_RETRY_PERIOD = RECOVERY_PREFIX + "rollbackedRetryPeriod";
Review Comment:
Done in https://github.com/apache/incubator-seata/pull/7133/commits/932c51fe7dd96c38d47f06e4e2ee375a9705baa6 !
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement scheduled handling for end status transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1958991067
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -189,12 +197,15 @@ public class DefaultCoordinator extends AbstractTCInboundHandler implements Tran
private final GlobalStatus[] retryRollbackingStatuses = new GlobalStatus[] {
GlobalStatus.TimeoutRollbacking,
- GlobalStatus.TimeoutRollbackRetrying, GlobalStatus.RollbackRetrying};
+ GlobalStatus.TimeoutRollbackRetrying,
+ GlobalStatus.RollbackRetrying
+ };
- private final GlobalStatus[] retryCommittingStatuses = new GlobalStatus[] {GlobalStatus.CommitRetrying, GlobalStatus.Committed};
+ private final GlobalStatus[] retryCommittingStatuses = new GlobalStatus[] {GlobalStatus.CommitRetrying};
private final GlobalStatus[] rollbackingStatuses = new GlobalStatus[] {GlobalStatus.Rollbacking};
private final GlobalStatus[] committingStatuses = new GlobalStatus[] {GlobalStatus.Committing};
+ private final GlobalStatus[] endStatuses = new GlobalStatus[] {GlobalStatus.Rollbacked, GlobalStatus.Committed, GlobalStatus.Finished};
Review Comment:
```suggestion
private final GlobalStatus[] endStatuses = new GlobalStatus[] {GlobalStatus.Rollbacked, GlobalStatus.TimeoutRollbacked, GlobalStatus.Committed, GlobalStatus.Finished};
```
##########
server/src/main/java/org/apache/seata/server/session/SessionHelper.java:
##########
@@ -454,6 +454,22 @@ public static void removeAllBranch(GlobalSession globalSession, boolean isAsync)
}
}
+ public static void processEndState(GlobalSession globalSession) throws TransactionException {
+ GlobalStatus globalStatus = globalSession.getStatus();
+
+ switch (globalStatus) {
+ case Committed:
+ case Finished:
+ endCommitted(globalSession, true);
+ return;
+ case Rollbacked:
+ endRollbacked(globalSession, true);
Review Comment:
```suggestion
case Rollbacked:
case TimeoutRollbacked:
endRollbacked(globalSession, true);
```
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement scheduled handling for end status transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1958994078
##########
server/src/main/java/org/apache/seata/server/session/GlobalSession.java:
##########
@@ -203,13 +211,31 @@ public boolean isTimeout() {
}
/**
- * prevent could not handle committing and rollbacking transaction
+ * prevent could not handle committing, rollbacking and rollbacked transaction
+ *
+ * If the global session's status is in end status, it returns the remaining time until the session reaches
+ * the end state retry dead threshold.
+ * For other statuses, it returns the remaining time until the session reaches the retry dead threshold.
+ *
* @return time to dead session. if not greater than 0, then deadSession
*/
public long timeToDeadSession() {
+ if (isEndStatus()) {
+ return beginTime + END_STATE_RETRY_DEAD_THRESHOLD - System.currentTimeMillis();
+ }
return beginTime + RETRY_DEAD_THRESHOLD - System.currentTimeMillis();
}
+ private boolean isEndStatus() {
+ EnumSet<GlobalStatus> endStatuses = EnumSet.of(
+ GlobalStatus.Rollbacked,
+ GlobalStatus.TimeoutRollbacked,
+ GlobalStatus.Committed,
+ GlobalStatus.Finished
+ );
+ return deadStatuses.contains(this.status);
Review Comment:
```suggestion
return endStatuses.contains(this.status);
```
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement scheduled handling for end status transaction [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1958979750
##########
server/src/main/java/org/apache/seata/server/session/GlobalSession.java:
##########
@@ -203,13 +211,33 @@ public boolean isTimeout() {
}
/**
- * prevent could not handle committing and rollbacking transaction
+ * prevent could not handle committing, rollbacking and rollbacked transaction
+ *
+ * If the global session's status is in end status, it returns the remaining time until the session reaches
+ * the end state retry dead threshold.
+ * For other statuses, it returns the remaining time until the session reaches the retry dead threshold.
+ *
* @return time to dead session. if not greater than 0, then deadSession
*/
public long timeToDeadSession() {
+ if (isEndStatus()) {
+ return beginTime + END_STATE_RETRY_DEAD_THRESHOLD - System.currentTimeMillis();
+ }
return beginTime + RETRY_DEAD_THRESHOLD - System.currentTimeMillis();
}
+ private boolean isEndStatus() {
+ EnumSet<GlobalStatus> deadStatuses = EnumSet.of(
+ GlobalStatus.Rollbacked,
+ GlobalStatus.TimeoutRollbacked,
+ GlobalStatus.CommitFailed,
+ GlobalStatus.RollbackFailed,
+ GlobalStatus.TimeoutRollbackFailed,
+ GlobalStatus.Finished
+ );
Review Comment:
This is okay
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] Add compensation handling for TimeoutRollbacked and Rollbacked states [incubator-seata]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#issuecomment-2644532785
## [Codecov](https://app.codecov.io/gh/apache/incubator-seata/pull/7133?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
Attention: Patch coverage is `0%` with `2 lines` in your changes missing coverage. Please review.
> Project coverage is 51.77%. Comparing base [(`b11cc1d`)](https://app.codecov.io/gh/apache/incubator-seata/commit/b11cc1d1521b99a040170d9d8a5ea6b47f43a2dd?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`4e21ee1`)](https://app.codecov.io/gh/apache/incubator-seata/commit/4e21ee1e9941d385c86c41bb22f8c05fa3737455?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
| [Files with missing lines](https://app.codecov.io/gh/apache/incubator-seata/pull/7133?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [...e/seata/server/coordinator/DefaultCoordinator.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7133?src=pr&el=tree&filepath=server%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fserver%2Fcoordinator%2FDefaultCoordinator.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2VydmVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zZWF0YS9zZXJ2ZXIvY29vcmRpbmF0b3IvRGVmYXVsdENvb3JkaW5hdG9yLmphdmE=) | 0.00% | [1 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/incubator-seata/pull/7133?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
[](https://app.codecov.io/gh/apache/incubator-seata/pull/7133?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
```diff
@@ Coverage Diff @@
## 2.x #7133 +/- ##
============================================
- Coverage 51.79% 51.77% -0.02%
+ Complexity 6755 6752 -3
============================================
Files 1151 1151
Lines 40970 40972 +2
Branches 4803 4804 +1
============================================
- Hits 21220 21213 -7
- Misses 17755 17764 +9
Partials 1995 1995
```
| [Files with missing lines](https://app.codecov.io/gh/apache/incubator-seata/pull/7133?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [...e/seata/server/coordinator/DefaultCoordinator.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7133?src=pr&el=tree&filepath=server%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fserver%2Fcoordinator%2FDefaultCoordinator.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2VydmVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zZWF0YS9zZXJ2ZXIvY29vcmRpbmF0b3IvRGVmYXVsdENvb3JkaW5hdG9yLmphdmE=) | `39.75% <0.00%> (-0.25%)` | :arrow_down: |
... and [3 files with indirect coverage changes](https://app.codecov.io/gh/apache/incubator-seata/pull/7133/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
</details>
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement Scheduled Handling for Rollbacked and TimeoutRollbacked Transaction [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1955455966
##########
server/src/main/java/org/apache/seata/server/session/GlobalSession.java:
##########
@@ -204,9 +204,17 @@ public boolean isTimeout() {
/**
* prevent could not handle committing and rollbacking transaction
+ *
+ * If the global session's status is "Rollbacked" or "TimeoutRollbacked", it returns the negative time since the session began,
+ * indicating that the session is already dead.
+ * For other statuses, it returns the remaining time until the session reaches the retry dead threshold.
+ *
* @return time to dead session. if not greater than 0, then deadSession
*/
public long timeToDeadSession() {
+ if (this.status == GlobalStatus.Rollbacked || this.status == GlobalStatus.TimeoutRollbacked) {
+ return beginTime - System.currentTimeMillis();
Review Comment:
> RETRY_DEAD_THRESHOLD
I think this can be done this way
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement Scheduled Handling for end status Transaction [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1957109454
##########
script/config-center/config.txt:
##########
@@ -153,6 +153,7 @@ store.redis.queryLimit=100
server.recovery.committingRetryPeriod=1000
server.recovery.asynCommittingRetryPeriod=1000
server.recovery.rollbackingRetryPeriod=1000
+server.recovery.endstatusRetryPeriod=1000
Review Comment:
```suggestion
server.recovery.endstatusRetryPeriod=10000
```
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement Scheduled Handling for end status Transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1957112929
##########
common/src/main/java/org/apache/seata/common/DefaultValues.java:
##########
@@ -397,6 +402,11 @@ public interface DefaultValues {
*/
int DEFAULT_ROLLBACKING_RETRY_PERIOD = 1000;
+ /**
+ * the constant DEFAULT_END_STATUS_RETRY_PERIOD
+ */
+ int DEFAULT_END_STATUS_RETRY_PERIOD = 1000;
Review Comment:
Done in https://github.com/apache/incubator-seata/pull/7133/commits/05735298ecc9a2f49f05ec9f413289f98931ed49 :)
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement scheduled handling for end status transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1958930164
##########
server/src/main/java/org/apache/seata/server/session/GlobalSession.java:
##########
@@ -203,13 +211,33 @@ public boolean isTimeout() {
}
/**
- * prevent could not handle committing and rollbacking transaction
+ * prevent could not handle committing, rollbacking and rollbacked transaction
+ *
+ * If the global session's status is in end status, it returns the remaining time until the session reaches
+ * the end state retry dead threshold.
+ * For other statuses, it returns the remaining time until the session reaches the retry dead threshold.
+ *
* @return time to dead session. if not greater than 0, then deadSession
*/
public long timeToDeadSession() {
+ if (isEndStatus()) {
+ return beginTime + END_STATE_RETRY_DEAD_THRESHOLD - System.currentTimeMillis();
+ }
return beginTime + RETRY_DEAD_THRESHOLD - System.currentTimeMillis();
}
+ private boolean isEndStatus() {
+ EnumSet<GlobalStatus> deadStatuses = EnumSet.of(
+ GlobalStatus.Rollbacked,
+ GlobalStatus.TimeoutRollbacked,
+ GlobalStatus.CommitFailed,
+ GlobalStatus.RollbackFailed,
+ GlobalStatus.TimeoutRollbackFailed,
+ GlobalStatus.Finished
+ );
Review Comment:
```suggestion
EnumSet<GlobalStatus> endStatuses = EnumSet.of(
GlobalStatus.Rollbacked,
GlobalStatus.TimeoutRollbacked,
GlobalStatus.Committed,
GlobalStatus.Finished
);
```
@funky-eyes
WDYT?
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement scheduled handling for end status transaction [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#issuecomment-2664475164
For the reasons I mentioned earlier:
1. IO exceptions, such as disk or network issues
2. Process crashes (whether it's the seata-server or the database, etc.)
In the above points or some examples I did not mention, transactions are not deleted in the end state, leaving residual data.
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement Scheduled Handling for Rollbacked and TimeoutRollbacked Transaction [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1953639147
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -189,12 +197,15 @@ public class DefaultCoordinator extends AbstractTCInboundHandler implements Tran
private final GlobalStatus[] retryRollbackingStatuses = new GlobalStatus[] {
GlobalStatus.TimeoutRollbacking,
- GlobalStatus.TimeoutRollbackRetrying, GlobalStatus.RollbackRetrying};
+ GlobalStatus.TimeoutRollbackRetrying,
+ GlobalStatus.RollbackRetrying
+ };
private final GlobalStatus[] retryCommittingStatuses = new GlobalStatus[] {GlobalStatus.CommitRetrying, GlobalStatus.Committed};
private final GlobalStatus[] rollbackingStatuses = new GlobalStatus[] {GlobalStatus.Rollbacking};
private final GlobalStatus[] committingStatuses = new GlobalStatus[] {GlobalStatus.Committing};
+ private final GlobalStatus[] rollbackedStatuses = new GlobalStatus[] {GlobalStatus.Rollbacked, GlobalStatus.TimeoutRollbacked};
Review Comment:
Why not process transactions in other end states together?
##########
server/src/main/java/org/apache/seata/server/session/GlobalSession.java:
##########
@@ -204,9 +204,17 @@ public boolean isTimeout() {
/**
* prevent could not handle committing and rollbacking transaction
+ *
+ * If the global session's status is "Rollbacked" or "TimeoutRollbacked", it returns the negative time since the session began,
+ * indicating that the session is already dead.
+ * For other statuses, it returns the remaining time until the session reaches the retry dead threshold.
+ *
* @return time to dead session. if not greater than 0, then deadSession
*/
public long timeToDeadSession() {
+ if (this.status == GlobalStatus.Rollbacked || this.status == GlobalStatus.TimeoutRollbacked) {
+ return beginTime - System.currentTimeMillis();
Review Comment:
The beginTime does not change after the creation of the global session, which will cause any global session to be added to the needDoRollbackedSessions list.
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -658,6 +724,8 @@ public void init() {
rollbackingSchedule(0);
committingSchedule(0);
+
+ rollbackedSchedule(0);
Review Comment:
The methods `rollbackingSchedule`, `committingSchedule`, and `rollbackedSchedule` need to use the `SessionHolder.distributedLockAndExecute` method to ensure thread safety in a distributed environment.
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement Scheduled Handling for end status Transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1957088827
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -631,6 +645,60 @@ private void committingSchedule(long delay) {
delay, TimeUnit.MILLISECONDS);
}
+ /**
+ * Handle rollbacked by scheduled.
+ */
+ protected void handleRollbackedByScheduled() {
+ SessionCondition sessionCondition = new SessionCondition(rollbackedStatuses);
+ sessionCondition.setLazyLoadBranch(true);
+ List<GlobalSession> rollbackedSessions =
+ SessionHolder.getRootSessionManager().findGlobalSessions(sessionCondition);
+ if (CollectionUtils.isEmpty(rollbackedSessions)) {
+ rollbackedSchedule(RETRY_DEAD_THRESHOLD);
+ return;
+ }
+ long delay = ROLLBACKED_RETRY_PERIOD;
+ rollbackedSessions.sort(Comparator.comparingLong(GlobalSession::getBeginTime));
+ List<GlobalSession> needDoRollbackedSessions = new ArrayList<>();
+ for (GlobalSession rollbackedSession : rollbackedSessions) {
+ long time = rollbackedSession.timeToDeadSession();
+ if (time <= 0) {
+ needDoRollbackedSessions.add(rollbackedSession);
+ } else {
+ delay = Math.max(time, ROLLBACKED_RETRY_PERIOD);
+ break;
+ }
+ }
+ long now = System.currentTimeMillis();
+ SessionHelper.forEach(needDoRollbackedSessions, rollbackedSession -> {
+ try {
+ if (isRetryTimeout(now, MAX_ROLLBACK_RETRY_TIMEOUT, rollbackedSession.getBeginTime())) {
+
+ // commit retry timeout event
+ SessionHelper.endRollbackFailed(rollbackedSession, true, true);
+
+ //The function of this 'return' is 'continue'.
+ return;
+ }
+ core.doGlobalRollback(rollbackedSession, true);
Review Comment:
@funky-eyes
When you have time, I would appreciate it if you could review this comment along with the issue below.
- https://github.com/apache/incubator-seata/issues/6774
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement scheduled handling for end status transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#issuecomment-2664352827
> I believe the `committed` state should be handled within the `end` state task, and transactions in a failed state should not be retried. Failed transactions need to be addressed by the operations team, rather than being handled by scheduled tasks.
Good idea!
I agree with you
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement scheduled handling for end status transaction [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes merged PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement scheduled handling for end status transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#issuecomment-2664594426
@funky-eyes
Is there anything else left to do?
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement scheduled handling for end status transaction [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1957250018
##########
common/src/main/java/org/apache/seata/common/DefaultValues.java:
##########
@@ -397,6 +402,11 @@ public interface DefaultValues {
*/
int DEFAULT_ROLLBACKING_RETRY_PERIOD = 1000;
+ /**
+ * the constant DEFAULT_END_STATUS_RETRY_PERIOD
+ */
+ int DEFAULT_END_STATUS_RETRY_PERIOD = 30;
Review Comment:
```suggestion
int DEFAULT_END_STATUS_RETRY_PERIOD = 30 * 1000;
```
##########
changes/zh-cn/2.x.md:
##########
@@ -9,6 +9,7 @@
- [[#7037](https://github.com/apache/incubator-seata/pull/7037)] 支持UndoLog的fury序列化方式
- [[#7069](https://github.com/apache/incubator-seata/pull/7069)] Raft集群模式支持地址转换
- [[#7038](https://github.com/apache/incubator-seata/pull/7038)] 支持Fury序列化器
+- [[#7133](https://github.com/apache/incubator-seata/pull/7133)] 实现对已回滚和超时回滚事务的定时处理
Review Comment:
```suggestion
- [[#7133](https://github.com/apache/incubator-seata/pull/7133)] 实现对残留的end状态事务定时处理
```
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement Scheduled Handling for Rollbacked and TimeoutRollbacked Transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1955423749
##########
server/src/main/java/org/apache/seata/server/session/GlobalSession.java:
##########
@@ -204,9 +204,17 @@ public boolean isTimeout() {
/**
* prevent could not handle committing and rollbacking transaction
+ *
+ * If the global session's status is "Rollbacked" or "TimeoutRollbacked", it returns the negative time since the session began,
+ * indicating that the session is already dead.
+ * For other statuses, it returns the remaining time until the session reaches the retry dead threshold.
+ *
* @return time to dead session. if not greater than 0, then deadSession
*/
public long timeToDeadSession() {
+ if (this.status == GlobalStatus.Rollbacked || this.status == GlobalStatus.TimeoutRollbacked) {
+ return beginTime - System.currentTimeMillis();
Review Comment:
@funky-eyes
Then, would it be appropriate to create a `RETRY_DEAD_THRESHOLD` specifically for the end state?
> Of course, this timeToDeadSession method is more relevant for ongoing statuses like "rollbacking" or "committing." For transactions in the "end" status, I believe the interval can be shortened.
As suggested in the discussion, since we can reduce the interval in the end state, I believe decreasing the size of `RETRY_DEAD_THRESHOLD` could be a reasonable approach.
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement Scheduled Handling for Rollbacked and TimeoutRollbacked Transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1956314769
##########
server/src/main/java/org/apache/seata/server/session/GlobalSession.java:
##########
@@ -204,9 +204,17 @@ public boolean isTimeout() {
/**
* prevent could not handle committing and rollbacking transaction
+ *
+ * If the global session's status is "Rollbacked" or "TimeoutRollbacked", it returns the negative time since the session began,
+ * indicating that the session is already dead.
+ * For other statuses, it returns the remaining time until the session reaches the retry dead threshold.
+ *
* @return time to dead session. if not greater than 0, then deadSession
*/
public long timeToDeadSession() {
+ if (this.status == GlobalStatus.Rollbacked || this.status == GlobalStatus.TimeoutRollbacked) {
+ return beginTime - System.currentTimeMillis();
Review Comment:
Done in https://github.com/apache/incubator-seata/pull/7133/commits/997775c07c4e946b39e4cc85cd9a42dc79c3d145 !
PTAL ⚡️
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] Add compensation handling for TimeoutRollbacked and Rollbacked states [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1952352985
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -189,7 +189,11 @@ public class DefaultCoordinator extends AbstractTCInboundHandler implements Tran
private final GlobalStatus[] retryRollbackingStatuses = new GlobalStatus[] {
GlobalStatus.TimeoutRollbacking,
- GlobalStatus.TimeoutRollbackRetrying, GlobalStatus.RollbackRetrying};
+ GlobalStatus.TimeoutRollbackRetrying,
+ GlobalStatus.RollbackRetrying,
+ GlobalStatus.TimeoutRollbacked,
+ GlobalStatus.Rollbacked
Review Comment:
@funky-eyes
Done in https://github.com/apache/incubator-seata/pull/7133 !
PTAL ⚡️
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement Scheduled Handling for Rollbacked and TimeoutRollbacked Transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1953801256
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -658,6 +724,8 @@ public void init() {
rollbackingSchedule(0);
committingSchedule(0);
+
+ rollbackedSchedule(0);
Review Comment:
```java
boolean called = SessionHolder.distributedLockAndExecute(ROLLBACKED, this::handleRollbackedByScheduled);
```
Aren’t we already using `SessionHolder.distributedLockAndExecute`?
Are you suggesting that the `rollbackingSchedule`, `committingSchedule`, and `rollbackedSchedule` methods should be explicitly called using the `SessionHolder.distributedLockAndExecute` API?
> It seems difficult because distributedLockAndExecute requires a parameterless function.
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement scheduled handling for end status transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1957516492
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -631,6 +644,64 @@ private void committingSchedule(long delay) {
delay, TimeUnit.MILLISECONDS);
}
+ /**
+ * Handle rollbacked by scheduled.
+ */
+ protected void handleEndStatesByScheduled() {
+ SessionCondition sessionCondition = new SessionCondition(endStatuses);
+ sessionCondition.setLazyLoadBranch(true);
+ List<GlobalSession> rollbackedSessions =
+ SessionHolder.getRootSessionManager().findGlobalSessions(sessionCondition);
+ if (CollectionUtils.isEmpty(rollbackedSessions)) {
+ rollbackedSchedule(RETRY_DEAD_THRESHOLD);
+ return;
+ }
+ long delay = END_STATUS_RETRY_PERIOD;
+ rollbackedSessions.sort(Comparator.comparingLong(GlobalSession::getBeginTime));
+ List<GlobalSession> needDoRollbackedSessions = new ArrayList<>();
+ for (GlobalSession rollbackedSession : rollbackedSessions) {
+ long time = rollbackedSession.timeToDeadSession();
+ if (time <= 0) {
+ needDoRollbackedSessions.add(rollbackedSession);
+ } else {
+ delay = Math.max(time, END_STATUS_RETRY_PERIOD);
+ break;
+ }
+ }
+ long now = System.currentTimeMillis();
+ SessionHelper.forEach(needDoRollbackedSessions, rollbackedSession -> {
+ try {
+ if (isRetryTimeout(now, MAX_ROLLBACK_RETRY_TIMEOUT, rollbackedSession.getBeginTime())) {
+ handleEndStateSession(rollbackedSession);
+ }
+ } catch (TransactionException ex) {
+ LOGGER.error("Failed to handle rollbacked [{}] {} {}", rollbackedSession.getXid(), ex.getCode(), ex.getMessage());
+ }
+ });
+ rollbackedSchedule(delay);
+ }
+
+ private void handleEndStateSession(GlobalSession globalSession) throws TransactionException {
+ GlobalStatus status = globalSession.getStatus();
+
+ if (status == GlobalStatus.CommitFailed) {
Review Comment:
As I understand it, instead of directly managing the transaction end states with conditional statements in `handleEndStateSession`, the `responsibility` is being delegated to `SessionHelper`.
Is my understanding correct?
Below is the implementation based on my understanding.
```java
private void handleEndStateSession(GlobalSession globalSession) throws TransactionException {
SessionHelper.processEndState(globalSession);
}
```
**The state values are just examples.**
```java
public class SessionHelper {
public static void processEndState(GlobalSession globalSession) throws TransactionException {
GlobalStatus status = globalSession.getStatus();
switch (status) {
case Committed:
case CommitSuccess:
endCommitted(globalSession, false);
break;
case CommitFailed:
case CommitPending:
endCommitted(globalSession, true);
break;
case Rollbacked:
case RollbackSuccess:
endRollbacked(globalSession, false);
break;
case RollbackFailed:
case RollbackPending:
endRollbacked(globalSession, true);
break;
default:
log.warn("Unknown transaction state: {}", status);
}
}
}
```
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] Add compensation handling for TimeoutRollbacked and Rollbacked states [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1942263419
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -189,7 +189,11 @@ public class DefaultCoordinator extends AbstractTCInboundHandler implements Tran
private final GlobalStatus[] retryRollbackingStatuses = new GlobalStatus[] {
GlobalStatus.TimeoutRollbacking,
- GlobalStatus.TimeoutRollbackRetrying, GlobalStatus.RollbackRetrying};
+ GlobalStatus.TimeoutRollbackRetrying,
+ GlobalStatus.RollbackRetrying,
+ GlobalStatus.TimeoutRollbacked,
+ GlobalStatus.Rollbacked
Review Comment:
> If you think it is necessary to handle rollbacked transactions during runtime, I suggest that you create a separate scheduled task to batch process transactions in the rollbacked and committed states, rather than blocking transactions that urgently need to be rolled back and retried.
Thank you for your suggestion!
The idea you proposed is very interesting, and I’m planning to work on it. :)
Additionally, I’ve posted a message on the Seata project’s issue list and mailing list regarding this topic.
I’ll leave the links below—could you kindly take a look when you have a chance?
- https://lists.apache.org/thread/xlkshkqs5v2hflp10jgz418kos8vwrsc
- https://github.com/apache/incubator-seata/issues/6774
Thanks again! 🚀
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] Add compensation handling for TimeoutRollbacked and Rollbacked states [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1942128559
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -189,7 +189,11 @@ public class DefaultCoordinator extends AbstractTCInboundHandler implements Tran
private final GlobalStatus[] retryRollbackingStatuses = new GlobalStatus[] {
GlobalStatus.TimeoutRollbacking,
- GlobalStatus.TimeoutRollbackRetrying, GlobalStatus.RollbackRetrying};
+ GlobalStatus.TimeoutRollbackRetrying,
+ GlobalStatus.RollbackRetrying,
+ GlobalStatus.TimeoutRollbacked,
+ GlobalStatus.Rollbacked
Review Comment:
由于rollback的概率是非常小的,并且rollbacked和TimeoutRollbacked的状态残留的概率更低,故这两种状态是特意放置在server重启时进行处理。
Since the probability of rollback is very low, and the chances of the rollbacked and TimeoutRollbacked states persisting are even lower, these two states are specifically handled during server restart.
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement scheduled handling for end status transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#issuecomment-2664406273
> I believe the `committed` state should be handled within the `end` state task, and transactions in a failed state should not be retried. Failed transactions need to be addressed by the operations team, rather than being handled by scheduled tasks.
That sounds like a good point.
However, while going through your comment, a few questions came to mind:
1. Could you explain the situations where retrying the `endStatus` session would be necessary?
2. If that approach is taken, does it still fail to resolve the `issue` mentioned?
- https://github.com/apache/incubator-seata/issues/6875
3. Lastly, was this PR ultimately decided to simply retry the end status session, or was there another approach considered?
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement scheduled handling for end status transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1958986971
##########
server/src/main/java/org/apache/seata/server/session/GlobalSession.java:
##########
@@ -203,13 +211,33 @@ public boolean isTimeout() {
}
/**
- * prevent could not handle committing and rollbacking transaction
+ * prevent could not handle committing, rollbacking and rollbacked transaction
+ *
+ * If the global session's status is in end status, it returns the remaining time until the session reaches
+ * the end state retry dead threshold.
+ * For other statuses, it returns the remaining time until the session reaches the retry dead threshold.
+ *
* @return time to dead session. if not greater than 0, then deadSession
*/
public long timeToDeadSession() {
+ if (isEndStatus()) {
+ return beginTime + END_STATE_RETRY_DEAD_THRESHOLD - System.currentTimeMillis();
+ }
return beginTime + RETRY_DEAD_THRESHOLD - System.currentTimeMillis();
}
+ private boolean isEndStatus() {
+ EnumSet<GlobalStatus> deadStatuses = EnumSet.of(
+ GlobalStatus.Rollbacked,
+ GlobalStatus.TimeoutRollbacked,
+ GlobalStatus.CommitFailed,
+ GlobalStatus.RollbackFailed,
+ GlobalStatus.TimeoutRollbackFailed,
+ GlobalStatus.Finished
+ );
Review Comment:
No worries 😉
I'll fix it.
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement Scheduled Handling for Rollbacked and TimeoutRollbacked Transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1956286688
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -189,12 +197,15 @@ public class DefaultCoordinator extends AbstractTCInboundHandler implements Tran
private final GlobalStatus[] retryRollbackingStatuses = new GlobalStatus[] {
GlobalStatus.TimeoutRollbacking,
- GlobalStatus.TimeoutRollbackRetrying, GlobalStatus.RollbackRetrying};
+ GlobalStatus.TimeoutRollbackRetrying,
+ GlobalStatus.RollbackRetrying
+ };
private final GlobalStatus[] retryCommittingStatuses = new GlobalStatus[] {GlobalStatus.CommitRetrying, GlobalStatus.Committed};
private final GlobalStatus[] rollbackingStatuses = new GlobalStatus[] {GlobalStatus.Rollbacking};
private final GlobalStatus[] committingStatuses = new GlobalStatus[] {GlobalStatus.Committing};
+ private final GlobalStatus[] rollbackedStatuses = new GlobalStatus[] {GlobalStatus.Rollbacked, GlobalStatus.TimeoutRollbacked};
Review Comment:
Done in https://github.com/apache/incubator-seata/pull/7133/commits/a9ec30f61e8d70815ca73e21f7dd22c54f5bb5ab !
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] Add compensation handling for TimeoutRollbacked and Rollbacked states [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#issuecomment-2641680385
> Do you use the DingTalk app?
Unfortunately, no..
However, if using DingTalk allows for better communication, I’m willing to install it!
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] Add compensation handling for TimeoutRollbacked and Rollbacked states [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#issuecomment-2641638241
Do you use the DingTalk app?
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement Scheduled Handling for end status Transaction [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1957112141
##########
common/src/main/java/org/apache/seata/common/DefaultValues.java:
##########
@@ -397,6 +402,11 @@ public interface DefaultValues {
*/
int DEFAULT_ROLLBACKING_RETRY_PERIOD = 1000;
+ /**
+ * the constant DEFAULT_END_STATUS_RETRY_PERIOD
+ */
+ int DEFAULT_END_STATUS_RETRY_PERIOD = 1000;
Review Comment:
I believe that for transactions in the end state, they should not be processed with such high frequency, because the probability of end state transactions not being processed by the business thread is very low. Thirty seconds might be more appropriate.
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement Scheduled Handling for end status Transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1957088827
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -631,6 +645,60 @@ private void committingSchedule(long delay) {
delay, TimeUnit.MILLISECONDS);
}
+ /**
+ * Handle rollbacked by scheduled.
+ */
+ protected void handleRollbackedByScheduled() {
+ SessionCondition sessionCondition = new SessionCondition(rollbackedStatuses);
+ sessionCondition.setLazyLoadBranch(true);
+ List<GlobalSession> rollbackedSessions =
+ SessionHolder.getRootSessionManager().findGlobalSessions(sessionCondition);
+ if (CollectionUtils.isEmpty(rollbackedSessions)) {
+ rollbackedSchedule(RETRY_DEAD_THRESHOLD);
+ return;
+ }
+ long delay = ROLLBACKED_RETRY_PERIOD;
+ rollbackedSessions.sort(Comparator.comparingLong(GlobalSession::getBeginTime));
+ List<GlobalSession> needDoRollbackedSessions = new ArrayList<>();
+ for (GlobalSession rollbackedSession : rollbackedSessions) {
+ long time = rollbackedSession.timeToDeadSession();
+ if (time <= 0) {
+ needDoRollbackedSessions.add(rollbackedSession);
+ } else {
+ delay = Math.max(time, ROLLBACKED_RETRY_PERIOD);
+ break;
+ }
+ }
+ long now = System.currentTimeMillis();
+ SessionHelper.forEach(needDoRollbackedSessions, rollbackedSession -> {
+ try {
+ if (isRetryTimeout(now, MAX_ROLLBACK_RETRY_TIMEOUT, rollbackedSession.getBeginTime())) {
+
+ // commit retry timeout event
+ SessionHelper.endRollbackFailed(rollbackedSession, true, true);
+
+ //The function of this 'return' is 'continue'.
+ return;
+ }
+ core.doGlobalRollback(rollbackedSession, true);
Review Comment:
@funky-eyes
When you have time, I would appreciate it if you could review this comment and the issue below.
- https://github.com/apache/incubator-seata/issues/6774
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement Scheduled Handling for end status Transaction [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1957109454
##########
script/config-center/config.txt:
##########
@@ -153,6 +153,7 @@ store.redis.queryLimit=100
server.recovery.committingRetryPeriod=1000
server.recovery.asynCommittingRetryPeriod=1000
server.recovery.rollbackingRetryPeriod=1000
+server.recovery.endstatusRetryPeriod=1000
Review Comment:
```suggestion
server.recovery.endstatusRetryPeriod=10000
```
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement scheduled handling for end status transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1957919591
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -631,6 +644,64 @@ private void committingSchedule(long delay) {
delay, TimeUnit.MILLISECONDS);
}
+ /**
+ * Handle rollbacked by scheduled.
+ */
+ protected void handleEndStatesByScheduled() {
+ SessionCondition sessionCondition = new SessionCondition(endStatuses);
+ sessionCondition.setLazyLoadBranch(true);
+ List<GlobalSession> rollbackedSessions =
+ SessionHolder.getRootSessionManager().findGlobalSessions(sessionCondition);
+ if (CollectionUtils.isEmpty(rollbackedSessions)) {
+ rollbackedSchedule(RETRY_DEAD_THRESHOLD);
+ return;
+ }
+ long delay = END_STATUS_RETRY_PERIOD;
+ rollbackedSessions.sort(Comparator.comparingLong(GlobalSession::getBeginTime));
+ List<GlobalSession> needDoRollbackedSessions = new ArrayList<>();
+ for (GlobalSession rollbackedSession : rollbackedSessions) {
+ long time = rollbackedSession.timeToDeadSession();
+ if (time <= 0) {
+ needDoRollbackedSessions.add(rollbackedSession);
+ } else {
+ delay = Math.max(time, END_STATUS_RETRY_PERIOD);
+ break;
+ }
+ }
+ long now = System.currentTimeMillis();
+ SessionHelper.forEach(needDoRollbackedSessions, rollbackedSession -> {
+ try {
+ if (isRetryTimeout(now, MAX_ROLLBACK_RETRY_TIMEOUT, rollbackedSession.getBeginTime())) {
+ handleEndStateSession(rollbackedSession);
+ }
+ } catch (TransactionException ex) {
+ LOGGER.error("Failed to handle rollbacked [{}] {} {}", rollbackedSession.getXid(), ex.getCode(), ex.getMessage());
+ }
+ });
+ rollbackedSchedule(delay);
+ }
+
+ private void handleEndStateSession(GlobalSession globalSession) throws TransactionException {
+ GlobalStatus status = globalSession.getStatus();
+
+ if (status == GlobalStatus.CommitFailed) {
Review Comment:
Done in https://github.com/apache/incubator-seata/pull/7133/commits/5837ae6b0e090af8cbe435f47528a40f68d6feaf !
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement scheduled handling for end status transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1957930967
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -631,6 +645,60 @@ private void committingSchedule(long delay) {
delay, TimeUnit.MILLISECONDS);
}
+ /**
+ * Handle rollbacked by scheduled.
+ */
+ protected void handleRollbackedByScheduled() {
Review Comment:
@funky-eyes
Is there a specific reason why you used `state` instead of `status`?
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement scheduled handling for end status transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#issuecomment-2662607710
@funky-eyes
You can see in the comment that the word `rollbacked` has been changed to `status`. https://github.com/apache/incubator-seata/pull/7133/commits/113a7fd66cfad29f76c64dd577fb86b021619358
Please take a look and provide your feedback.
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement scheduled handling for end status transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1958930164
##########
server/src/main/java/org/apache/seata/server/session/GlobalSession.java:
##########
@@ -203,13 +211,33 @@ public boolean isTimeout() {
}
/**
- * prevent could not handle committing and rollbacking transaction
+ * prevent could not handle committing, rollbacking and rollbacked transaction
+ *
+ * If the global session's status is in end status, it returns the remaining time until the session reaches
+ * the end state retry dead threshold.
+ * For other statuses, it returns the remaining time until the session reaches the retry dead threshold.
+ *
* @return time to dead session. if not greater than 0, then deadSession
*/
public long timeToDeadSession() {
+ if (isEndStatus()) {
+ return beginTime + END_STATE_RETRY_DEAD_THRESHOLD - System.currentTimeMillis();
+ }
return beginTime + RETRY_DEAD_THRESHOLD - System.currentTimeMillis();
}
+ private boolean isEndStatus() {
+ EnumSet<GlobalStatus> deadStatuses = EnumSet.of(
+ GlobalStatus.Rollbacked,
+ GlobalStatus.TimeoutRollbacked,
+ GlobalStatus.CommitFailed,
+ GlobalStatus.RollbackFailed,
+ GlobalStatus.TimeoutRollbackFailed,
+ GlobalStatus.Finished
+ );
Review Comment:
```suggestion
EnumSet<GlobalStatus> endStatuses = EnumSet.of(
GlobalStatus.Rollbacked,
GlobalStatus.Committed,
GlobalStatus.Finished
);
```
@funky-eyes
WDYT?
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement scheduled handling for end status transaction [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1957481470
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -631,6 +644,64 @@ private void committingSchedule(long delay) {
delay, TimeUnit.MILLISECONDS);
}
+ /**
+ * Handle rollbacked by scheduled.
+ */
+ protected void handleEndStatesByScheduled() {
+ SessionCondition sessionCondition = new SessionCondition(endStatuses);
+ sessionCondition.setLazyLoadBranch(true);
+ List<GlobalSession> rollbackedSessions =
+ SessionHolder.getRootSessionManager().findGlobalSessions(sessionCondition);
+ if (CollectionUtils.isEmpty(rollbackedSessions)) {
+ rollbackedSchedule(RETRY_DEAD_THRESHOLD);
+ return;
+ }
+ long delay = END_STATUS_RETRY_PERIOD;
+ rollbackedSessions.sort(Comparator.comparingLong(GlobalSession::getBeginTime));
+ List<GlobalSession> needDoRollbackedSessions = new ArrayList<>();
+ for (GlobalSession rollbackedSession : rollbackedSessions) {
+ long time = rollbackedSession.timeToDeadSession();
+ if (time <= 0) {
+ needDoRollbackedSessions.add(rollbackedSession);
+ } else {
+ delay = Math.max(time, END_STATUS_RETRY_PERIOD);
+ break;
+ }
+ }
+ long now = System.currentTimeMillis();
+ SessionHelper.forEach(needDoRollbackedSessions, rollbackedSession -> {
+ try {
+ if (isRetryTimeout(now, MAX_ROLLBACK_RETRY_TIMEOUT, rollbackedSession.getBeginTime())) {
+ handleEndStateSession(rollbackedSession);
+ }
+ } catch (TransactionException ex) {
+ LOGGER.error("Failed to handle rollbacked [{}] {} {}", rollbackedSession.getXid(), ex.getCode(), ex.getMessage());
+ }
+ });
+ rollbackedSchedule(delay);
Review Comment:
```suggestion
endSchedule(delay);
```
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -631,6 +644,64 @@ private void committingSchedule(long delay) {
delay, TimeUnit.MILLISECONDS);
}
+ /**
+ * Handle rollbacked by scheduled.
+ */
+ protected void handleEndStatesByScheduled() {
+ SessionCondition sessionCondition = new SessionCondition(endStatuses);
+ sessionCondition.setLazyLoadBranch(true);
+ List<GlobalSession> rollbackedSessions =
+ SessionHolder.getRootSessionManager().findGlobalSessions(sessionCondition);
+ if (CollectionUtils.isEmpty(rollbackedSessions)) {
+ rollbackedSchedule(RETRY_DEAD_THRESHOLD);
+ return;
+ }
+ long delay = END_STATUS_RETRY_PERIOD;
+ rollbackedSessions.sort(Comparator.comparingLong(GlobalSession::getBeginTime));
+ List<GlobalSession> needDoRollbackedSessions = new ArrayList<>();
+ for (GlobalSession rollbackedSession : rollbackedSessions) {
+ long time = rollbackedSession.timeToDeadSession();
+ if (time <= 0) {
+ needDoRollbackedSessions.add(rollbackedSession);
+ } else {
+ delay = Math.max(time, END_STATUS_RETRY_PERIOD);
+ break;
+ }
+ }
+ long now = System.currentTimeMillis();
+ SessionHelper.forEach(needDoRollbackedSessions, rollbackedSession -> {
+ try {
+ if (isRetryTimeout(now, MAX_ROLLBACK_RETRY_TIMEOUT, rollbackedSession.getBeginTime())) {
+ handleEndStateSession(rollbackedSession);
+ }
+ } catch (TransactionException ex) {
+ LOGGER.error("Failed to handle rollbacked [{}] {} {}", rollbackedSession.getXid(), ex.getCode(), ex.getMessage());
+ }
+ });
+ rollbackedSchedule(delay);
+ }
+
+ private void handleEndStateSession(GlobalSession globalSession) throws TransactionException {
+ GlobalStatus status = globalSession.getStatus();
+
+ if (status == GlobalStatus.CommitFailed) {
Review Comment:
The commit state is not limited to just one, and the rollback state is the same. I suggest putting the handling of various end states directly in the SessionHelper, and then calling it from handleEndStateSession. The only input parameter needed is a globalsession
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -631,6 +644,64 @@ private void committingSchedule(long delay) {
delay, TimeUnit.MILLISECONDS);
}
+ /**
+ * Handle rollbacked by scheduled.
+ */
+ protected void handleEndStatesByScheduled() {
+ SessionCondition sessionCondition = new SessionCondition(endStatuses);
+ sessionCondition.setLazyLoadBranch(true);
+ List<GlobalSession> rollbackedSessions =
+ SessionHolder.getRootSessionManager().findGlobalSessions(sessionCondition);
+ if (CollectionUtils.isEmpty(rollbackedSessions)) {
+ rollbackedSchedule(RETRY_DEAD_THRESHOLD);
+ return;
+ }
+ long delay = END_STATUS_RETRY_PERIOD;
+ rollbackedSessions.sort(Comparator.comparingLong(GlobalSession::getBeginTime));
+ List<GlobalSession> needDoRollbackedSessions = new ArrayList<>();
+ for (GlobalSession rollbackedSession : rollbackedSessions) {
+ long time = rollbackedSession.timeToDeadSession();
+ if (time <= 0) {
+ needDoRollbackedSessions.add(rollbackedSession);
+ } else {
+ delay = Math.max(time, END_STATUS_RETRY_PERIOD);
+ break;
+ }
+ }
+ long now = System.currentTimeMillis();
+ SessionHelper.forEach(needDoRollbackedSessions, rollbackedSession -> {
+ try {
+ if (isRetryTimeout(now, MAX_ROLLBACK_RETRY_TIMEOUT, rollbackedSession.getBeginTime())) {
+ handleEndStateSession(rollbackedSession);
+ }
+ } catch (TransactionException ex) {
+ LOGGER.error("Failed to handle rollbacked [{}] {} {}", rollbackedSession.getXid(), ex.getCode(), ex.getMessage());
+ }
+ });
+ rollbackedSchedule(delay);
+ }
+
+ private void handleEndStateSession(GlobalSession globalSession) throws TransactionException {
+ GlobalStatus status = globalSession.getStatus();
+
+ if (status == GlobalStatus.CommitFailed) {
+ SessionHelper.endCommitted(globalSession, true);
+ return;
+ }
+ SessionHelper.endRollbacked(globalSession, true);
+ }
+
+ private void rollbackedSchedule(long delay) {
Review Comment:
```suggestion
private void endSchedule(long delay) {
```
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -631,6 +644,64 @@ private void committingSchedule(long delay) {
delay, TimeUnit.MILLISECONDS);
}
+ /**
+ * Handle rollbacked by scheduled.
+ */
+ protected void handleEndStatesByScheduled() {
+ SessionCondition sessionCondition = new SessionCondition(endStatuses);
+ sessionCondition.setLazyLoadBranch(true);
+ List<GlobalSession> rollbackedSessions =
+ SessionHolder.getRootSessionManager().findGlobalSessions(sessionCondition);
+ if (CollectionUtils.isEmpty(rollbackedSessions)) {
+ rollbackedSchedule(RETRY_DEAD_THRESHOLD);
+ return;
+ }
+ long delay = END_STATUS_RETRY_PERIOD;
+ rollbackedSessions.sort(Comparator.comparingLong(GlobalSession::getBeginTime));
+ List<GlobalSession> needDoRollbackedSessions = new ArrayList<>();
+ for (GlobalSession rollbackedSession : rollbackedSessions) {
+ long time = rollbackedSession.timeToDeadSession();
+ if (time <= 0) {
+ needDoRollbackedSessions.add(rollbackedSession);
+ } else {
+ delay = Math.max(time, END_STATUS_RETRY_PERIOD);
+ break;
+ }
+ }
+ long now = System.currentTimeMillis();
+ SessionHelper.forEach(needDoRollbackedSessions, rollbackedSession -> {
+ try {
+ if (isRetryTimeout(now, MAX_ROLLBACK_RETRY_TIMEOUT, rollbackedSession.getBeginTime())) {
+ handleEndStateSession(rollbackedSession);
+ }
+ } catch (TransactionException ex) {
+ LOGGER.error("Failed to handle rollbacked [{}] {} {}", rollbackedSession.getXid(), ex.getCode(), ex.getMessage());
+ }
+ });
+ rollbackedSchedule(delay);
+ }
+
+ private void handleEndStateSession(GlobalSession globalSession) throws TransactionException {
+ GlobalStatus status = globalSession.getStatus();
+
+ if (status == GlobalStatus.CommitFailed) {
+ SessionHelper.endCommitted(globalSession, true);
+ return;
+ }
+ SessionHelper.endRollbacked(globalSession, true);
+ }
+
+ private void rollbackedSchedule(long delay) {
+ syncProcessing.schedule(
+ () -> {
+ boolean called = SessionHolder.distributedLockAndExecute(ROLLBACKED, this::handleEndStatesByScheduled);
Review Comment:
```suggestion
boolean called = SessionHolder.distributedLockAndExecute(END, this::handleEndStatesByScheduled);
```
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] Add compensation handling for TimeoutRollbacked and Rollbacked states [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1942204066
##########
server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java:
##########
@@ -189,7 +189,11 @@ public class DefaultCoordinator extends AbstractTCInboundHandler implements Tran
private final GlobalStatus[] retryRollbackingStatuses = new GlobalStatus[] {
GlobalStatus.TimeoutRollbacking,
- GlobalStatus.TimeoutRollbackRetrying, GlobalStatus.RollbackRetrying};
+ GlobalStatus.TimeoutRollbackRetrying,
+ GlobalStatus.RollbackRetrying,
+ GlobalStatus.TimeoutRollbacked,
+ GlobalStatus.Rollbacked
Review Comment:
Since the probability of a transaction rollback occurring is very low, the likelihood of the rollbacked intermediate state persisting is even lower. After the rollbacking state, it transitions to rollbacked and is then deleted. These two actions are separated by just one I/O operation, meaning that once the status is successfully updated to rollbacked, the transaction will be immediately deleted, unless a network or storage-side exception occurs during deletion, preventing the transaction from being deleted. Otherwise, there will be no rollbacked transactions left.
The commit of a transaction is a high-probability event, so the likelihood of the committed state persisting is much higher than that of rollbacked. To prevent storage-side pressure and meet performance requirements, committed transactions need to be processed during the server's runtime, while the low-probability rollbacked transactions are handled during the server startup.
Since both of these probabilities are very low, the final result is that they are both deleted. If you think it is necessary to handle rollbacked transactions during runtime, I suggest that you create a separate scheduled task to batch process transactions in the rollbacked and committed states, rather than blocking transactions that urgently need to be rolled back and retried.
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement Scheduled Handling for Rollbacked and TimeoutRollbacked Transaction [incubator-seata]
Posted by "YongGoose (via GitHub)" <gi...@apache.org>.
YongGoose commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1953803003
##########
server/src/main/java/org/apache/seata/server/session/GlobalSession.java:
##########
@@ -204,9 +204,17 @@ public boolean isTimeout() {
/**
* prevent could not handle committing and rollbacking transaction
+ *
+ * If the global session's status is "Rollbacked" or "TimeoutRollbacked", it returns the negative time since the session began,
+ * indicating that the session is already dead.
+ * For other statuses, it returns the remaining time until the session reaches the retry dead threshold.
+ *
* @return time to dead session. if not greater than 0, then deadSession
*/
public long timeToDeadSession() {
+ if (this.status == GlobalStatus.Rollbacked || this.status == GlobalStatus.TimeoutRollbacked) {
+ return beginTime - System.currentTimeMillis();
Review Comment:
I implemented it this way to set a slightly shorter interval for sessions in the `end` state.
If possible, could you please provide a more detailed explanation? 🙂
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: Implement Scheduled Handling for Rollbacked and TimeoutRollbacked Transaction [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #7133:
URL: https://github.com/apache/incubator-seata/pull/7133#discussion_r1955423436
##########
server/src/main/java/org/apache/seata/server/session/GlobalSession.java:
##########
@@ -204,9 +204,17 @@ public boolean isTimeout() {
/**
* prevent could not handle committing and rollbacking transaction
+ *
+ * If the global session's status is "Rollbacked" or "TimeoutRollbacked", it returns the negative time since the session began,
+ * indicating that the session is already dead.
+ * For other statuses, it returns the remaining time until the session reaches the retry dead threshold.
+ *
* @return time to dead session. if not greater than 0, then deadSession
*/
public long timeToDeadSession() {
+ if (this.status == GlobalStatus.Rollbacked || this.status == GlobalStatus.TimeoutRollbacked) {
+ return beginTime - System.currentTimeMillis();
Review Comment:
The beginTime is set when the transaction is created. When the Seata server's business thread changes the transaction status from "Rollbacking" to "Rollbacked," your timeToDeadSession method directly subtracts the current timestamp from beginTime, which will inevitably result in a negative value. As a result, the business thread will delete the transaction, and your scheduled task will also delete the transaction, leading to a concurrency issue and thread safety problem. I believe that beginTime should be increased by the corresponding transaction timeout, plus an additional buffer time to ensure thread safety.
--
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-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org