提交 07d2daf4 编写于 作者: M Matteo Merli 提交者: GitHub

Shutdown load manager executor on pulsar service close (#489)

上级 02198296
...@@ -94,7 +94,7 @@ public class PulsarService implements AutoCloseable { ...@@ -94,7 +94,7 @@ public class PulsarService implements AutoCloseable {
private final ScheduledExecutorService cacheExecutor = Executors.newScheduledThreadPool(10, private final ScheduledExecutorService cacheExecutor = Executors.newScheduledThreadPool(10,
new DefaultThreadFactory("zk-cache-callback")); new DefaultThreadFactory("zk-cache-callback"));
private final OrderedSafeExecutor orderedExecutor = new OrderedSafeExecutor(8, "pulsar-ordered"); private final OrderedSafeExecutor orderedExecutor = new OrderedSafeExecutor(8, "pulsar-ordered");
private ScheduledExecutorService loadManagerExecutor = null; private final ScheduledExecutorService loadManagerExecutor;
private ScheduledFuture<?> loadReportTask = null; private ScheduledFuture<?> loadReportTask = null;
private ScheduledFuture<?> loadSheddingTask = null; private ScheduledFuture<?> loadSheddingTask = null;
private ScheduledFuture<?> loadResourceQuotaTask = null; private ScheduledFuture<?> loadResourceQuotaTask = null;
...@@ -133,7 +133,8 @@ public class PulsarService implements AutoCloseable { ...@@ -133,7 +133,8 @@ public class PulsarService implements AutoCloseable {
this.brokerVersion = PulsarBrokerVersionStringUtils.getNormalizedVersionString(); this.brokerVersion = PulsarBrokerVersionStringUtils.getNormalizedVersionString();
this.config = config; this.config = config;
this.shutdownService = new MessagingServiceShutdownHook(this); this.shutdownService = new MessagingServiceShutdownHook(this);
loadManagerExecutor = Executors.newSingleThreadScheduledExecutor(); this.loadManagerExecutor = Executors
.newSingleThreadScheduledExecutor(new DefaultThreadFactory("pulsar-load-manager"));
} }
/** /**
...@@ -174,10 +175,7 @@ public class PulsarService implements AutoCloseable { ...@@ -174,10 +175,7 @@ public class PulsarService implements AutoCloseable {
this.leaderElectionService = null; this.leaderElectionService = null;
} }
if (loadManagerExecutor != null) { loadManagerExecutor.shutdown();
loadManagerExecutor.shutdownNow();
}
loadManager = null;
if (globalZkCache != null) { if (globalZkCache != null) {
globalZkCache.close(); globalZkCache.close();
...@@ -205,6 +203,12 @@ public class PulsarService implements AutoCloseable { ...@@ -205,6 +203,12 @@ public class PulsarService implements AutoCloseable {
orderedExecutor.shutdown(); orderedExecutor.shutdown();
cacheExecutor.shutdown(); cacheExecutor.shutdown();
LoadManager loadManager = this.loadManager.get();
if (loadManager != null) {
loadManager.stop();
}
state = State.Closed; state = State.Closed;
} catch (Exception e) { } catch (Exception e) {
......
...@@ -60,6 +60,8 @@ import com.yahoo.pulsar.zookeeper.ZooKeeperCacheListener; ...@@ -60,6 +60,8 @@ import com.yahoo.pulsar.zookeeper.ZooKeeperCacheListener;
import com.yahoo.pulsar.zookeeper.ZooKeeperChildrenCache; import com.yahoo.pulsar.zookeeper.ZooKeeperChildrenCache;
import com.yahoo.pulsar.zookeeper.ZooKeeperDataCache; import com.yahoo.pulsar.zookeeper.ZooKeeperDataCache;
import io.netty.util.concurrent.DefaultThreadFactory;
public class ModularLoadManagerImpl implements ModularLoadManager, ZooKeeperCacheListener<LocalBrokerData> { public class ModularLoadManagerImpl implements ModularLoadManager, ZooKeeperCacheListener<LocalBrokerData> {
private static final Logger log = LoggerFactory.getLogger(ModularLoadManagerImpl.class); private static final Logger log = LoggerFactory.getLogger(ModularLoadManagerImpl.class);
...@@ -163,13 +165,13 @@ public class ModularLoadManagerImpl implements ModularLoadManager, ZooKeeperCach ...@@ -163,13 +165,13 @@ public class ModularLoadManagerImpl implements ModularLoadManager, ZooKeeperCach
loadSheddingPipeline = new ArrayList<>(); loadSheddingPipeline = new ArrayList<>();
loadSheddingPipeline.add(new OverloadShedder(conf)); loadSheddingPipeline.add(new OverloadShedder(conf));
preallocatedBundleToBroker = new ConcurrentHashMap<>(); preallocatedBundleToBroker = new ConcurrentHashMap<>();
scheduler = Executors.newScheduledThreadPool(1); scheduler = Executors.newSingleThreadScheduledExecutor(new DefaultThreadFactory("pulsar-modular-load-manager"));
} }
/** /**
* Initialize this load manager using the given PulsarService. Should be called only once, after invoking the * Initialize this load manager using the given PulsarService. Should be called only once, after invoking the
* default constructor. * default constructor.
* *
* @param pulsar * @param pulsar
* The service to initialize with. * The service to initialize with.
*/ */
...@@ -224,7 +226,7 @@ public class ModularLoadManagerImpl implements ModularLoadManager, ZooKeeperCach ...@@ -224,7 +226,7 @@ public class ModularLoadManagerImpl implements ModularLoadManager, ZooKeeperCach
/** /**
* Initialize this load manager. * Initialize this load manager.
* *
* @param pulsar * @param pulsar
* Client to construct this manager from. * Client to construct this manager from.
*/ */
...@@ -475,7 +477,7 @@ public class ModularLoadManagerImpl implements ModularLoadManager, ZooKeeperCach ...@@ -475,7 +477,7 @@ public class ModularLoadManagerImpl implements ModularLoadManager, ZooKeeperCach
/** /**
* As any broker, disable the broker this manager is running on. * As any broker, disable the broker this manager is running on.
* *
* @throws PulsarServerException * @throws PulsarServerException
* If ZooKeeper failed to disable the broker. * If ZooKeeper failed to disable the broker.
*/ */
...@@ -548,7 +550,7 @@ public class ModularLoadManagerImpl implements ModularLoadManager, ZooKeeperCach ...@@ -548,7 +550,7 @@ public class ModularLoadManagerImpl implements ModularLoadManager, ZooKeeperCach
/** /**
* As the leader broker, find a suitable broker for the assignment of the given bundle. * As the leader broker, find a suitable broker for the assignment of the given bundle.
* *
* @param serviceUnit * @param serviceUnit
* ServiceUnitId for the bundle. * ServiceUnitId for the bundle.
* @return The name of the selected broker, as it appears on ZooKeeper. * @return The name of the selected broker, as it appears on ZooKeeper.
...@@ -610,7 +612,7 @@ public class ModularLoadManagerImpl implements ModularLoadManager, ZooKeeperCach ...@@ -610,7 +612,7 @@ public class ModularLoadManagerImpl implements ModularLoadManager, ZooKeeperCach
/** /**
* As any broker, start the load manager. * As any broker, start the load manager.
* *
* @throws PulsarServerException * @throws PulsarServerException
* If an unexpected error prevented the load manager from being started. * If an unexpected error prevented the load manager from being started.
*/ */
...@@ -647,7 +649,7 @@ public class ModularLoadManagerImpl implements ModularLoadManager, ZooKeeperCach ...@@ -647,7 +649,7 @@ public class ModularLoadManagerImpl implements ModularLoadManager, ZooKeeperCach
/** /**
* As any broker, stop the load manager. * As any broker, stop the load manager.
* *
* @throws PulsarServerException * @throws PulsarServerException
* If an unexpected error occurred when attempting to stop the load manager. * If an unexpected error occurred when attempting to stop the load manager.
*/ */
......
...@@ -74,6 +74,8 @@ import com.yahoo.pulsar.zookeeper.ZooKeeperCacheListener; ...@@ -74,6 +74,8 @@ import com.yahoo.pulsar.zookeeper.ZooKeeperCacheListener;
import com.yahoo.pulsar.zookeeper.ZooKeeperChildrenCache; import com.yahoo.pulsar.zookeeper.ZooKeeperChildrenCache;
import com.yahoo.pulsar.zookeeper.ZooKeeperDataCache; import com.yahoo.pulsar.zookeeper.ZooKeeperDataCache;
import io.netty.util.concurrent.DefaultThreadFactory;
public class SimpleLoadManagerImpl implements LoadManager, ZooKeeperCacheListener<LoadReport> { public class SimpleLoadManagerImpl implements LoadManager, ZooKeeperCacheListener<LoadReport> {
private static final Logger log = LoggerFactory.getLogger(SimpleLoadManagerImpl.class); private static final Logger log = LoggerFactory.getLogger(SimpleLoadManagerImpl.class);
...@@ -179,7 +181,7 @@ public class SimpleLoadManagerImpl implements LoadManager, ZooKeeperCacheListene ...@@ -179,7 +181,7 @@ public class SimpleLoadManagerImpl implements LoadManager, ZooKeeperCacheListene
// Perform initializations which may be done without a PulsarService. // Perform initializations which may be done without a PulsarService.
public SimpleLoadManagerImpl() { public SimpleLoadManagerImpl() {
scheduler = Executors.newScheduledThreadPool(1); scheduler = Executors.newSingleThreadScheduledExecutor(new DefaultThreadFactory("pulsar-simple-load-manager"));
this.sortedRankings.set(new TreeMap<>()); this.sortedRankings.set(new TreeMap<>());
this.currentLoadReports = new HashMap<>(); this.currentLoadReports = new HashMap<>();
this.resourceUnitRankings = new HashMap<>(); this.resourceUnitRankings = new HashMap<>();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册