Browse Source

HADOOP-9748. Reduce blocking on UGI.ensureInitialized (daryn)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.23@1504882 13f79535-47bb-0310-9956-ffa450edef68
Daryn Sharp 12 years ago
parent
commit
f425c893f1

+ 2 - 0
hadoop-common-project/hadoop-common/CHANGES.txt

@@ -10,6 +10,8 @@ Release 0.23.10 - UNRELEASED
 
   OPTIMIZATIONS
 
+    HADOOP-9748. Reduce blocking on UGI.ensureInitialized (daryn)
+
   BUG FIXES
 
 Release 0.23.9 - 2013-07-08

+ 7 - 5
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java

@@ -190,7 +190,6 @@ public class UserGroupInformation {
   /** Metrics to track UGI activity */
   static UgiMetrics metrics = UgiMetrics.create();
   /** Are the static variables that depend on configuration initialized? */
-  private static boolean isInitialized = false;
   /** Should we use Kerberos configuration? */
   private static boolean useKerberos;
   /** Server-side groups fetching service */
@@ -210,9 +209,13 @@ public class UserGroupInformation {
    * A method to initialize the fields that depend on a configuration.
    * Must be called before useKerberos or groups is used.
    */
-  private static synchronized void ensureInitialized() {
-    if (!isInitialized) {
-        initialize(new Configuration(), KerberosName.hasRulesBeenSet());
+  private static void ensureInitialized() {
+    if (conf == null) {
+      synchronized(UserGroupInformation.class) {
+        if (conf == null) { // someone might have beat us
+          initialize(new Configuration(), KerberosName.hasRulesBeenSet());
+        }
+      }
     }
   }
 
@@ -252,7 +255,6 @@ public class UserGroupInformation {
     if (!(groups instanceof TestingGroups)) {
       groups = Groups.getUserToGroupsMappingService(conf);
     }
-    isInitialized = true;
     UserGroupInformation.conf = conf;
   }