This is an automated email from the ASF dual-hosted git repository.

sijie pushed a commit to branch branch-4.7
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/branch-4.7 by this push:
     new 0cea52e  Allow to configure read-only mode in ZooKeeperClient
0cea52e is described below

commit 0cea52e75e669daae72407ef50e52ad7506bffc9
Author: Sijie Guo <si...@apache.org>
AuthorDate: Wed Jun 13 17:35:34 2018 -0700

    Allow to configure read-only mode in ZooKeeperClient
    
    Underlying `Zookeeper` instance has an option to specify the client is fine 
to remain connected when the ZK quorum is lost, just in read-only mode.
    
    We should expose the "allow read-only mode" option in `ZooKeeperClient`.
    
    One example of use case for this flag is when connecting to a ZK ensemble 
that is just used for configuration/metadata store, in which no ephemeral nodes 
are used. It's therefore better to keep the connection with ZK and be able to 
keep reading (possibly stale) data from ZK rather than no read at all. Concrete 
use case is for ZK session for Pulsar global ZK ensemble, where we read 
configuration data and we don't really need to have a valid session when 
brokers are trying to read.
    
    Author: Sijie Guo <si...@apache.org>
    Author: Matteo Merli <mme...@apache.org>
    
    Reviewers: Ivan Kelly <iv...@apache.org>, Enrico Olivelli 
<eolive...@gmail.com>, Jia Zhai <None>, Sijie Guo <si...@apache.org>
    
    This closes #1344 from merlimat/zk-client-read-only
    
    (cherry picked from commit 9f55f78815c80d6b335d8e1cf6fd91196aeb8cff)
    Signed-off-by: Sijie Guo <si...@apache.org>
---
 .../apache/bookkeeper/zookeeper/ZooKeeperClient.java   | 18 ++++++++++++++----
 .../bookkeeper/zookeeper/TestZooKeeperClient.java      |  2 +-
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/zookeeper/ZooKeeperClient.java
 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/zookeeper/ZooKeeperClient.java
index 8147817..24693ea 100644
--- 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/zookeeper/ZooKeeperClient.java
+++ 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/zookeeper/ZooKeeperClient.java
@@ -77,6 +77,7 @@ public class ZooKeeperClient extends ZooKeeper implements 
Watcher {
     // ZooKeeper client connection variables
     private final String connectString;
     private final int sessionTimeoutMs;
+    private final boolean allowReadOnlyMode;
 
     // state for the zookeeper client
     private final AtomicReference<ZooKeeper> zk = new 
AtomicReference<ZooKeeper>();
@@ -172,6 +173,7 @@ public class ZooKeeperClient extends ZooKeeper implements 
Watcher {
         StatsLogger statsLogger = NullStatsLogger.INSTANCE;
         int retryExecThreadCount = DEFAULT_RETRY_EXECUTOR_THREAD_COUNT;
         double requestRateLimit = 0;
+        boolean allowReadOnlyMode = false;
 
         private Builder() {}
 
@@ -215,6 +217,11 @@ public class ZooKeeperClient extends ZooKeeper implements 
Watcher {
             return this;
         }
 
+        public Builder allowReadOnlyMode(boolean allowReadOnlyMode) {
+            this.allowReadOnlyMode = allowReadOnlyMode;
+            return this;
+        }
+
         public ZooKeeperClient build() throws IOException, KeeperException, 
InterruptedException {
             checkNotNull(connectString);
             checkArgument(sessionTimeoutMs > 0);
@@ -243,7 +250,8 @@ public class ZooKeeperClient extends ZooKeeper implements 
Watcher {
                     operationRetryPolicy,
                     statsLogger,
                     retryExecThreadCount,
-                    requestRateLimit
+                    requestRateLimit,
+                    allowReadOnlyMode
             );
             // Wait for connection to be established.
             try {
@@ -271,10 +279,12 @@ public class ZooKeeperClient extends ZooKeeper implements 
Watcher {
                     RetryPolicy operationRetryPolicy,
                     StatsLogger statsLogger,
                     int retryExecThreadCount,
-                    double rate) throws IOException {
-        super(connectString, sessionTimeoutMs, watcherManager);
+                    double rate,
+                    boolean allowReadOnlyMode) throws IOException {
+        super(connectString, sessionTimeoutMs, watcherManager, 
allowReadOnlyMode);
         this.connectString = connectString;
         this.sessionTimeoutMs = sessionTimeoutMs;
+        this.allowReadOnlyMode =  allowReadOnlyMode;
         this.watcherManager = watcherManager;
         this.connectRetryPolicy = connectRetryPolicy;
         this.operationRetryPolicy = operationRetryPolicy;
@@ -325,7 +335,7 @@ public class ZooKeeperClient extends ZooKeeper implements 
Watcher {
     }
 
     protected ZooKeeper createZooKeeper() throws IOException {
-        return new ZooKeeper(connectString, sessionTimeoutMs, watcherManager);
+        return new ZooKeeper(connectString, sessionTimeoutMs, watcherManager, 
allowReadOnlyMode);
     }
 
     @Override
diff --git 
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/zookeeper/TestZooKeeperClient.java
 
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/zookeeper/TestZooKeeperClient.java
index c2aaf90..8e88418 100644
--- 
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/zookeeper/TestZooKeeperClient.java
+++ 
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/zookeeper/TestZooKeeperClient.java
@@ -115,7 +115,7 @@ public class TestZooKeeperClient extends TestCase {
             super(connectString, sessionTimeoutMs, watcher,
                     new BoundExponentialBackoffRetryPolicy(sessionTimeoutMs, 
sessionTimeoutMs, Integer.MAX_VALUE),
                     operationRetryPolicy,
-                    NullStatsLogger.INSTANCE, 1, 0);
+                    NullStatsLogger.INSTANCE, 1, 0, false);
         }
 
         @Override

-- 
To stop receiving notification emails like this one, please contact
si...@apache.org.

Reply via email to