Return-Path: X-Original-To: apmail-accumulo-commits-archive@www.apache.org Delivered-To: apmail-accumulo-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AFFEB18245 for ; Thu, 11 Jun 2015 01:11:05 +0000 (UTC) Received: (qmail 85781 invoked by uid 500); 11 Jun 2015 01:11:05 -0000 Delivered-To: apmail-accumulo-commits-archive@accumulo.apache.org Received: (qmail 85683 invoked by uid 500); 11 Jun 2015 01:11:05 -0000 Mailing-List: contact commits-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list commits@accumulo.apache.org Received: (qmail 85599 invoked by uid 99); 11 Jun 2015 01:11:05 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Jun 2015 01:11:05 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 61150E04AC; Thu, 11 Jun 2015 01:11:05 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: billie@apache.org To: commits@accumulo.apache.org Date: Thu, 11 Jun 2015 01:11:05 -0000 Message-Id: <682cbf8365d54e98b3c4758471ee3070@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/3] accumulo git commit: ACCUMULO-3890 cache CredentialProvider objects to prevent unneeded NN ops Repository: accumulo Updated Branches: refs/heads/master a5e4ae849 -> 3fe4f690b ACCUMULO-3890 cache CredentialProvider objects to prevent unneeded NN ops Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/a2e131bd Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/a2e131bd Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/a2e131bd Branch: refs/heads/master Commit: a2e131bda969061b93e8639e11c3445d450e5bc3 Parents: c6d1ce5 Author: Billie Rinaldi Authored: Wed Jun 10 14:25:13 2015 -0700 Committer: Billie Rinaldi Committed: Wed Jun 10 18:04:44 2015 -0700 ---------------------------------------------------------------------- .../conf/CredentialProviderFactoryShim.java | 24 +++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/a2e131bd/core/src/main/java/org/apache/accumulo/core/conf/CredentialProviderFactoryShim.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/conf/CredentialProviderFactoryShim.java b/core/src/main/java/org/apache/accumulo/core/conf/CredentialProviderFactoryShim.java index 3c3c051..9af3e00 100644 --- a/core/src/main/java/org/apache/accumulo/core/conf/CredentialProviderFactoryShim.java +++ b/core/src/main/java/org/apache/accumulo/core/conf/CredentialProviderFactoryShim.java @@ -21,7 +21,9 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.accumulo.core.util.CachedConfiguration; import org.apache.hadoop.conf.Configuration; @@ -62,6 +64,9 @@ public class CredentialProviderFactoryShim { private static Method flushMethod = null; private static Boolean hadoopClassesAvailable = null; + // access to cachedProviders should be synchronized when necessary (for example see getCredentialProviders) + private static final Map> cachedProviders = new HashMap>(); + /** * Determine if we can load the necessary CredentialProvider classes. Only loaded the first time, so subsequent invocations of this method should return fast. * @@ -200,6 +205,15 @@ public class CredentialProviderFactoryShim { */ @SuppressWarnings("unchecked") protected static List getCredentialProviders(Configuration conf) { + String path = conf.get(CREDENTIAL_PROVIDER_PATH); + if (path == null || path.isEmpty()) { + return null; + } + + if (cachedProviders.containsKey(path)) { + return cachedProviders.get(path); + } + // Call CredentialProviderFactory.getProviders(Configuration) Object providersObj = null; try { @@ -217,7 +231,15 @@ public class CredentialProviderFactoryShim { // Cast the Object to List (actually List) try { - return (List) providersObj; + List providersList = (List) providersObj; + synchronized (cachedProviders) { + if (cachedProviders.containsKey(path)) { + return cachedProviders.get(path); + } else { + cachedProviders.put(path, providersList); + } + } + return providersList; } catch (ClassCastException e) { log.error("Expected a List from {} method", HADOOP_CRED_PROVIDER_FACTORY_GET_PROVIDERS_METHOD_NAME, e); return null;