You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2022/05/12 11:21:10 UTC

[GitHub] [accumulo] dlmarion commented on a diff in pull request #2647: Consolidated duplicate Thrift client code

dlmarion commented on code in PR #2647:
URL: https://github.com/apache/accumulo/pull/2647#discussion_r871260772


##########
core/src/main/java/org/apache/accumulo/core/rpc/ThriftClientTypes.java:
##########
@@ -74,26 +259,217 @@ public C getClient(TProtocol prot) {
           "CompactionCoordinatorService", new CompactionCoordinatorService.Client.Factory());
 
   public static final ThriftClientType<FateService.Client,FateService.Client.Factory> FATE =
-      new ThriftClientType<>("FateService", new FateService.Client.Factory());
+      new ThriftClientType<>("FateService", new FateService.Client.Factory()) {
+
+        @Override
+        public org.apache.accumulo.core.manager.thrift.FateService.Client
+            getManagerConnection(ClientContext context) {
+          checkArgument(context != null, "context is null");
+
+          List<String> locations = context.getManagerLocations();
+
+          if (locations.isEmpty()) {
+            LOG.debug("No managers...");
+            return null;
+          }
+
+          HostAndPort manager = HostAndPort.fromString(locations.get(0));
+          if (manager.getPort() == 0)
+            return null;
+
+          try {
+            // Manager requests can take a long time: don't ever time out
+            return ThriftUtil.getClientNoTimeout(ThriftClientTypes.FATE, manager, context);
+          } catch (TTransportException tte) {
+            Throwable cause = tte.getCause();
+            if (cause != null && cause instanceof UnknownHostException) {
+              // do not expect to recover from this
+              throw new RuntimeException(tte);
+            }
+            LOG.debug("Failed to connect to manager=" + manager + ", will retry... ", tte);
+            return null;
+          }
+        }
+      };
 
   public static final ThriftClientType<GCMonitorService.Client,GCMonitorService.Client.Factory> GC =
       new ThriftClientType<>("GCMonitorService", new GCMonitorService.Client.Factory());
 
   public static final ThriftClientType<ManagerClientService.Client,
-      ManagerClientService.Client.Factory> MANAGER =
-          new ThriftClientType<>("ManagerClientService", new ManagerClientService.Client.Factory());
+      ManagerClientService.Client.Factory> MANAGER = new ThriftClientType<>("ManagerClientService",
+          new ManagerClientService.Client.Factory()) {
+
+        @Override
+        public Client getManagerConnection(ClientContext context) {
+          checkArgument(context != null, "context is null");
+
+          List<String> locations = context.getManagerLocations();
+
+          if (locations.isEmpty()) {
+            LOG.debug("No managers...");
+            return null;
+          }
+
+          HostAndPort manager = HostAndPort.fromString(locations.get(0));
+          if (manager.getPort() == 0)
+            return null;
+
+          try {
+            // Manager requests can take a long time: don't ever time out
+            return ThriftUtil.getClientNoTimeout(ThriftClientTypes.MANAGER, manager, context);
+          } catch (TTransportException tte) {
+            Throwable cause = tte.getCause();
+            if (cause != null && cause instanceof UnknownHostException) {
+              // do not expect to recover from this
+              throw new RuntimeException(tte);
+            }
+            LOG.debug("Failed to connect to manager=" + manager + ", will retry... ", tte);
+            return null;
+          }
+
+        }
+
+      };
 
   public static final ThriftClientType<ReplicationCoordinator.Client,
       ReplicationCoordinator.Client.Factory> REPLICATION_COORDINATOR = new ThriftClientType<>(

Review Comment:
   This has been done.



-- 
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@accumulo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org