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 java.lang.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
Constructors Constructor Description ZkRoutersClusterManager(org.apache.helix.zookeeper.impl.client.ZkClient zkClient, HelixAdapterSerializer adapter, java.lang.String clusterName, int refreshAttemptsForZkReconnect, long refreshIntervalForZkReconnectInMs)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
changeLiveRouterCount(int newRouterCount)
void
clear()
void
createRouterClusterConfig()
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
getExpectedRoutersCount()
Get the expected number of routers in the cluster.java.util.Set<Instance>
getLiveRouterInstances()
int
getLiveRoutersCount()
Get how many routers live right now.protected java.lang.String
getRouterRootPath()
RoutersClusterConfig
getRoutersClusterConfig()
void
handleChildChange(java.lang.String parentPath, java.util.List<java.lang.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(java.lang.String dataPath, java.lang.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(java.lang.String dataPath)
void
handleNewSession(java.lang.String s)
void
handleSessionEstablishmentError(java.lang.Throwable throwable)
void
handleStateChanged(org.apache.zookeeper.Watcher.Event.KeeperState keeperState)
boolean
isMaxCapacityProtectionEnabled()
boolean
isThrottlingEnabled()
void
refresh()
void
registerRouter(java.lang.String instanceId)
Create a ephemeral ZNode for the give router.void
subscribeRouterCountChangedEvent(RoutersClusterManager.RouterCountChangedListener listener)
Listen on the router count, get the notification once it's changed.protected void
triggerRouterCountChangedEvent(int newRouterCount)
void
unregisterRouter(java.lang.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
-
-
-
-
Constructor Detail
-
ZkRoutersClusterManager
public ZkRoutersClusterManager(org.apache.helix.zookeeper.impl.client.ZkClient zkClient, HelixAdapterSerializer adapter, java.lang.String clusterName, int refreshAttemptsForZkReconnect, long refreshIntervalForZkReconnectInMs)
-
-
Method Detail
-
refresh
public void refresh()
- Specified by:
refresh
in interfaceVeniceResource
-
clear
public void clear()
- Specified by:
clear
in interfaceVeniceResource
-
getLiveRouterInstances
public java.util.Set<Instance> getLiveRouterInstances()
- Specified by:
getLiveRouterInstances
in interfaceRoutersClusterManager
-
registerRouter
public void registerRouter(java.lang.String instanceId)
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
public void unregisterRouter(java.lang.String instanceId)
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
public RoutersClusterConfig getRoutersClusterConfig()
-
changeLiveRouterCount
protected void changeLiveRouterCount(int newRouterCount)
-
triggerRouterCountChangedEvent
protected void triggerRouterCountChangedEvent(int newRouterCount)
-
handleChildChange
public void handleChildChange(java.lang.String parentPath, java.util.List<java.lang.String> currentChildren) throws java.lang.Exception
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:
java.lang.Exception
-
handleDataChange
public void handleDataChange(java.lang.String dataPath, java.lang.Object data) throws java.lang.Exception
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:
java.lang.Exception
-
handleDataDeleted
public void handleDataDeleted(java.lang.String dataPath) throws java.lang.Exception
- Specified by:
handleDataDeleted
in interfaceorg.apache.helix.zookeeper.zkclient.IZkDataListener
- Throws:
java.lang.Exception
-
getRouterRootPath
protected final java.lang.String getRouterRootPath()
-
handleStateChanged
public void handleStateChanged(org.apache.zookeeper.Watcher.Event.KeeperState keeperState)
- Specified by:
handleStateChanged
in interfaceorg.apache.helix.zookeeper.zkclient.IZkStateListener
-
handleNewSession
public void handleNewSession(java.lang.String s) throws java.lang.Exception
- Specified by:
handleNewSession
in interfaceorg.apache.helix.zookeeper.zkclient.IZkStateListener
- Throws:
java.lang.Exception
-
handleSessionEstablishmentError
public void handleSessionEstablishmentError(java.lang.Throwable throwable) throws java.lang.Exception
- Specified by:
handleSessionEstablishmentError
in interfaceorg.apache.helix.zookeeper.zkclient.IZkStateListener
- Throws:
java.lang.Exception
-
-