accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bil...@apache.org
Subject [1/3] accumulo git commit: ACCUMULO-3890 cache CredentialProvider objects to prevent unneeded NN ops
Date Thu, 11 Jun 2015 01:11:05 GMT
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 <billie@apache.org>
Authored: Wed Jun 10 14:25:13 2015 -0700
Committer: Billie Rinaldi <billie@apache.org>
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<String,List<Object>> cachedProviders = new HashMap<String,List<Object>>();
+
   /**
    * 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<Object> 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<Object> (actually List<CredentialProvider>)
     try {
-      return (List<Object>) providersObj;
+      List<Object> providersList = (List<Object>) 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;


Mime
View raw message