curator-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Work logged] (CURATOR-533) Improve CURATOR-505 by making the CircuitBreaker instance shared
Date Mon, 12 Aug 2019 14:34:00 GMT

     [ https://issues.apache.org/jira/browse/CURATOR-533?focusedWorklogId=293172&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-293172
]

ASF GitHub Bot logged work on CURATOR-533:
------------------------------------------

                Author: ASF GitHub Bot
            Created on: 12/Aug/19 14:33
            Start Date: 12/Aug/19 14:33
    Worklog Time Spent: 10m 
      Work Description: Randgalt commented on pull request #320: [CURATOR-533] - improve circuit
breaking behavior
URL: https://github.com/apache/curator/pull/320#discussion_r312956306
 
 

 ##########
 File path: curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatch.java
 ##########
 @@ -43,60 +43,119 @@
 import org.testng.annotations.Test;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.Callable;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorCompletionService;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
 
 public class TestLeaderLatch extends BaseClassForTests
 {
     private static final String PATH_NAME = "/one/two/me";
     private static final int MAX_LOOPS = 5;
 
+    private static class Holder
+    {
+        final AtomicInteger stateChangeCount = new AtomicInteger(0);
+        final CountDownLatch isLockedLatch = new CountDownLatch(1);
+        volatile LeaderLatch latch;
+    }
+
     @Test
     public void testWithCircuitBreaker() throws Exception
     {
+        final int threadQty = 5;
+
+        ExecutorService executorService = Executors.newFixedThreadPool(threadQty);
+        List<Holder> holders = Collections.emptyList();
         Timing2 timing = new Timing2();
-        ConnectionStateListenerDecorator decorator = ConnectionStateListenerDecorator.circuitBreaking(new
RetryForever(timing.multiple(2).milliseconds()));
-        try ( CuratorFramework client = CuratorFrameworkFactory.builder()
+        ConnectionStateListenerManagerFactory managerFactory = ConnectionStateListenerManagerFactory.circuitBreaking(new
RetryForever(timing.multiple(2).milliseconds()));
+        CuratorFramework client = CuratorFrameworkFactory.builder()
             .connectString(server.getConnectString())
             .retryPolicy(new RetryOneTime(1))
-            .connectionStateListenerDecorator(decorator)
+            .connectionStateListenerManagerFactory(managerFactory)
             .connectionTimeoutMs(timing.connection())
             .sessionTimeoutMs(timing.session())
-            .build() )
-        {
+            .build();
+        try {
             client.start();
-            AtomicInteger resetCount = new AtomicInteger(0);
-            try ( LeaderLatch latch = new LeaderLatch(client, "/foo/bar")
+            client.create().forPath("/hey");
+
+            Semaphore lostSemaphore = new Semaphore(0);
+            ConnectionStateListener undecoratedListener = new ConnectionStateListener()
             {
                 @Override
-                void reset() throws Exception
+                public void stateChanged(CuratorFramework client, ConnectionState newState)
                 {
-                    resetCount.incrementAndGet();
-                    super.reset();
+                    if ( newState == ConnectionState.LOST )
+                    {
+                        lostSemaphore.release();
+                    }
                 }
-            } )
-            {
-                latch.start();
-                Assert.assertTrue(latch.await(timing.forWaiting().milliseconds(), TimeUnit.MILLISECONDS));
 
-                for ( int i = 0; i < 5; ++i )
+                @Override
+                public boolean doNotProxy()
                 {
-                    server.stop();
-                    server.restart();
-                    timing.sleepABit();
+                    return true;
                 }
-                Assert.assertTrue(latch.await(timing.forWaiting().milliseconds(), TimeUnit.MILLISECONDS));
-                Assert.assertEquals(resetCount.get(), 2);
+            };
+            client.getConnectionStateListenable().addListener(undecoratedListener);
+
+            holders = IntStream.range(0, threadQty)
+                .mapToObj(index -> {
+                    Holder holder = new Holder();
+                    holder.latch = new LeaderLatch(client, "/foo/bar/" + index)
+                    {
+                        @Override
+                        protected void handleStateChange(ConnectionState newState)
+                        {
+                            holder.stateChangeCount.incrementAndGet();
+                            super.handleStateChange(newState);
+                        }
+                    };
+                    return holder;
+                })
+                .collect(Collectors.toList());
+
+            holders.forEach(holder -> {
+                executorService.submit(() -> {
+                    holder.latch.start();
+                    Assert.assertTrue(holder.latch.await(timing.forWaiting().milliseconds(),
TimeUnit.MILLISECONDS));
+                    holder.isLockedLatch.countDown();
+                    return null;
+                });
+                timing.awaitLatch(holder.isLockedLatch);
+            });
+
+            for ( int i = 0; i < 5; ++i )
+            {
+                server.stop();
+                Assert.assertTrue(timing.acquireSemaphore(lostSemaphore));
+                server.restart();
+                timing.sleepABit();
             }
+
+            for ( Holder holder : holders )
+            {
+                Assert.assertTrue(holder.latch.await(timing.forWaiting().milliseconds(),
TimeUnit.MILLISECONDS));
+                Assert.assertEquals(holder.stateChangeCount.get(), 3);  // 1 suspend, 1 lost,
1 reconnected
 
 Review comment:
   done
 
----------------------------------------------------------------
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:
users@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 293172)
    Time Spent: 2h 50m  (was: 2h 40m)

> Improve CURATOR-505 by making the CircuitBreaker instance shared
> ----------------------------------------------------------------
>
>                 Key: CURATOR-533
>                 URL: https://issues.apache.org/jira/browse/CURATOR-533
>             Project: Apache Curator
>          Issue Type: Improvement
>          Components: Framework, Recipes
>    Affects Versions: 4.2.0
>            Reporter: Jordan Zimmerman
>            Assignee: Jordan Zimmerman
>            Priority: Major
>             Fix For: 4.2.1
>
>          Time Spent: 2h 50m
>  Remaining Estimate: 0h
>
> CURATOR-505 introduced circuit breaking behavior via {{CircuitBreakingConnectionStateListener}}
and {{ConnectionStateListenerDecorator}}. Elastic has been using it to success but reports
that the implementation can be improved. The existing implementation uses a new {{CircuitBreaker}}
for each {{ConnectionStateListener}} set in a Curator client. It turns out that this is not
ideal. Instead, a shared {{CircuitBreaker}} should be used per Curator client.
> Unfortunately, the best way to do this is to remove the {{ConnectionStateListenerDecorator}}
semantics and use a different mechanism. This Issue proposes to do this and remove {{ConnectionStateListenerDecorator}}.
This is a breaking change but given the short amount of time it's been in Curator it's unlikely
that it's been widely adopted. 
> If the community considers a breaking change too harsh the older classes can be maintained
for a while and marked as {{@Deprecated}}.



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

Mime
View raw message