zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f..@apache.org
Subject svn commit: r1524364 - in /zookeeper/trunk: CHANGES.txt src/java/main/org/apache/zookeeper/ClientCnxn.java src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java src/java/test/org/apache/zookeeper/test/SaslClientTest.java
Date Wed, 18 Sep 2013 10:58:33 GMT
Author: fpj
Date: Wed Sep 18 10:58:32 2013
New Revision: 1524364

URL: http://svn.apache.org/r1524364
Log:
ZOOKEEPER-1657. Increased CPU usage by unnecessary SASL checks (Philip K. Warren via fpj)

Added:
    zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SaslClientTest.java
Modified:
    zookeeper/trunk/CHANGES.txt
    zookeeper/trunk/src/java/main/org/apache/zookeeper/ClientCnxn.java
    zookeeper/trunk/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java

Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1524364&r1=1524363&r2=1524364&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Wed Sep 18 10:58:32 2013
@@ -381,6 +381,8 @@ BUGFIXES:
   ZOOKEEPER-1751. ClientCnxn#run could miss the second ping or connection get
   dropped before a ping. (Jeffrey Zhong via mahadev)
 
+  ZOOKEEPER-1657. Increased CPU usage by unnecessary SASL checks (Philip K. Warren via fpj)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-1170. Fix compiler (eclipse) warnings: unused imports,

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/ClientCnxn.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/ClientCnxn.java?rev=1524364&r1=1524363&r2=1524364&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/ClientCnxn.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/ClientCnxn.java Wed Sep 18 10:58:32
2013
@@ -979,19 +979,21 @@ public class ClientCnxn {
 
             setName(getName().replaceAll("\\(.*\\)",
                     "(" + addr.getHostName() + ":" + addr.getPort() + ")"));
-            try {
-                zooKeeperSaslClient = new ZooKeeperSaslClient("zookeeper/"+addr.getHostName());
-            } catch (LoginException e) {
-                // An authentication error occurred when the SASL client tried to initialize:
-                // for Kerberos this means that the client failed to authenticate with the
KDC.
-                // This is different from an authentication error that occurs during communication
-                // with the Zookeeper server, which is handled below.
-                LOG.warn("SASL configuration failed: " + e + " Will continue connection to
Zookeeper server without "
-                  + "SASL authentication, if Zookeeper server allows it.");
-                eventThread.queueEvent(new WatchedEvent(
-                  Watcher.Event.EventType.None,
-                  Watcher.Event.KeeperState.AuthFailed, null));
-                saslLoginFailed = true;
+            if (ZooKeeperSaslClient.isEnabled()) {
+                try {
+                    zooKeeperSaslClient = new ZooKeeperSaslClient("zookeeper/"+addr.getHostName());
+                } catch (LoginException e) {
+                    // An authentication error occurred when the SASL client tried to initialize:
+                    // for Kerberos this means that the client failed to authenticate with
the KDC.
+                    // This is different from an authentication error that occurs during
communication
+                    // with the Zookeeper server, which is handled below.
+                    LOG.warn("SASL configuration failed: " + e + " Will continue connection
to Zookeeper server without "
+                      + "SASL authentication, if Zookeeper server allows it.");
+                    eventThread.queueEvent(new WatchedEvent(
+                      Watcher.Event.EventType.None,
+                      Watcher.Event.KeeperState.AuthFailed, null));
+                    saslLoginFailed = true;
+                }
             }
             logStartConnect(addr);
 
@@ -1263,18 +1265,23 @@ public class ClientCnxn {
         }
 
         public boolean clientTunneledAuthenticationInProgress() {
-            // 1. SASL login failed.
+            // 1. SASL client is disabled.
+            if (!ZooKeeperSaslClient.isEnabled()) {
+                return false;
+            }
+
+            // 2. SASL login failed.
             if (saslLoginFailed == true) {
                 return false;
             }
 
-            // 2. SendThread has not created the authenticating object yet,
+            // 3. SendThread has not created the authenticating object yet,
             // therefore authentication is (at the earliest stage of being) in progress.
             if (zooKeeperSaslClient == null) {
                 return true;
             }
 
-            // 3. authenticating object exists, so ask it for its progress.
+            // 4. authenticating object exists, so ask it for its progress.
             return zooKeeperSaslClient.clientTunneledAuthenticationInProgress();
         }
 

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java?rev=1524364&r1=1524363&r2=1524364&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/client/ZooKeeperSaslClient.java Wed
Sep 18 10:58:32 2013
@@ -62,6 +62,21 @@ import org.slf4j.LoggerFactory;
  */
 public class ZooKeeperSaslClient {
     public static final String LOGIN_CONTEXT_NAME_KEY = "zookeeper.sasl.clientconfig";
+    public static final String ENABLE_CLIENT_SASL_KEY = "zookeeper.sasl.client";
+    public static final String ENABLE_CLIENT_SASL_DEFAULT = "true";
+
+    /**
+     * Returns true if the SASL client is enabled. By default, the client
+     * is enabled but can be disabled by setting the system property
+     * <code>zookeeper.sasl.client</code> to <code>false</code>.
See
+     * ZOOKEEPER-1657 for more information.
+     *
+     * @return If the SASL client is enabled.
+     */
+    public static boolean isEnabled() {
+        return Boolean.valueOf(System.getProperty(ENABLE_CLIENT_SASL_KEY, ENABLE_CLIENT_SASL_DEFAULT));
+    }
+
     private static final Logger LOG = LoggerFactory.getLogger(ZooKeeperSaslClient.class);
     private static Login login = null;
     private SaslClient saslClient;

Added: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SaslClientTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SaslClientTest.java?rev=1524364&view=auto
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SaslClientTest.java (added)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SaslClientTest.java Wed Sep 18
10:58:32 2013
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zookeeper.test;
+
+import org.apache.zookeeper.ZKTestCase;
+import org.apache.zookeeper.client.ZooKeeperSaslClient;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Arrays;
+
+public class SaslClientTest extends ZKTestCase {
+
+    private String existingPropertyValue = null;
+
+    @Before
+    public void setUp() {
+        existingPropertyValue = System.getProperty(ZooKeeperSaslClient.ENABLE_CLIENT_SASL_KEY);
+    }
+
+    @After
+    public void tearDown() {
+        // Restore the System property if it was set previously
+        if (existingPropertyValue != null) {
+            System.setProperty(ZooKeeperSaslClient.ENABLE_CLIENT_SASL_KEY, existingPropertyValue);
+        }
+    }
+
+    @Test
+    public void testSaslClientDisabled() {
+        System.clearProperty(ZooKeeperSaslClient.ENABLE_CLIENT_SASL_KEY);
+        Assert.assertTrue("SASL client disabled", ZooKeeperSaslClient.isEnabled());
+
+        for (String value : Arrays.asList("true", "TRUE")) {
+            System.setProperty(ZooKeeperSaslClient.ENABLE_CLIENT_SASL_KEY, value);
+            Assert.assertTrue("SASL client disabled", ZooKeeperSaslClient.isEnabled());
+        }
+
+        for (String value : Arrays.asList("false", "FALSE")) {
+            System.setProperty(ZooKeeperSaslClient.ENABLE_CLIENT_SASL_KEY, value);
+            Assert.assertFalse("SASL client disabled", ZooKeeperSaslClient.isEnabled());
+        }
+    }
+}



Mime
View raw message