[
https://issues.apache.org/jira/browse/CURATOR-533?focusedWorklogId=292713&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-292713
]
ASF GitHub Bot logged work on CURATOR-533:
------------------------------------------
Author: ASF GitHub Bot
Created on: 11/Aug/19 14:39
Start Date: 11/Aug/19 14:39
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_r312741836
##########
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 )
Review comment:
actually not - just a coincidence. I'll make it `6` so this is clear
----------------------------------------------------------------
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]
Issue Time Tracking
-------------------
Worklog Id: (was: 292713)
Time Spent: 2h 10m (was: 2h)
> 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 10m
> 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)