eric-lee-ltk 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_r160855592
##########
File path:
alpha/alpha-core/src/main/java/org/apache/servicecomb/saga/alpha/core/TxConsistentService.java
##########
@@ -44,7 +58,32 @@ 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) -> {
+ CopyOnWriteArraySet<String> eventSet = new CopyOnWriteArraySet<>();
+ events.forEach(e -> eventSet.add(getUniqueEventId(e)));
+ return eventSet;
+ });
+ }
+
+ private void updateCompensateStatus(TxEvent event) {
+ Set<String> events = eventsToCompensate.get(event.globalTxId());
+ if (events != null) {
+ events.remove(getUniqueEventId(event));
+ if (events.isEmpty()) {
+ markGlobalTxEnd(event);
+ }
+ }
+ }
+
+ private String getUniqueEventId(TxEvent event) {
+ return event.globalTxId() + "_" + event.localTxId();
Review comment:
That's a good point. Use localTxId is enough.
----------------------------------------------------------------
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