anmolnar commented on a change in pull request #419: ZOOKEEPER-2849: 
Exponential back-off retry for Quorum port binding
URL: https://github.com/apache/zookeeper/pull/419#discussion_r152395245
 
 

 ##########
 File path: src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
 ##########
 @@ -963,6 +963,107 @@ protected Election createElectionAlgorithm(int 
electionAlgorithm){
         return le;
     }
 
+    /**
+     * Support setting the exponential backoff strategy via a system property.
+     */
+    public static final String BACKOFF_STRATEGY = 
"zookeeper.quorum.backoffStrategy";
+
+    /**
+     * Support configuring the fixed interval backoff strategy via a system 
property.
+     */
+    public static final String FIXED_INTERVAL_BACKOFF_INTERVALS = 
"zookeeper.quorum.fixedIntervalBackoff.intervalMillis";
+
+    /**
+     * Support configuring the fixed interval backoff strategy via a system 
property.
+     */
+    public static final String FIXED_INTERVAL_BACKOFF_INTERVAL_MILLIS = 
"zookeeper.quorum.fixedIntervalBackoff.intervals";
+
+    /**
+     * Support setting the exponential backoff strategy via a system property.
+     */
+    public static final String EXPONENTIAL_BACKOFF = 
"zookeeper.quorum.exponentialBackoff";
+
+    /**
+     * Support configuring the fixed interval backoff strategy via a system 
property.
+     */
+    public static final String EXPONENTIAL_BACKOFF_INITIAL = 
"zookeeper.quorum.exponentialBackoff.initialBackoff";
+
+    /**
+     * Support configuring the fixed interval backoff strategy via a system 
property.
+     */
+    public static final String EXPONENTIAL_BACKOFF_MULTIPLIER = 
"zookeeper.quorum.exponentialBackoff.multiplier";
+
+    /**
+     * Support configuring the fixed interval backoff strategy via a system 
property.
+     */
+    public static final String EXPONENTIAL_BACKOFF_MAX_ELAPSED = 
"zookeeper.quorum.exponentialBackoff.maxElapsedMillis";
+
+    /**
+     * Support configuring the fixed interval backoff strategy via a system 
property.
+     */
+    public static final String EXPONENTIAL_BACKOFF_MAX_BACKOFF = 
"zookeeper.quorum.exponentialBackoff.maxBackoffMillis";
+
+    /**
+     * Construct the {@link BackoffStrategy} to use.
+     * @return the constructed BackoffStrategy
+     */
+    protected BackoffStrategy buildBackoffStrategy() {
+
+        // check for external BackoffStrategy
+        final String externalBackoffStrategy = 
System.getProperty(BACKOFF_STRATEGY);
+        if(externalBackoffStrategy != null) {
+            try {
+                return (BackoffStrategy) 
Class.forName(externalBackoffStrategy).newInstance();
+            } catch(ClassNotFoundException cnfe) {
+                LOG.warn("Unable to load BackoffStrategy {}, default to 
Zookeeper internal BackoffStrategy",
+                    externalBackoffStrategy);
+            } catch(InstantiationException | IllegalAccessException ex) {
+                LOG.warn("Unable to construct BackoffStrategy {}, default to 
Zookeeper internal BackoffStrategy",
+                    externalBackoffStrategy);
+            }
+        }
+
+        // if the user specifies the exponential back, configure and create it
+        if(Boolean.getBoolean(EXPONENTIAL_BACKOFF)) {
+            final ExponentialBackoffStrategy.Builder builder = 
ExponentialBackoffStrategy.builder();
+
+            if(Long.getLong(EXPONENTIAL_BACKOFF_INITIAL) != null) {
+                
builder.setInitialBackoff(Long.getLong(EXPONENTIAL_BACKOFF_INITIAL));
+            }
+
+            if(Long.getLong(EXPONENTIAL_BACKOFF_MAX_ELAPSED) != null) {
+                
builder.setMaxElapsed(Long.getLong(EXPONENTIAL_BACKOFF_MAX_ELAPSED));
+            }
+
+            if(Long.getLong(EXPONENTIAL_BACKOFF_MAX_BACKOFF) != null) {
+                
builder.setMaxBackoff(Long.getLong(EXPONENTIAL_BACKOFF_MAX_BACKOFF));
+            }
+
+            final String multiplierProp = 
System.getProperty(EXPONENTIAL_BACKOFF_MULTIPLIER);
+            if(multiplierProp != null) {
+                try {
+                    
builder.setBackoffMultiplier(Double.valueOf(multiplierProp));
+                } catch(NumberFormatException nfe) {
+                    LOG.warn("{} is not a valid floating point value, ignoring 
it.", multiplierProp);
 
 Review comment:
   I suggest to add:
   ...floating point value **for backoffMultiplier**, ignoring...

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to