Repository: flume
Updated Branches:
  refs/heads/flume-1.6 8ccbb0b4b -> f8065ef7a


FLUME-2642. Limit the number of calls to UGI.checkTGTAndRelogin method.

(Johny Rufus via Hari)


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

Branch: refs/heads/flume-1.6
Commit: f8065ef7a35fa2cb3d5e01f76e00e6474e3c6b4c
Parents: 8ccbb0b
Author: Hari Shreedharan <[email protected]>
Authored: Tue Mar 10 21:53:31 2015 -0700
Committer: Hari Shreedharan <[email protected]>
Committed: Tue Mar 10 21:54:41 2015 -0700

----------------------------------------------------------------------
 .../main/java/org/apache/flume/auth/UGIExecutor.java | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flume/blob/f8065ef7/flume-ng-auth/src/main/java/org/apache/flume/auth/UGIExecutor.java
----------------------------------------------------------------------
diff --git a/flume-ng-auth/src/main/java/org/apache/flume/auth/UGIExecutor.java 
b/flume-ng-auth/src/main/java/org/apache/flume/auth/UGIExecutor.java
index a5aeef2..cd62b91 100644
--- a/flume-ng-auth/src/main/java/org/apache/flume/auth/UGIExecutor.java
+++ b/flume-ng-auth/src/main/java/org/apache/flume/auth/UGIExecutor.java
@@ -27,6 +27,8 @@ import java.security.PrivilegedExceptionAction;
 
 class UGIExecutor implements PrivilegedExecutor {
   private UserGroupInformation ugi;
+  private static final long MIN_TIME_BEFORE_RELOGIN = 5 * 60 * 1000L;
+  private volatile long lastReloginAttempt = 0;
 
   UGIExecutor(UserGroupInformation ugi) {
     this.ugi = ugi;
@@ -58,9 +60,22 @@ class UGIExecutor implements PrivilegedExecutor {
     }
   }
 
+  /*
+   * lastReloginAttempt is introduced to avoid making the synchronized call
+   *  ugi.checkTGTAndReloginFromKeytab() often, Hence this method is
+   *  intentionally not synchronized, so that multiple threads can execute 
without
+   *  the need to lock, which may result in an edge case where multiple threads
+   *  simultaneously reading the lastReloginAttempt, and finding it > 5 
minutes, can
+   *  result in all of them attempting the checkTGT method, which is fine
+   */
   private void reloginUGI(UserGroupInformation ugi) {
     try {
       if(ugi.hasKerberosCredentials()) {
+        long now = System.currentTimeMillis();
+        if(now - lastReloginAttempt < MIN_TIME_BEFORE_RELOGIN) {
+          return;
+        }
+        lastReloginAttempt = now;
         ugi.checkTGTAndReloginFromKeytab();
       }
     } catch (IOException e) {

Reply via email to