Sfoglia il codice sorgente

ZOOKEEPER-3821: Improve getSnapCount and getGlobalOutstandingLimit

Author: dengliming <liming.d.pro@gmail.com>

Reviewers: Enrico Olivelli <eolivelli@apache.org>, Andor Molnar <anmolnar@apache.org>, maoling <maoling@apache.org>

Closes #1352 from dengliming/ZOOKEEPER-3821
dengliming 4 anni fa
parent
commit
32e40e8cee

+ 9 - 20
zookeeper-server/src/main/java/org/apache/zookeeper/server/ZooKeeperServer.java

@@ -194,6 +194,8 @@ public class ZooKeeperServer implements SessionExpirer, ServerStats.Provider {
     protected String initialConfig;
     protected String initialConfig;
     protected boolean reconfigEnabled;
     protected boolean reconfigEnabled;
     private final RequestPathMetricsCollector requestPathMetricsCollector;
     private final RequestPathMetricsCollector requestPathMetricsCollector;
+    private static final int DEFAULT_SNAP_COUNT = 100000;
+    private static final int DEFAULT_GLOBAL_OUTSTANDING_LIMIT = 1000;
 
 
     private boolean localSessionEnabled = false;
     private boolean localSessionEnabled = false;
     protected enum State {
     protected enum State {
@@ -1183,30 +1185,17 @@ public class ZooKeeperServer implements SessionExpirer, ServerStats.Provider {
     }
     }
 
 
     public static int getSnapCount() {
     public static int getSnapCount() {
-        String sc = System.getProperty(SNAP_COUNT);
-        try {
-            int snapCount = Integer.parseInt(sc);
-
-            // snapCount must be 2 or more. See org.apache.zookeeper.server.SyncRequestProcessor
-            if (snapCount < 2) {
-                LOG.warn("SnapCount should be 2 or more. Now, snapCount is reset to 2");
-                snapCount = 2;
-            }
-            return snapCount;
-        } catch (Exception e) {
-            return 100000;
+        int snapCount = Integer.getInteger(SNAP_COUNT, DEFAULT_SNAP_COUNT);
+        // snapCount must be 2 or more. See org.apache.zookeeper.server.SyncRequestProcessor
+        if (snapCount < 2) {
+            LOG.warn("SnapCount should be 2 or more. Now, snapCount is reset to 2");
+            snapCount = 2;
         }
         }
+        return snapCount;
     }
     }
 
 
     public int getGlobalOutstandingLimit() {
     public int getGlobalOutstandingLimit() {
-        String sc = System.getProperty(GLOBAL_OUTSTANDING_LIMIT);
-        int limit;
-        try {
-            limit = Integer.parseInt(sc);
-        } catch (Exception e) {
-            limit = 1000;
-        }
-        return limit;
+        return Integer.getInteger(GLOBAL_OUTSTANDING_LIMIT, DEFAULT_GLOBAL_OUTSTANDING_LIMIT);
     }
     }
 
 
     public static long getSnapSizeInBytes() {
     public static long getSnapSizeInBytes() {