Class 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.
    • 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

      • 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 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
      • 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
      • 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 interface org.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 interface org.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 interface org.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 interface org.apache.helix.zookeeper.zkclient.IZkStateListener
      • handleNewSession

        public void handleNewSession​(java.lang.String s)
                              throws java.lang.Exception
        Specified by:
        handleNewSession in interface org.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 interface org.apache.helix.zookeeper.zkclient.IZkStateListener
        Throws:
        java.lang.Exception