From 96f14d287971cdbbba5e5b4e60508177da603d54 Mon Sep 17 00:00:00 2001 From: Keven Li Date: Wed, 30 Oct 2019 14:30:10 +0800 Subject: [PATCH] fix misspelling and adjust code style (#5497) Signed-off-by: KevenYLi --- .../pulsar/broker/loadbalance/LoadManager.java | 2 +- .../loadbalance/impl/LoadManagerShared.java | 16 +++++++--------- .../loadbalance/impl/ModularLoadManagerImpl.java | 13 +++++-------- .../broker/loadbalance/impl/OverloadShedder.java | 1 + 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/LoadManager.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/LoadManager.java index 283c8f0df897c..13592fd4baa61 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/LoadManager.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/LoadManager.java @@ -47,7 +47,7 @@ public interface LoadManager { String LOADBALANCE_BROKERS_ROOT = "/loadbalance/brokers"; - public void start() throws PulsarServerException; + void start() throws PulsarServerException; /** * Is centralized decision making to assign a new bundle. diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/LoadManagerShared.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/LoadManagerShared.java index d9cab2399a50f..df5439e778d9b 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/LoadManagerShared.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/LoadManagerShared.java @@ -121,11 +121,9 @@ public static void applyNamespacePolicies(final ServiceUnitId serviceUnit, log.error("Unable to parse brokerUrl from ResourceUnitId - [{}]", e); continue; } - // todo: in future check if the resource unit has resources to take - // the namespace + // todo: in future check if the resource unit has resources to take the namespace if (isIsolationPoliciesPresent) { - // note: serviceUnitID is namespace name and ResourceID is - // brokerName + // note: serviceUnitID is namespace name and ResourceID is brokerName if (policies.isPrimaryBroker(namespace, brokerUrl.getHost())) { primariesCache.add(broker); if (log.isDebugEnabled()) { @@ -475,14 +473,14 @@ public static CompletableFuture> getAntiAffinityNamespaceOw * @param currentBroker * @param pulsar * @param brokerToNamespaceToBundleRange - * @param candidateBroekrs + * @param candidateBrokers * @return * @throws Exception */ public static boolean shouldAntiAffinityNamespaceUnload(String namespace, String bundle, String currentBroker, final PulsarService pulsar, final ConcurrentOpenHashMap>> brokerToNamespaceToBundleRange, - Set candidateBroekrs) throws Exception { + Set candidateBrokers) throws Exception { Map brokerNamespaceCount = getAntiAffinityNamespaceOwnedBrokers(pulsar, namespace, brokerToNamespaceToBundleRange).get(10, TimeUnit.SECONDS); @@ -490,7 +488,7 @@ public static boolean shouldAntiAffinityNamespaceUnload(String namespace, String int leastNsCount = Integer.MAX_VALUE; int currentBrokerNsCount = 0; - for (String broker : candidateBroekrs) { + for (String broker : candidateBrokers) { int nsCount = brokerNamespaceCount.getOrDefault(broker, 0); if (currentBroker.equals(broker)) { currentBrokerNsCount = nsCount; @@ -505,13 +503,13 @@ public static boolean shouldAntiAffinityNamespaceUnload(String namespace, String } // check if all the brokers having same number of ns-count then broker can't unload int leastNsOwnerBrokers = 0; - for (String broker : candidateBroekrs) { + for (String broker : candidateBrokers) { if (leastNsCount == brokerNamespaceCount.getOrDefault(broker, 0)) { leastNsOwnerBrokers++; } } // if all candidate brokers own same-number of ns then broker can't unload - return candidateBroekrs.size() != leastNsOwnerBrokers; + return candidateBrokers.size() != leastNsOwnerBrokers; } return true; } diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java index ab687d437ab36..89e965e5da47b 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java @@ -222,9 +222,9 @@ public boolean isEnableNonPersistentTopics(String brokerUrl) { * Initialize this load manager using the given PulsarService. Should be called only once, after invoking the * default constructor. * - * @param pulsar - * The service to initialize with. + * @param pulsar The service to initialize with. */ + @Override public void initialize(final PulsarService pulsar) { this.pulsar = pulsar; availableActiveBrokers = new ZooKeeperChildrenCache(pulsar.getLocalZkCache(), @@ -491,13 +491,11 @@ private void updateBundleData() { final String bundle = entry.getKey(); final NamespaceBundleStats stats = entry.getValue(); if (bundleData.containsKey(bundle)) { - // If we recognize the bundle, add these stats as a new - // sample. + // If we recognize the bundle, add these stats as a new sample. bundleData.get(bundle).update(stats); } else { // Otherwise, attempt to find the bundle data on ZooKeeper. - // If it cannot be found, use the latest stats as the first - // sample. + // If it cannot be found, use the latest stats as the first sample. BundleData currentBundleData = getBundleDataOrDefault(bundle); currentBundleData.update(stats); bundleData.put(bundle, currentBundleData); @@ -572,8 +570,7 @@ public synchronized void doLoadShedding() { log.info("Only 1 broker available: no load shedding will be performed"); return; } - // Remove bundles who have been unloaded for longer than the grace period from the recently unloaded - // map. + // Remove bundles who have been unloaded for longer than the grace period from the recently unloaded map. final long timeout = System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(conf.getLoadBalancerSheddingGracePeriodMinutes()); final Map recentlyUnloadedBundles = loadData.getRecentlyUnloadedBundles(); diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/OverloadShedder.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/OverloadShedder.java index d587cce598581..c61f8cb564f72 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/OverloadShedder.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/OverloadShedder.java @@ -60,6 +60,7 @@ public class OverloadShedder implements LoadSheddingStrategy { * The service configuration. * @return A map from bundles to unload to the brokers on which they are loaded. */ + @Override public Multimap findBundlesForUnloading(final LoadData loadData, final ServiceConfiguration conf) { selectedBundlesCache.clear(); final double overloadThreshold = conf.getLoadBalancerBrokerOverloadedThresholdPercentage() / 100.0;