-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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. In this commit, ConnectionStateListenerDecorator is removed in favor of ConnectionStateListenerManagerFactory. ConnectionStateManager uses this factory to create the container to hold registered ConnectionStateListeners. A new CircuitBreakerManager now manages the circuit breaking behavior using a shared CircuitBreaker.
- Loading branch information
randgalt
committed
Aug 12, 2019
1 parent
b5eea4c
commit 066ff40
Showing
17 changed files
with
357 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...tor-framework/src/main/java/org/apache/curator/framework/listen/UnaryListenerManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.curator.framework.listen; | ||
|
||
/** | ||
* A {@link ListenerManager} that doesn't do any mapping | ||
*/ | ||
public interface UnaryListenerManager<T> extends ListenerManager<T, T> | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...or-framework/src/main/java/org/apache/curator/framework/state/CircuitBreakingManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.curator.framework.state; | ||
|
||
import org.apache.curator.framework.CuratorFramework; | ||
import org.apache.curator.framework.listen.StandardListenerManager; | ||
import org.apache.curator.framework.listen.UnaryListenerManager; | ||
import java.util.concurrent.Executor; | ||
import java.util.function.Consumer; | ||
|
||
class CircuitBreakingManager implements UnaryListenerManager<ConnectionStateListener> | ||
{ | ||
private final StandardListenerManager<ConnectionStateListener> mainContainer = StandardListenerManager.standard(); | ||
private final StandardListenerManager<ConnectionStateListener> doNotProxyContainer = StandardListenerManager.standard(); | ||
private final CircuitBreakingConnectionStateListener masterListener; | ||
|
||
CircuitBreakingManager(CuratorFramework client, CircuitBreaker circuitBreaker) | ||
{ | ||
ConnectionStateListener masterStateChanged = (__, newState) -> mainContainer.forEach(listener -> listener.stateChanged(client, newState)); | ||
masterListener = new CircuitBreakingConnectionStateListener(client, masterStateChanged, circuitBreaker); | ||
} | ||
|
||
@Override | ||
public void clear() | ||
{ | ||
doNotProxyContainer.clear(); | ||
mainContainer.clear(); | ||
} | ||
|
||
@Override | ||
public int size() | ||
{ | ||
return mainContainer.size() + doNotProxyContainer.size(); | ||
} | ||
|
||
@Override | ||
public void forEach(Consumer<ConnectionStateListener> function) | ||
{ | ||
doNotProxyContainer.forEach(function); | ||
function.accept(masterListener); | ||
} | ||
|
||
@Override | ||
public void addListener(ConnectionStateListener listener) | ||
{ | ||
if ( listener.doNotProxy() ) | ||
{ | ||
doNotProxyContainer.addListener(listener); | ||
} | ||
else | ||
{ | ||
mainContainer.addListener(listener); | ||
} | ||
} | ||
|
||
@Override | ||
public void addListener(ConnectionStateListener listener, Executor executor) | ||
{ | ||
if ( listener.doNotProxy() ) | ||
{ | ||
doNotProxyContainer.addListener(listener, executor); | ||
} | ||
else | ||
{ | ||
mainContainer.addListener(listener, executor); | ||
} | ||
} | ||
|
||
@Override | ||
public void removeListener(ConnectionStateListener listener) | ||
{ | ||
mainContainer.removeListener(listener); | ||
doNotProxyContainer.removeListener(listener); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.