You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2020/05/07 22:42:53 UTC

[curator] branch master updated (5223466 -> 092c1e3)

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

randgalt pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/curator.git.


    from 5223466  Document breaking changes
     new 61d2817  JIRA:CURATOR-568
     new 092c1e3  JIRA:CURATOR-568

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../curator/framework/CuratorFrameworkFactory.java | 25 ++++++++++
 .../framework/imps/CuratorFrameworkImpl.java       |  2 +-
 .../framework/imps/TestReconfiguration.java        | 56 +++++++++++++++++++++-
 3 files changed, 80 insertions(+), 3 deletions(-)


[curator] 01/02: JIRA:CURATOR-568

Posted by ra...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

randgalt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/curator.git

commit 61d281721f06ba85cf3b764c332da904353fb2b0
Author: chevaris <ev...@yahoo.es>
AuthorDate: Wed May 6 09:54:55 2020 +0200

    JIRA:CURATOR-568
    
    - Adding ensembleTracker(boolean) and withEnsembleTracker() methods to
    CuratorFrameworkFactory.builder() that allows enabling/disabling
    ensemble tracking
---
 .../curator/framework/CuratorFrameworkFactory.java | 25 ++++++++++
 .../framework/imps/CuratorFrameworkImpl.java       |  2 +-
 .../framework/imps/TestReconfiguration.java        | 56 +++++++++++++++++++++-
 3 files changed, 80 insertions(+), 3 deletions(-)

diff --git a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java
index 7980e1e..37db325 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java
@@ -66,6 +66,7 @@ public class CuratorFrameworkFactory
     private static final DefaultACLProvider DEFAULT_ACL_PROVIDER = new DefaultACLProvider();
     private static final long DEFAULT_INACTIVE_THRESHOLD_MS = (int)TimeUnit.MINUTES.toMillis(3);
     private static final int DEFAULT_CLOSE_WAIT_MS = (int)TimeUnit.SECONDS.toMillis(1);
