You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2019/12/07 01:18:39 UTC

[GitHub] [servicecomb-pack] WillemJiang commented on a change in pull request #609: [SCB-1627] Omega side CallbackContext send the compensation result event to Alpha

WillemJiang commented on a change in pull request #609: [SCB-1627] Omega side CallbackContext send the compensation result event to Alpha
URL: https://github.com/apache/servicecomb-pack/pull/609#discussion_r355087648
 
 

 ##########
 File path: alpha/alpha-server/src/main/java/org/apache/servicecomb/pack/alpha/server/fsm/GrpcOmegaCallback.java
 ##########
 @@ -19,32 +19,71 @@
 
 import com.google.protobuf.ByteString;
 import io.grpc.stub.StreamObserver;
+import java.lang.invoke.MethodHandles;
 import org.apache.servicecomb.pack.alpha.core.OmegaCallback;
 import org.apache.servicecomb.pack.alpha.core.TxEvent;
+import org.apache.servicecomb.pack.alpha.core.exception.CompensateAckFailedException;
+import org.apache.servicecomb.pack.alpha.core.exception.CompensateConnectException;
+import org.apache.servicecomb.pack.alpha.core.fsm.CompensateAckType;
 import org.apache.servicecomb.pack.contract.grpc.GrpcCompensateCommand;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 class GrpcOmegaCallback implements OmegaCallback {
 
+  private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
   private final StreamObserver<GrpcCompensateCommand> observer;
+  private CompensateAckCountDownLatch compensateAckCountDownLatch;
 
   GrpcOmegaCallback(StreamObserver<GrpcCompensateCommand> observer) {
     this.observer = observer;
   }
 
   @Override
   public void compensate(TxEvent event) {
-    GrpcCompensateCommand command = GrpcCompensateCommand.newBuilder()
-        .setGlobalTxId(event.globalTxId())
-        .setLocalTxId(event.localTxId())
-        .setParentTxId(event.parentTxId() == null ? "" : event.parentTxId())
-        .setCompensationMethod(event.compensationMethod())
-        .setPayloads(ByteString.copyFrom(event.payloads()))
-        .build();
-    observer.onNext(command);
+    compensateAckCountDownLatch = new CompensateAckCountDownLatch(1);
+    try {
+      GrpcCompensateCommand command = GrpcCompensateCommand.newBuilder()
+          .setGlobalTxId(event.globalTxId())
+          .setLocalTxId(event.localTxId())
+          .setParentTxId(event.parentTxId() == null ? "" : event.parentTxId())
+          .setCompensationMethod(event.compensationMethod())
+          .setPayloads(ByteString.copyFrom(event.payloads()))
+          .build();
+      observer.onNext(command);
+      compensateAckCountDownLatch.await();
 
 Review comment:
   I don't think it's a good practices to start a wait without timeout, as the compensate method block the method
   I think we could create a mechanism to check the response in an async way without waiting for the response by blocking the calling thread.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services