Package com.linkedin.venice.helix
Class ZkRoutersClusterManager
java.lang.Object
com.linkedin.venice.helix.ZkRoutersClusterManager
- All Implemented Interfaces:
RoutersClusterManager
,VeniceResource
,org.apache.helix.zookeeper.zkclient.IZkChildListener
,org.apache.helix.zookeeper.zkclient.IZkDataListener
,org.apache.helix.zookeeper.zkclient.IZkStateListener
public class ZkRoutersClusterManager
extends Object
implements RoutersClusterManager, org.apache.helix.zookeeper.zkclient.IZkChildListener, org.apache.helix.zookeeper.zkclient.IZkDataListener, VeniceResource, org.apache.helix.zookeeper.zkclient.IZkStateListener
Manage live routers through Zookeeper. Help each router to create a ZNode which reflects whether that router is
connected to ZK cluster or not and monitor all routers' ZNodes to get how many routers live right now.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.linkedin.venice.meta.RoutersClusterManager
RoutersClusterManager.RouterCountChangedListener
-
Constructor Summary
ConstructorDescriptionZkRoutersClusterManager
(org.apache.helix.zookeeper.impl.client.ZkClient zkClient, HelixAdapterSerializer adapter, String clusterName, int refreshAttemptsForZkReconnect, long refreshIntervalForZkReconnectInMs) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
changeLiveRouterCount
(int newRouterCount) void
clear()
void
void
enableMaxCapacityProtection
(boolean enable) Enable or disable max read capacity protection feature on router.void
enableThrottling
(boolean enable) Enable or disable read throttling feature on router.int
Get the expected number of routers in the cluster.int
Get how many routers live right now.protected final String
void
handleChildChange
(String parentPath, List<String> currentChildren) Once a router instance is added/remove from cluster, its ephemeral zk node will be added/removed, then this handler will be executed to process the event.void
handleDataChange
(String dataPath, Object data) Once router cluster config is changed(Both cluster level or router level config is changed), its persistent zk node's data will be changed, then this handler will be executed to process the event.void
handleDataDeleted
(String dataPath) void
void
handleSessionEstablishmentError
(Throwable throwable) void
handleStateChanged
(org.apache.zookeeper.Watcher.Event.KeeperState keeperState) boolean
boolean
void
refresh()
void
registerRouter
(String instanceId) Create a ephemeral ZNode for the give router.void
Listen on the router count, get the notification once it's changed.protected void
triggerRouterCountChangedEvent
(int newRouterCount) void
unregisterRouter
(String instanceId) Unregister the given router instance from the cluster.void
updateExpectedRouterCount
(int expectedNumber) Update the expected number of routers in the cluster.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.helix.zookeeper.zkclient.IZkChildListener
handleChildChange
Methods inherited from interface org.apache.helix.zookeeper.zkclient.IZkDataListener
handleDataChange
Methods inherited from interface org.apache.helix.zookeeper.zkclient.IZkStateListener
handleStateChanged
-
Constructor Details
-
ZkRoutersClusterManager
public ZkRoutersClusterManager(org.apache.helix.zookeeper.impl.client.ZkClient zkClient, HelixAdapterSerializer adapter, String clusterName, int refreshAttemptsForZkReconnect, long refreshIntervalForZkReconnectInMs)
-
-
Method Details
-
refresh
public void refresh()- Specified by:
refresh
in interfaceVeniceResource
-
clear
public void clear()- Specified by:
clear
in interfaceVeniceResource
-
getLiveRouterInstances
- Specified by:
getLiveRouterInstances
in interfaceRoutersClusterManager
-
registerRouter
Create a ephemeral ZNode for the give router. If parent path does not exist, it will help to create that as well.- Specified by:
registerRouter
in interfaceRoutersClusterManager
-
unregisterRouter
Description copied from interface:RoutersClusterManager
Unregister the given router instance from the cluster.- Specified by:
unregisterRouter
in interfaceRoutersClusterManager
-
getLiveRoutersCount
public int getLiveRoutersCount()Get how many routers live right now. It could be a delay because the number will only be update once the manger received the zk notification.- Specified by:
getLiveRoutersCount
in interfaceRoutersClusterManager
-
getExpectedRoutersCount
public int getExpectedRoutersCount()Description copied from interface:RoutersClusterManager
Get the expected number of routers in the cluster.- Specified by:
getExpectedRoutersCount
in interfaceRoutersClusterManager
-
updateExpectedRouterCount
public void updateExpectedRouterCount(int expectedNumber) Description copied from interface:RoutersClusterManager
Update the expected number of routers in the cluster.- Specified by:
updateExpectedRouterCount
in interfaceRoutersClusterManager
-
subscribeRouterCountChangedEvent
public void subscribeRouterCountChangedEvent(RoutersClusterManager.RouterCountChangedListener listener) Description copied from interface:RoutersClusterManager
Listen on the router count, get the notification once it's changed.- Specified by:
subscribeRouterCountChangedEvent
in interfaceRoutersClusterManager
-
isThrottlingEnabled
public boolean isThrottlingEnabled()- Specified by:
isThrottlingEnabled
in interfaceRoutersClusterManager
-
isMaxCapacityProtectionEnabled
public boolean isMaxCapacityProtectionEnabled()- Specified by:
isMaxCapacityProtectionEnabled
in interfaceRoutersClusterManager
-
enableThrottling
public void enableThrottling(boolean enable) Description copied from interface:RoutersClusterManager
Enable or disable read throttling feature on router. If this feature is disable, router will accept all read request regardless of store's quota.- Specified by:
enableThrottling
in interfaceRoutersClusterManager
-
enableMaxCapacityProtection
public void enableMaxCapacityProtection(boolean enable) Description copied from interface:RoutersClusterManager
Enable or disable max read capacity protection feature on router. If this feature is disabled, router will not protected by pre-defined max read capacity which means the total quota one router assigned might exceed the max capacity that router could serve.- Specified by:
enableMaxCapacityProtection
in interfaceRoutersClusterManager
-
createRouterClusterConfig
public void createRouterClusterConfig()- Specified by:
createRouterClusterConfig
in interfaceRoutersClusterManager
-
getRoutersClusterConfig
-
changeLiveRouterCount
protected void changeLiveRouterCount(int newRouterCount) -
triggerRouterCountChangedEvent
protected void triggerRouterCountChangedEvent(int newRouterCount) -
handleChildChange
Once a router instance is added/remove from cluster, its ephemeral zk node will be added/removed, then this handler will be executed to process the event.- Specified by:
handleChildChange
in interfaceorg.apache.helix.zookeeper.zkclient.IZkChildListener
- Throws:
Exception
-
handleDataChange
Once router cluster config is changed(Both cluster level or router level config is changed), its persistent zk node's data will be changed, then this handler will be executed to process the event.Make this method synchronized to avoid the conflict modification of routersClusterConfig.
- Specified by:
handleDataChange
in interfaceorg.apache.helix.zookeeper.zkclient.IZkDataListener
- Throws:
Exception
-
handleDataDeleted
- Specified by:
handleDataDeleted
in interfaceorg.apache.helix.zookeeper.zkclient.IZkDataListener
- Throws:
Exception
-
getRouterRootPath
-
handleStateChanged
public void handleStateChanged(org.apache.zookeeper.Watcher.Event.KeeperState keeperState) - Specified by:
handleStateChanged
in interfaceorg.apache.helix.zookeeper.zkclient.IZkStateListener
-
handleNewSession
- Specified by:
handleNewSession
in interfaceorg.apache.helix.zookeeper.zkclient.IZkStateListener
- Throws:
Exception
-
handleSessionEstablishmentError
- Specified by:
handleSessionEstablishmentError
in interfaceorg.apache.helix.zookeeper.zkclient.IZkStateListener
- Throws:
Exception
-