You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ni...@apache.org on 2020/05/05 14:21:28 UTC

[servicecomb-pack] 01/01: SCB-1879 Support to disable the TCC feature from configuration

This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch SCB-1879
in repository https://gitbox.apache.org/repos/asf/servicecomb-pack.git

commit 5ab99bb1ed42fd4db6f4051491d46446a60138df
Author: Willem Jiang <wi...@gmail.com>
AuthorDate: Tue May 5 22:20:51 2020 +0800

    SCB-1879 Support to disable the TCC feature from configuration
---
 .../servicecomb/pack/alpha/server/AlphaConfig.java | 62 ++++++++++++++--------
 .../alpha/server/fsm/AlphaIntegrationFsmTest.java  |  1 +
 2 files changed, 40 insertions(+), 23 deletions(-)

diff --git a/alpha/alpha-server/src/main/java/org/apache/servicecomb/pack/alpha/server/AlphaConfig.java b/alpha/alpha-server/src/main/java/org/apache/servicecomb/pack/alpha/server/AlphaConfig.java
index ce9f688..57302aa 100644
--- a/alpha/alpha-server/src/main/java/org/apache/servicecomb/pack/alpha/server/AlphaConfig.java
+++ b/alpha/alpha-server/src/main/java/org/apache/servicecomb/pack/alpha/server/AlphaConfig.java
@@ -18,6 +18,8 @@
 package org.apache.servicecomb.pack.alpha.server;
 
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.ConcurrentHashMap;
@@ -49,6 +51,8 @@ import org.springframework.context.ApplicationEventPublisher;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
+import io.grpc.BindableService;
+
 @EntityScan(basePackages = "org.apache.servicecomb.pack.alpha")
 @Configuration
 public class AlphaConfig {
@@ -141,7 +145,15 @@ public class AlphaConfig {
   }
 
   @Bean
-  GrpcTccEventService grpcTccEventService(TccTxEventService tccTxEventService) {
+  @ConditionalOnProperty(name = "alpha.feature.tcc.enabled", havingValue = "true", matchIfMissing = true)
+  GrpcTccEventService grpcTccEventService(TccTxEventService tccTxEventService, TccPendingTaskRunner tccPendingTaskRunner, TccEventScanner tccEventScanner) {
+    // start the service which are needed for TCC
+    tccPendingTaskRunner.start();
+    tccEventScanner.start();
+    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+      tccPendingTaskRunner.shutdown();
+      tccEventScanner.shutdown();
+    }));
     return new GrpcTccEventService(tccTxEventService);
   }
 
@@ -150,43 +162,47 @@ public class AlphaConfig {
     return new TccEventScanner(tccTxEventService, delay, globalTxTimeoutSeconds);
   }
 
-  @Bean
+
+  @Bean()
   @ConditionalOnProperty(name = "alpha.feature.akka.enabled", havingValue = "false", matchIfMissing = true)
   ServerStartable serverStartable(GrpcServerConfig serverConfig, TxConsistentService txConsistentService,
-      Map<String, Map<String, OmegaCallback>> omegaCallbacks, GrpcTccEventService grpcTccEventService,
-      TccPendingTaskRunner tccPendingTaskRunner, TccEventScanner tccEventScanner, @Qualifier("alphaEventBus") EventBus eventBus) throws IOException {
+      Map<String, Map<String, OmegaCallback>> omegaCallbacks, @Autowired(required = false) GrpcTccEventService grpcTccEventService,
+      @Qualifier("alphaEventBus") EventBus eventBus) throws IOException {
     ServerMeta serverMeta = ServerMeta.newBuilder()
         .putMeta(AlphaMetaKeys.AkkaEnabled.name(), String.valueOf(false)).build();
+    List<BindableService> bindableServices = new ArrayList();
+    bindableServices.add(new GrpcTxEventEndpointImpl(txConsistentService, omegaCallbacks, serverMeta));
+    if (grpcTccEventService != null) {
+      LOG.info("alpha.feature.tcc.enable=true, starting the TCC service.");
+      bindableServices.add(grpcTccEventService);
+    } else {
+      LOG.info("alpha.feature.tcc.enable=false, the TCC service is disabled.");
+    }
     ServerStartable bootstrap = new GrpcStartable(serverConfig, eventBus,
-        new GrpcTxEventEndpointImpl(txConsistentService, omegaCallbacks, serverMeta), grpcTccEventService);
+        bindableServices.toArray(new BindableService[0]));
     new Thread(bootstrap::start).start();
