You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sentry.apache.org by va...@apache.org on 2017/08/31 17:26:46 UTC

sentry git commit: SENTRY-1906: Sentry clients to retry connections to server with delay to avoid failing fast (Vamsee Yarlagadda, Reviewed by: Alexander Kolbasov, Na Li)

Repository: sentry
Updated Branches:
  refs/heads/master 1e29fa981 -> 8474ec7de


SENTRY-1906: Sentry clients to retry connections to server with delay to avoid failing fast (Vamsee Yarlagadda, Reviewed by: Alexander Kolbasov, Na Li)


Project: http://git-wip-us.apache.org/repos/asf/sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/8474ec7d
Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/8474ec7d
Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/8474ec7d

Branch: refs/heads/master
Commit: 8474ec7de7d973895ffaa603b2adb94ae43820d8
Parents: 1e29fa9
Author: Vamsee Yarlagadda <va...@cloudera.com>
Authored: Tue Aug 29 18:27:07 2017 -0700
Committer: Vamsee Yarlagadda <va...@cloudera.com>
Committed: Thu Aug 31 10:26:30 2017 -0700

----------------------------------------------------------------------
 .../transport/RetryClientInvocationHandler.java | 11 +++++++++
 .../SentryClientTransportConfigInterface.java   |  7 ++++++
 .../SentryClientTransportConstants.java         | 25 +++++++++++++++++---
 .../SentryHDFSClientTransportConfig.java        |  5 ++++
 .../SentryPolicyClientTransportConfig.java      |  5 ++++
 5 files changed, 50 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sentry/blob/8474ec7d/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/transport/RetryClientInvocationHandler.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/transport/RetryClientInvocationHandler.java b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/transport/RetryClientInvocationHandler.java
index d400f89..1161238 100644
--- a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/transport/RetryClientInvocationHandler.java
+++ b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/transport/RetryClientInvocationHandler.java
@@ -50,6 +50,7 @@ public final class RetryClientInvocationHandler extends SentryClientInvocationHa
     LoggerFactory.getLogger(RetryClientInvocationHandler.class);
   private SentryConnection client = null;
   private final int maxRetryCount;
+  private final long connRetryDelayInMs;
 
   /**
    * Initialize the sentry configurations, including rpc retry count and client connection
@@ -61,6 +62,7 @@ public final class RetryClientInvocationHandler extends SentryClientInvocationHa
     Preconditions.checkNotNull(clientObject, "Client Object cannot be null");
     client = clientObject;
     maxRetryCount = transportConfig.getSentryRpcRetryTotal(conf);
+    connRetryDelayInMs = transportConfig.getSentryRpcConnRetryDelayInMs(conf);
   }
 
   /**
@@ -150,6 +152,15 @@ public final class RetryClientInvocationHandler extends SentryClientInvocationHa
         }
         lastExc = causeException;
       }
+
+      // Sleep until connection retry delay
+      try {
+        Thread.sleep(connRetryDelayInMs);
+      } catch (InterruptedException ex) {
+        // Resetting the interrupt flag
+        Thread.currentThread().interrupt();
+        throw ex;
+      }
     }
     assert lastExc != null;
     throw new SentryUserException (lastExc.getMessage(), lastExc);

http://git-wip-us.apache.org/repos/asf/sentry/blob/8474ec7d/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/transport/SentryClientTransportConfigInterface.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/transport/SentryClientTransportConfigInterface.java b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/transport/SentryClientTransportConfigInterface.java
index 9fd4013..27759bb 100644
--- a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/transport/SentryClientTransportConfigInterface.java
+++ b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/transport/SentryClientTransportConfigInterface.java
@@ -39,6 +39,13 @@ interface SentryClientTransportConfigInterface {
 
   /**
    * @param conf configuration
+   * @return time interval in milli-secs that the client should wait before
+   * retrying to establish connection to the server.
+   */
+  long getSentryRpcConnRetryDelayInMs(Configuration conf);
+
+  /**
+   * @param conf configuration
    * @return True, if kerberos should be enabled.
    * False, Iff kerberos is enabled.
    */