+    private static final boolean DEFAULT_WITH_ENSEMBLE_TRACKER = true;
 
     /**
      * Return a new builder that builds a CuratorFramework
@@ -129,6 +130,7 @@ public class CuratorFrameworkFactory
     public static class Builder
     {
         private EnsembleProvider ensembleProvider;
+        private boolean withEnsembleTracker = DEFAULT_WITH_ENSEMBLE_TRACKER;
         private int sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT_MS;
         private int connectionTimeoutMs = DEFAULT_CONNECTION_TIMEOUT_MS;
         private int maxCloseWaitMs = DEFAULT_CLOSE_WAIT_MS;
@@ -243,6 +245,29 @@ public class CuratorFrameworkFactory
         }
 
         /**
+         * Allows to configure if the ensemble configuration changes will be watched.
+         * The default value is {@code true}.<br>
+         * 
+         * IMPORTANT: Use this method in combination with {@link #ensembleProvider(EnsembleProvider)} to provide
+         * and instance that returns {@code false} on {@link EnsembleProvider#updateServerListEnabled()} in order
+         * to fully achieve that ensemble server list changes are ignored<br>
+         * 
+         * @param withTracker use {@code false} if you want to avoid following ensemble configuration changes
+         * @return this
+         */
+        public Builder ensembleTracker(boolean withEnsembleTracker) {
+            this.withEnsembleTracker = withEnsembleTracker;
+            return this;
+        }
+
+        /**
+         * @return {@code true} if ensemble configuration changes MUST be watched
+         */
+        public boolean withEnsembleTracker() {
+            return withEnsembleTracker;
+        }
+
+        /**
          * Sets the data to use when {@link PathAndBytesable#forPath(String)} is used.
          * This is useful for debugging purposes. For example, you could set this to be the IP of the
          * client.
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
index d4d8241..d80c20b 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
@@ -153,7 +153,7 @@ public class CuratorFrameworkImpl implements CuratorFramework
         failedRemoveWatcherManager = new FailedRemoveWatchManager(this);
         namespaceFacadeCache = new NamespaceFacadeCache(this);
 
-        ensembleTracker = new EnsembleTracker(this, builder.getEnsembleProvider());
+        ensembleTracker = builder.withEnsembleTracker() ? new EnsembleTracker(this, builder.getEnsembleProvider()) : null;
 
         runSafeService = makeRunSafeService(builder);
     }
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
index e3327e0..500e728 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
@@ -26,6 +26,7 @@ import org.apache.curator.framework.CuratorFrameworkFactory;
 import org.apache.curator.framework.api.BackgroundCallback;
 import org.apache.curator.framework.api.CuratorEvent;
 import org.apache.curator.framework.api.CuratorEventType;
+import org.apache.curator.framework.state.ConnectionState;
 import org.apache.curator.retry.ExponentialBackoffRetry;
 import org.apache.curator.test.InstanceSpec;
 import org.apache.curator.test.TestingCluster;
@@ -54,6 +55,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Properties;
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
 
 public class TestReconfiguration extends CuratorTestBase
@@ -174,6 +176,51 @@ public class TestReconfiguration extends CuratorTestBase
     }
 
     @Test
+    public void testAddWithoutEnsembleTracker() throws Exception
+    {
+        final String initialClusterCS = cluster.getConnectString();
+        try ( CuratorFramework client = newClient(cluster.getConnectString(), false))
+        {
+            Assert.assertEquals(((CuratorFrameworkImpl) client).getEnsembleTracker(), null);
+            client.start();
+
+            QuorumVerifier oldConfig = toQuorumVerifier(client.getConfig().forEnsemble());
+            assertConfig(oldConfig, cluster.getInstances());
+
+            CountDownLatch latch = setChangeWaiter(client);
+            try ( TestingCluster newCluster = new TestingCluster(TestingCluster.makeSpecs(1, false)) )
+            {
+                newCluster.start();
+
+                client.reconfig().joining(toReconfigSpec(newCluster.getInstances())).fromConfig(oldConfig.getVersion()).forEnsemble();
+
+                Assert.assertTrue(timing.awaitLatch(latch));
+
+                byte[] newConfigData = client.getConfig().forEnsemble();
+                QuorumVerifier newConfig = toQuorumVerifier(newConfigData);
+                List<InstanceSpec> newInstances = Lists.newArrayList(cluster.getInstances());
+                newInstances.addAll(newCluster.getInstances());
+                assertConfig(newConfig, newInstances);
+                Assert.assertEquals(ensembleProvider.getConnectionString(), initialClusterCS);
+                Assert.assertNotEquals(EnsembleTracker.configToConnectionString(newConfig), ensembleProvider.getConnectionString());
+                Assert.assertEquals(client.getZookeeperClient().getCurrentConnectionString(), initialClusterCS);
+                final CountDownLatch reconnectLatch = new CountDownLatch(1);
+                client.getConnectionStateListenable().addListener(
+                    (cfClient, newState) -> {
+                        if (newState == ConnectionState.RECONNECTED) reconnectLatch.countDown();
+                    }
+                );
+                client.getZookeeperClient().getZooKeeper().getTestable().injectSessionExpiration();
+                Assert.assertTrue(reconnectLatch.await(2, TimeUnit.SECONDS));
+                Assert.assertEquals(client.getZookeeperClient().getCurrentConnectionString(), initialClusterCS);
+                Assert.assertEquals(ensembleProvider.getConnectionString(), initialClusterCS);
+                newConfigData = client.getConfig().forEnsemble();
+                Assert.assertNotEquals(EnsembleTracker.configToConnectionString(newConfig), ensembleProvider.getConnectionString());
+            }
+        }
+    }
+
+    @Test
     public void testAdd() throws Exception
     {
         try ( CuratorFramework client = newClient())
@@ -412,10 +459,14 @@ public class TestReconfiguration extends CuratorTestBase
 
     private CuratorFramework newClient()
     {
-        return newClient(cluster.getConnectString());
+        return newClient(cluster.getConnectString(), true);
+    }
+    
+    private CuratorFramework newClient(String connectionString) {
+    	return newClient(connectionString, true);
     }
 
-    private CuratorFramework newClient(String connectionString)
+    private CuratorFramework newClient(String connectionString, boolean withEnsembleProvider)
     {
         final AtomicReference<String> connectString = new AtomicReference<>(connectionString);
         ensembleProvider = new EnsembleProvider()
@@ -450,6 +501,7 @@ public class TestReconfiguration extends CuratorTestBase
         };
         return CuratorFrameworkFactory.builder()
             .ensembleProvider(ensembleProvider)
+            .ensembleTracker(withEnsembleProvider)
             .sessionTimeoutMs(timing.session())
             .connectionTimeoutMs(timing.connection())
             .authorization("digest", superUserPassword.getBytes())


[curator] 02/02: JIRA:CURATOR-568

Posted by ra...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

randgalt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/curator.git

commit 092c1e3f34c9e53d2dbf29c37f060e47a6fb74a1
Author: chevaris <ev...@yahoo.es>
AuthorDate: Thu May 7 09:22:30 2020 +0200

    JIRA:CURATOR-568
    
    - Javadoc typo
---
 .../java/org/apache/curator/framework/CuratorFrameworkFactory.java    | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java
index 37db325..ca5b203 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java
@@ -249,10 +249,10 @@ public class CuratorFrameworkFactory
          * The default value is {@code true}.<br>
          * 
          * IMPORTANT: Use this method in combination with {@link #ensembleProvider(EnsembleProvider)} to provide
-         * and instance that returns {@code false} on {@link EnsembleProvider#updateServerListEnabled()} in order
+         * an instance that returns {@code false} on {@link EnsembleProvider#updateServerListEnabled()} in order
          * to fully achieve that ensemble server list changes are ignored<br>
          * 
-         * @param withTracker use {@code false} if you want to avoid following ensemble configuration changes
+         * @param withEnsembleTracker use {@code false} if you want to avoid following ensemble configuration changes
          * @return this
          */
         public Builder ensembleTracker(boolean withEnsembleTracker) {