Repository: flume Updated Branches: refs/heads/trunk 49150fe6d -> 39bc4da1e
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/39bc4da1 Tree: http://git-wip-us.apache.org/repos/asf/flume/tree/39bc4da1 Diff: http://git-wip-us.apache.org/repos/asf/flume/diff/39bc4da1 Branch: refs/heads/trunk Commit: 39bc4da1ed286fa3690876dda741cadb35386d93 Parents: 49150fe Author: Hari Shreedharan <[email protected]> Authored: Tue Mar 10 21:53:31 2015 -0700 Committer: Hari Shreedharan <[email protected]> Committed: Tue Mar 10 21:53:31 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/39bc4da1/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) {
