seanyinx commented on a change in pull request #111: SCB-213 proper timing to
handle SagaEndedEvent in asynchronous situation
URL:
https://github.com/apache/incubator-servicecomb-saga/pull/111#discussion_r160862939
##########
File path:
alpha/alpha-core/src/main/java/org/apache/servicecomb/saga/alpha/core/TxConsistentService.java
##########
@@ -44,7 +58,28 @@ public void handle(TxEvent event) {
}
private void compensate(TxEvent event) {
- List<TxEvent> events =
eventRepository.findStartedTransactions(event.globalTxId(),
EventType.TxStartedEvent.name());
+ List<TxEvent> events =
eventRepository.findStartedTransactions(event.globalTxId(),
TxStartedEvent.name());
events.forEach(omegaCallback::compensate);
+ eventsToCompensate.computeIfAbsent(event.globalTxId(), (v) -> {
+ Set<String> eventSet = new HashSet<>(events.size());
+ events.forEach(e -> eventSet.add(e.localTxId()));
+ return eventSet;
+ });
+ }
+
+ private void updateCompensateStatus(TxEvent event) {
+ Set<String> events = eventsToCompensate.get(event.globalTxId());
+ if (events != null) {
+ events.remove(event.localTxId());
+ if (events.isEmpty()) {
+ markGlobalTxEnd(event);
Review comment:
how about remove the set from map, or it will keep growing?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services