mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Keep at least one DataSource in the pool when update by events.
This commit is contained in:
@@ -97,6 +97,7 @@ public class HighAvailableDataSource extends WrapperAdapter implements DataSourc
|
||||
private String dataSourceFile = DEFAULT_DATA_SOURCE_FILE;
|
||||
private String propertyPrefix = "";
|
||||
private int poolPurgeIntervalSeconds = PoolUpdater.DEFAULT_INTERVAL;
|
||||
private boolean allowEmptyPoolWhenUpdate = false;
|
||||
|
||||
private volatile boolean inited = false;
|
||||
|
||||
@@ -113,6 +114,7 @@ public class HighAvailableDataSource extends WrapperAdapter implements DataSourc
|
||||
}
|
||||
if (dataSourceMap == null || dataSourceMap.isEmpty()) {
|
||||
poolUpdater.setIntervalSeconds(poolPurgeIntervalSeconds);
|
||||
poolUpdater.setAllowEmptyPool(allowEmptyPoolWhenUpdate);
|
||||
poolUpdater.init();
|
||||
createNodeMap();
|
||||
}
|
||||
@@ -304,6 +306,14 @@ public class HighAvailableDataSource extends WrapperAdapter implements DataSourc
|
||||
nodeListener.update(); // Do update in the current Thread at the startup
|
||||
}
|
||||
|
||||
public boolean isAllowEmptyPoolWhenUpdate() {
|
||||
return allowEmptyPoolWhenUpdate;
|
||||
}
|
||||
|
||||
public void setAllowEmptyPoolWhenUpdate(boolean allowEmptyPoolWhenUpdate) {
|
||||
this.allowEmptyPoolWhenUpdate = allowEmptyPoolWhenUpdate;
|
||||
}
|
||||
|
||||
// Getters & Setters
|
||||
|
||||
public int getPoolPurgeIntervalSeconds() {
|
||||
|
||||
@@ -50,6 +50,7 @@ public class PoolUpdater implements Observer {
|
||||
private ScheduledExecutorService executor;
|
||||
private int intervalSeconds = DEFAULT_INTERVAL;
|
||||
private volatile boolean inited = false;
|
||||
private boolean allowEmptyPool = false;
|
||||
|
||||
public PoolUpdater(HighAvailableDataSource highAvailableDataSource) {
|
||||
setHighAvailableDataSource(highAvailableDataSource);
|
||||
@@ -213,6 +214,11 @@ public class PoolUpdater implements Observer {
|
||||
if (nodeName == null || nodeName.isEmpty() || !map.containsKey(nodeName)) {
|
||||
return;
|
||||
}
|
||||
map = highAvailableDataSource.getAvailableDataSourceMap();
|
||||
if (!allowEmptyPool && map.size() == 1 && map.containsKey(nodeName)) {
|
||||
LOG.warn(nodeName + " is the only DataSource left, don't remove it.");
|
||||
return;
|
||||
}
|
||||
blacklistNode(nodeName);
|
||||
}
|
||||
|
||||
@@ -247,4 +253,12 @@ public class PoolUpdater implements Observer {
|
||||
public void setIntervalSeconds(int intervalSeconds) {
|
||||
this.intervalSeconds = intervalSeconds;
|
||||
}
|
||||
|
||||
public boolean isAllowEmptyPool() {
|
||||
return allowEmptyPool;
|
||||
}
|
||||
|
||||
public void setAllowEmptyPool(boolean allowEmptyPool) {
|
||||
this.allowEmptyPool = allowEmptyPool;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user