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.
  • 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 interface VeniceResource
    • clear

      public void clear()
      Specified by:
      clear in interface VeniceResource
    • getLiveRouterInstances

      public Set<Instance> getLiveRouterInstances()
      Specified by:
      getLiveRouterInstances in interface RoutersClusterManager
    • registerRouter

      public void registerRouter(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 interface RoutersClusterManager
    • unregisterRouter

      public void unregisterRouter(String instanceId)
      Description copied from interface: RoutersClusterManager
      Unregister the given router instance from the cluster.
      Specified by:
      unregisterRouter in interface RoutersClusterManager
    • 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 interface RoutersClusterManager
    • getExpectedRoutersCount

      public int getExpectedRoutersCount()
      Description copied from interface: RoutersClusterManager
      Get the expected number of routers in the cluster.
      Specified by:
      getExpectedRoutersCount in interface RoutersClusterManager
    • updateExpectedRouterCount

      public void updateExpectedRouterCount(int expectedNumber)
      Description copied from interface: RoutersClusterManager
      Update the expected number of routers in the cluster.
      Specified by:
      updateExpectedRouterCount in interface RoutersClusterManager
    • 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 interface RoutersClusterManager
    • isThrottlingEnabled

      public boolean isThrottlingEnabled()
      Specified by:
      isThrottlingEnabled in interface RoutersClusterManager
    • isMaxCapacityProtectionEnabled

      public boolean isMaxCapacityProtectionEnabled()
      Specified by:
      isMaxCapacityProtectionEnabled in interface RoutersClusterManager
    • 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 interface RoutersClusterManager
    • 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 interface RoutersClusterManager
    • createRouterClusterConfig

      public void createRouterClusterConfig()
      Specified by:
      createRouterClusterConfig in interface RoutersClusterManager
    • getRoutersClusterConfig

      public RoutersClusterConfig getRoutersClusterConfig()
    • changeLiveRouterCount

      protected void changeLiveRouterCount(int newRouterCount)
    • triggerRouterCountChangedEvent

      protected void triggerRouterCountChangedEvent(int newRouterCount)
    • handleChildChange

      public void handleChildChange(String parentPath, List<String> currentChildren) throws 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 interface org.apache.helix.zookeeper.zkclient.IZkChildListener
      Throws:
      Exception
    • handleDataChange

      public void handleDataChange(String dataPath, Object data) throws 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 interface org.apache.helix.zookeeper.zkclient.IZkDataListener
      Throws:
      Exception
    • handleDataDeleted

      public void handleDataDeleted(String dataPath) throws Exception
      Specified by:
      handleDataDeleted in interface org.apache.helix.zookeeper.zkclient.IZkDataListener
      Throws:
      Exception
    • getRouterRootPath

      protected final String getRouterRootPath()
    • handleStateChanged

      public void handleStateChanged(org.apache.zookeeper.Watcher.Event.KeeperState keeperState)
      Specified by:
      handleStateChanged in interface org.apache.helix.zookeeper.zkclient.IZkStateListener
    • handleNewSession

      public void handleNewSession(String s) throws Exception
      Specified by:
      handleNewSession in interface org.apache.helix.zookeeper.zkclient.IZkStateListener
      Throws:
      Exception
    • handleSessionEstablishmentError

      public void handleSessionEstablishmentError(Throwable throwable) throws Exception
      Specified by:
      handleSessionEstablishmentError in interface org.apache.helix.zookeeper.zkclient.IZkStateListener
      Throws:
      Exception