Class ModularLoadManagerImpl
- java.lang.Object
-
- org.apache.pulsar.broker.loadbalance.impl.ModularLoadManagerImpl
-
- All Implemented Interfaces:
ModularLoadManager
public class ModularLoadManagerImpl extends java.lang.Object implements ModularLoadManager
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringBUNDLE_DATA_PATHstatic doubleDEFAULT_MESSAGE_RATEstatic doubleDEFAULT_MESSAGE_THROUGHPUTstatic intNUM_LONG_SAMPLESstatic intNUM_SHORT_SAMPLESstatic java.lang.StringRESOURCE_QUOTA_ZPATHstatic java.lang.StringTIME_AVERAGE_BROKER_ZPATH
-
Constructor Summary
Constructors Constructor Description ModularLoadManagerImpl()Initializes fields which do not depend on PulsarService.ModularLoadManagerImpl(PulsarService pulsar)Initialize this load manager.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckNamespaceBundleSplit()As the leader broker, attempt to automatically detect and split hot namespace bundles.voiddisableBroker()As any broker, disable the broker this manager is running on.voiddoLoadShedding()As the leader broker, select bundles for the namespace service to unload so that they may be reassigned to new brokers.java.util.Set<java.lang.String>getAvailableBrokers()Get available broker list in cluster.org.apache.pulsar.policies.data.loadbalancer.LocalBrokerDatagetBrokerLocalData(java.lang.String broker)Fetch local-broker data from load-manager broker cache.java.util.List<org.apache.pulsar.common.stats.Metrics>getLoadBalancingMetrics()Fetch load balancing metrics.voidhandleDataNotification(org.apache.pulsar.metadata.api.Notification t)voidinitialize(PulsarService pulsar)Initialize this load manager using the given PulsarService.java.util.Optional<java.lang.String>selectBrokerForAssignment(org.apache.pulsar.common.naming.ServiceUnitId serviceUnit)As the leader broker, find a suitable broker for the assignment of the given bundle.booleanshouldAntiAffinityNamespaceUnload(java.lang.String namespace, java.lang.String bundle, java.lang.String currentBroker)voidstart()As any broker, start the load manager.voidstop()As any broker, stop the load manager.voidupdateAll()org.apache.pulsar.policies.data.loadbalancer.LocalBrokerDataupdateLocalBrokerData()As any broker, retrieve the namespace bundle stats and system resource usage to update data local to this broker.voidwriteBrokerDataOnZooKeeper()As any broker, write the local broker data to metadata store.voidwriteBrokerDataOnZooKeeper(boolean force)As any broker, write the local broker data to ZooKeeper, forced or not.voidwriteBundleDataOnZooKeeper()As the leader broker, write bundle data aggregated from all brokers to metadata store.
-
-
-
Field Detail
-
BUNDLE_DATA_PATH
public static final java.lang.String BUNDLE_DATA_PATH
- See Also:
- Constant Field Values
-
DEFAULT_MESSAGE_RATE
public static final double DEFAULT_MESSAGE_RATE
- See Also:
- Constant Field Values
-
DEFAULT_MESSAGE_THROUGHPUT
public static final double DEFAULT_MESSAGE_THROUGHPUT
- See Also:
- Constant Field Values
-
NUM_LONG_SAMPLES
public static final int NUM_LONG_SAMPLES
- See Also:
- Constant Field Values
-
NUM_SHORT_SAMPLES
public static final int NUM_SHORT_SAMPLES
- See Also:
- Constant Field Values
-
RESOURCE_QUOTA_ZPATH
public static final java.lang.String RESOURCE_QUOTA_ZPATH
- See Also:
- Constant Field Values
-
TIME_AVERAGE_BROKER_ZPATH
public static final java.lang.String TIME_AVERAGE_BROKER_ZPATH
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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 Detail
-
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:
initializein interfaceModularLoadManager- Parameters:
pulsar- The service to initialize with.
-
handleDataNotification
public void handleDataNotification(org.apache.pulsar.metadata.api.Notification t)
-
getAvailableBrokers
public java.util.Set<java.lang.String> getAvailableBrokers()
Description copied from interface:ModularLoadManagerGet available broker list in cluster.- Specified by:
getAvailableBrokersin interfaceModularLoadManager- Returns:
-
updateAll
public void updateAll()
-
disableBroker
public void disableBroker() throws org.apache.pulsar.broker.PulsarServerExceptionAs any broker, disable the broker this manager is running on.- Specified by:
disableBrokerin interfaceModularLoadManager- 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:
doLoadSheddingin interfaceModularLoadManager
-
shouldAntiAffinityNamespaceUnload
public boolean shouldAntiAffinityNamespaceUnload(java.lang.String namespace, java.lang.String bundle, java.lang.String currentBroker)
-
checkNamespaceBundleSplit
public void checkNamespaceBundleSplit()
As the leader broker, attempt to automatically detect and split hot namespace bundles.- Specified by:
checkNamespaceBundleSplitin interfaceModularLoadManager
-
selectBrokerForAssignment
public java.util.Optional<java.lang.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:
selectBrokerForAssignmentin interfaceModularLoadManager- 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.PulsarServerExceptionAs any broker, start the load manager.- Specified by:
startin interfaceModularLoadManager- 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.PulsarServerExceptionAs any broker, stop the load manager.- Specified by:
stopin interfaceModularLoadManager- 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:
updateLocalBrokerDatain interfaceModularLoadManager- Returns:
-
writeBrokerDataOnZooKeeper
public void writeBrokerDataOnZooKeeper()
As any broker, write the local broker data to metadata store.- Specified by:
writeBrokerDataOnZooKeeperin interfaceModularLoadManager
-
writeBrokerDataOnZooKeeper
public void writeBrokerDataOnZooKeeper(boolean force)
Description copied from interface:ModularLoadManagerAs any broker, write the local broker data to ZooKeeper, forced or not.- Specified by:
writeBrokerDataOnZooKeeperin interfaceModularLoadManager
-
writeBundleDataOnZooKeeper
public void writeBundleDataOnZooKeeper()
As the leader broker, write bundle data aggregated from all brokers to metadata store.- Specified by:
writeBundleDataOnZooKeeperin interfaceModularLoadManager
-
getBrokerLocalData
public org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData getBrokerLocalData(java.lang.String broker)
Description copied from interface:ModularLoadManagerFetch local-broker data from load-manager broker cache.- Specified by:
getBrokerLocalDatain interfaceModularLoadManager- Parameters:
broker- load-balancer path- Returns:
-
getLoadBalancingMetrics
public java.util.List<org.apache.pulsar.common.stats.Metrics> getLoadBalancingMetrics()
Description copied from interface:ModularLoadManagerFetch load balancing metrics.- Specified by:
getLoadBalancingMetricsin interfaceModularLoadManager- Returns:
- List of LoadBalancing Metrics
-
-