Class ModularLoadManagerImpl

java.lang.Object
org.apache.pulsar.broker.loadbalance.impl.ModularLoadManagerImpl
All Implemented Interfaces:
ModularLoadManager

public class ModularLoadManagerImpl extends Object implements ModularLoadManager
  • Field Details

  • Constructor Details

    • ModularLoadManagerImpl

      public ModularLoadManagerImpl()
      Initializes fields which do not depend on PulsarService. initialize(PulsarService) should subsequently be called.
    • ModularLoadManagerImpl

      public ModularLoadManagerImpl(PulsarService pulsar)
      Initialize this load manager.
      Parameters:
      pulsar - Client to construct this manager from.
  • Method Details

    • initialize

      public void initialize(PulsarService pulsar)
      Initialize this load manager using the given PulsarService. Should be called only once, after invoking the default constructor.
      Specified by:
      initialize in interface ModularLoadManager
      Parameters:
      pulsar - The service to initialize with.
    • handleDataNotification

      public void handleDataNotification(org.apache.pulsar.metadata.api.Notification t)
    • getAvailableBrokers

      public Set<String> getAvailableBrokers()
      Description copied from interface: ModularLoadManager
      Get available broker list in cluster.
      Specified by:
      getAvailableBrokers in interface ModularLoadManager
      Returns:
    • getAvailableBrokersAsync

      public CompletableFuture<Set<String>> getAvailableBrokersAsync()
      Description copied from interface: ModularLoadManager
      Get available broker list in cluster by async invoke.
      Specified by:
      getAvailableBrokersAsync in interface ModularLoadManager
    • getBundleDataOrDefault

      public org.apache.pulsar.policies.data.loadbalancer.BundleData getBundleDataOrDefault(String bundle)
      Description copied from interface: ModularLoadManager
      Fetch bundle's load report data.
      Specified by:
      getBundleDataOrDefault in interface ModularLoadManager
      Returns:
      bundle data
    • getBundleDataPath

      public static String getBundleDataPath(String bundle)
    • updateAll

      public void updateAll()
    • disableBroker

      public void disableBroker() throws org.apache.pulsar.broker.PulsarServerException
      As any broker, disable the broker this manager is running on.
      Specified by:
      disableBroker in interface ModularLoadManager
      Throws:
      org.apache.pulsar.broker.PulsarServerException - If there's a failure when disabling broker on metadata store.
    • doLoadShedding

      public void doLoadShedding()
      As the leader broker, select bundles for the namespace service to unload so that they may be reassigned to new brokers.
      Specified by:
      doLoadShedding in interface ModularLoadManager
    • shouldNamespacePoliciesUnload

      public boolean shouldNamespacePoliciesUnload(String namespace, String bundle, String currentBroker)
    • shouldAntiAffinityNamespaceUnload

      public boolean shouldAntiAffinityNamespaceUnload(String namespace, String bundle, String currentBroker)
    • checkNamespaceBundleSplit

      public void checkNamespaceBundleSplit()
      As the leader broker, attempt to automatically detect and split hot namespace bundles.
      Specified by:
      checkNamespaceBundleSplit in interface ModularLoadManager
    • selectBrokerForAssignment

      public Optional<String> selectBrokerForAssignment(org.apache.pulsar.common.naming.ServiceUnitId serviceUnit)
      As the leader broker, find a suitable broker for the assignment of the given bundle.
      Specified by:
      selectBrokerForAssignment in interface ModularLoadManager
      Parameters:
      serviceUnit - ServiceUnitId for the bundle.
      Returns:
      The name of the selected broker, as it appears on metadata store.
    • start

      public void start() throws org.apache.pulsar.broker.PulsarServerException
      As any broker, start the load manager.
      Specified by:
      start in interface ModularLoadManager
      Throws:
      org.apache.pulsar.broker.PulsarServerException - If an unexpected error prevented the load manager from being started.
    • stop

      public void stop() throws org.apache.pulsar.broker.PulsarServerException
      As any broker, stop the load manager.
      Specified by:
      stop in interface ModularLoadManager
      Throws:
      org.apache.pulsar.broker.PulsarServerException - If an unexpected error occurred when attempting to stop the load manager.
    • updateLocalBrokerData

      public org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData updateLocalBrokerData()
      As any broker, retrieve the namespace bundle stats and system resource usage to update data local to this broker.
      Specified by:
      updateLocalBrokerData in interface ModularLoadManager
      Returns:
    • writeBrokerDataOnZooKeeper

      public void writeBrokerDataOnZooKeeper()
      As any broker, write the local broker data to metadata store.
      Specified by:
      writeBrokerDataOnZooKeeper in interface ModularLoadManager
    • writeBrokerDataOnZooKeeper

      public void writeBrokerDataOnZooKeeper(boolean force)
      Description copied from interface: ModularLoadManager
      As any broker, write the local broker data to ZooKeeper, forced or not.
      Specified by:
      writeBrokerDataOnZooKeeper in interface ModularLoadManager
    • writeBundleDataOnZooKeeper

      public void writeBundleDataOnZooKeeper()
      As the leader broker, write bundle data aggregated from all brokers to metadata store.
      Specified by:
      writeBundleDataOnZooKeeper in interface ModularLoadManager
    • getBrokerLocalData

      public org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData getBrokerLocalData(String broker)
      Description copied from interface: ModularLoadManager
      Fetch local-broker data from load-manager broker cache.
      Specified by:
      getBrokerLocalData in interface ModularLoadManager
      Parameters:
      broker - load-balancer path
      Returns:
    • getLoadBalancingMetrics

      public List<org.apache.pulsar.common.stats.Metrics> getLoadBalancingMetrics()
      Description copied from interface: ModularLoadManager
      Fetch load balancing metrics.
      Specified by:
      getLoadBalancingMetrics in interface ModularLoadManager
      Returns:
      List of LoadBalancing Metrics