-    tccPendingTaskRunner.start();
-    tccEventScanner.start();
-    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
-      tccPendingTaskRunner.shutdown();
-      tccEventScanner.shutdown();
-    }));
-    LOG.info("alpha.feature.akka.enabled=false");
+    LOG.info("alpha.feature.akka.enabled=false, starting the saga db service");
     return bootstrap;
   }
 
   @Bean
   @ConditionalOnProperty(name= "alpha.feature.akka.enabled", havingValue = "true")
   ServerStartable serverStartableWithAkka(GrpcServerConfig serverConfig,
-      Map<String, Map<String, OmegaCallback>> omegaCallbacks, GrpcTccEventService grpcTccEventService,
-      TccPendingTaskRunner tccPendingTaskRunner, TccEventScanner tccEventScanner, @Qualifier("alphaEventBus") EventBus eventBus, ActorEventChannel actorEventChannel) throws IOException {
+      Map<String, Map<String, OmegaCallback>> omegaCallbacks, @Autowired(required = false) GrpcTccEventService grpcTccEventService,
+      @Qualifier("alphaEventBus") EventBus eventBus, ActorEventChannel actorEventChannel) throws IOException {
     ServerMeta serverMeta = ServerMeta.newBuilder()
         .putMeta(AlphaMetaKeys.AkkaEnabled.name(), String.valueOf(true)).build();
-    ServerStartable bootstrap = new GrpcStartable(serverConfig, eventBus,
-        new GrpcSagaEventService(actorEventChannel, omegaCallbacks, serverMeta), grpcTccEventService);
+    List<BindableService> bindableServices = new ArrayList();
+    bindableServices.add(new GrpcSagaEventService(actorEventChannel, omegaCallbacks, serverMeta));
+    if (grpcTccEventService != null) {
+      LOG.info("alpha.feature.tcc.enable=true, starting the TCC service.");
+      bindableServices.add(grpcTccEventService);
+    } else {
+      LOG.info("alpha.feature.tcc.enable=false, the TCC service is disabled.");
+    }
+    ServerStartable bootstrap = new GrpcStartable(serverConfig, eventBus, bindableServices.toArray(new BindableService[0]));
     new Thread(bootstrap::start).start();
-    tccPendingTaskRunner.start();
-    tccEventScanner.start();
-    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
-      tccPendingTaskRunner.shutdown();
-      tccEventScanner.shutdown();
-    }));
-    LOG.info("alpha.feature.akka.enabled=true");
+    LOG.info("alpha.feature.akka.enabled=true, starting the saga akka service.");
     return bootstrap;
   }
 
diff --git a/alpha/alpha-server/src/test/java/org/apache/servicecomb/pack/alpha/server/fsm/AlphaIntegrationFsmTest.java b/alpha/alpha-server/src/test/java/org/apache/servicecomb/pack/alpha/server/fsm/AlphaIntegrationFsmTest.java
index 15c1a0e..aede177 100644
--- a/alpha/alpha-server/src/test/java/org/apache/servicecomb/pack/alpha/server/fsm/AlphaIntegrationFsmTest.java
+++ b/alpha/alpha-server/src/test/java/org/apache/servicecomb/pack/alpha/server/fsm/AlphaIntegrationFsmTest.java
@@ -61,6 +61,7 @@ import org.springframework.test.context.junit4.SpringRunner;
         "spring.profiles.active=akka-persistence-mem",
         //akka
         "alpha.feature.akka.enabled=true",
+        "alpha.feature.tcc.enabled=false",
         "alpha.feature.akka.channel.type=memory",
         "akkaConfig.akka.persistence.journal.plugin=akka.persistence.journal.inmem",
         "akkaConfig.akka.persistence.journal.leveldb.dir=target/example/journal",