http://git-wip-us.apache.org/repos/asf/sentry/blob/8474ec7d/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/transport/SentryClientTransportConstants.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/transport/SentryClientTransportConstants.java b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/transport/SentryClientTransportConstants.java
index 358d282..d7f43dd 100644
--- a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/transport/SentryClientTransportConstants.java
+++ b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/transport/SentryClientTransportConstants.java
@@ -36,7 +36,12 @@ public final class SentryClientTransportConstants {
    * {link RetryClientInvocationHandler#invokeImpl(Object, Method, Object[])}
    */
   static final String SENTRY_RPC_RETRY_TOTAL = "sentry.service.client.rpc.retry-total";
-  static final int SENTRY_RPC_RETRY_TOTAL_DEFAULT = 3;
+  static final int SENTRY_RPC_RETRY_TOTAL_DEFAULT = 5;
+
+  static final String SERVER_RPC_CONN_RETRY_DELAY_MS = "sentry.service.client.rpc.retry.interval.msec";
+  // Default of 3 seconds time for retry
+  static final long SERVER_RPC_CONN_RETRY_DELAY_MS_DEFAULT =
+      TimeUnit.MILLISECONDS.convert(3, TimeUnit.SECONDS);
 
   /**
    * full retry num for getting the connection in non-pool model
@@ -97,7 +102,14 @@ public final class SentryClientTransportConstants {
      * {link RetryClientInvocationHandler#invokeImpl(Object, Method, Object[])}
      */
     static final String SENTRY_RPC_RETRY_TOTAL = "sentry.service.client.rpc.retry-total";
-    static final int SENTRY_RPC_RETRY_TOTAL_DEFAULT = 3;
+    static final int SENTRY_RPC_RETRY_TOTAL_DEFAULT =
+        SentryClientTransportConstants.SENTRY_RPC_RETRY_TOTAL_DEFAULT;
+
+    // Wait interval before retrying connections
+    static final String SERVER_RPC_CONN_RETRY_DELAY_MS =
+        SentryClientTransportConstants.SERVER_RPC_CONN_RETRY_DELAY_MS;
+    static final long SERVER_RPC_CONN_RETRY_DELAY_MS_DEFAULT =
+        SentryClientTransportConstants.SERVER_RPC_CONN_RETRY_DELAY_MS_DEFAULT;
 
     // commons-pool configuration
     static final String SENTRY_POOL_ENABLE = "sentry.service.client.connection.pool.enabled";
@@ -174,7 +186,14 @@ public final class SentryClientTransportConstants {
     static final String SENTRY_RPC_RETRY_TOTAL =
       SentryClientTransportConstants.SENTRY_RPC_RETRY_TOTAL;
 
-    static final int SENTRY_RPC_RETRY_TOTAL_DEFAULT = 3;
+    static final int SENTRY_RPC_RETRY_TOTAL_DEFAULT =
+        SentryClientTransportConstants.SENTRY_RPC_RETRY_TOTAL_DEFAULT;
+
+    // Wait interval before retrying connections
+    static final String SERVER_RPC_CONN_RETRY_DELAY_MS =
+        SentryClientTransportConstants.SERVER_RPC_CONN_RETRY_DELAY_MS;
+    static final long SERVER_RPC_CONN_RETRY_DELAY_MS_DEFAULT =
+        SentryClientTransportConstants.SERVER_RPC_CONN_RETRY_DELAY_MS_DEFAULT;
 
     // commons-pool configuration - disable pool for HDFS clients
     static final String SENTRY_POOL_ENABLE = "sentry.hdfs.service.client.connection.pool.enable";

http://git-wip-us.apache.org/repos/asf/sentry/blob/8474ec7d/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/transport/SentryHDFSClientTransportConfig.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/transport/SentryHDFSClientTransportConfig.java b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/transport/SentryHDFSClientTransportConfig.java
index 1724e7f..b07bc2c 100644
--- a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/transport/SentryHDFSClientTransportConfig.java
+++ b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/transport/SentryHDFSClientTransportConfig.java
@@ -45,6 +45,11 @@ public final class SentryHDFSClientTransportConfig
   }
 
   @Override
+  public long getSentryRpcConnRetryDelayInMs(Configuration conf) {
+    return conf.getLong(SERVER_RPC_CONN_RETRY_DELAY_MS, SERVER_RPC_CONN_RETRY_DELAY_MS_DEFAULT);
+  }
+
+  @Override
   public boolean useUserGroupInformation(Configuration conf) {
     return Boolean.parseBoolean(conf.get(SECURITY_USE_UGI_TRANSPORT, "true"));
   }

http://git-wip-us.apache.org/repos/asf/sentry/blob/8474ec7d/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/transport/SentryPolicyClientTransportConfig.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/transport/SentryPolicyClientTransportConfig.java b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/transport/SentryPolicyClientTransportConfig.java
index 45522df..4cb8b9c 100644
--- a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/transport/SentryPolicyClientTransportConfig.java
+++ b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/transport/SentryPolicyClientTransportConfig.java
@@ -46,6 +46,11 @@ public final class SentryPolicyClientTransportConfig
   }
 
   @Override
+  public long getSentryRpcConnRetryDelayInMs(Configuration conf) {
+    return conf.getLong(SERVER_RPC_CONN_RETRY_DELAY_MS, SERVER_RPC_CONN_RETRY_DELAY_MS_DEFAULT);
+  }
+
+  @Override
   public boolean useUserGroupInformation(Configuration conf) {
     return Boolean.valueOf(conf.get(SECURITY_USE_UGI_TRANSPORT, "true"));
   }