Skip to content

Commit d7a6763

Browse files
committed
reload NPE
1 parent f30e6e1 commit d7a6763

File tree

4 files changed

+48
-27
lines changed

4 files changed

+48
-27
lines changed

src/main/java/com/actiontech/dble/backend/datasource/PhysicalDBPool.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,10 @@ private String getMessage(int index, String info) {
347347
}
348348

349349
private boolean initSource(int index, PhysicalDatasource ds) {
350+
if (ds.getConfig().isFake()) {
351+
LOGGER.info(ds.getConfig().getHostName() + " has not real url, skipped");
352+
return true;
353+
}
350354
int initSize = ds.getConfig().getMinCon();
351355
if (initSize == 0) {
352356
return true;

src/main/java/com/actiontech/dble/config/ConfigInitializer.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,9 @@ private void selfChecking0() throws ConfigException {
155155

156156
private void checkWriteHost() {
157157
for (Map.Entry<String, PhysicalDBPool> pool : this.dataHosts.entrySet()) {
158-
this.dataHostWithoutWH = false;
159-
if (pool.getValue().getSources() == null || pool.getValue().getSources().length == 0) {
160-
LOGGER.info("dataHost " + pool.getKey() + " has no writeHost ,server will ignore it");
161-
this.dataHostWithoutWH = true;
158+
PhysicalDatasource[] writeSource = pool.getValue().getSources();
159+
if (writeSource != null && writeSource.length != 0 && !writeSource[0].getConfig().isFake()) {
160+
this.dataHostWithoutWH = false;
162161
break;
163162
}
164163
}

src/main/java/com/actiontech/dble/config/loader/xml/XMLSchemaLoader.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ private void loadDataHosts(Element root) {
562562
final String heartbeatSQL = element.getElementsByTagName("heartbeat").item(0).getTextContent();
563563

564564
NodeList writeNodes = element.getElementsByTagName("writeHost");
565+
NodeList readOnlyNodes = element.getElementsByTagName("readHost");
565566
if (writeNodes.getLength() > 0) {
566567
DBHostConfig[] writeDbConfs = new DBHostConfig[writeNodes.getLength()];
567568
Map<Integer, DBHostConfig[]> readHostsMap = new HashMap<>(2);
@@ -587,25 +588,39 @@ private void loadDataHosts(Element root) {
587588
hostConf.setBalance(balance);
588589
hostConf.setHearbeatSQL(heartbeatSQL);
589590
dataHosts.put(hostConf.getName(), hostConf);
590-
} else { //read host only
591-
NodeList readNodes = element.getElementsByTagName("readHost");
591+
} else if (readOnlyNodes.getLength() > 0) { //read host only
592+
if (readOnlyNodes.getLength() > 1) {
593+
LOGGER.info("only the first Read_Node will be load, others will be ignore");
594+
}
592595
DBHostConfig[] writeDbConfs = new DBHostConfig[1];
593596
writeDbConfs[0] = new DBHostConfig("fakeHost", "-", 0, "-:0)", "-", "-");
594597
writeDbConfs[0].setFake(true);
595598
DBHostConfig[] readDbConfs = new DBHostConfig[1];
596-
Element readNode = (Element) readNodes.item(0);
599+
Element readNode = (Element) readOnlyNodes.item(0);
597600
readDbConfs[0] = createDBHostConf(name, readNode, maxCon, minCon);
598601
Map<Integer, DBHostConfig[]> readHostsMap = new HashMap<>(1);
599602
readHostsMap.put(0, readDbConfs);
600-
601603
DataHostConfig hostConf = new DataHostConfig(name,
602604
writeDbConfs, readHostsMap, -1, slaveThreshold, true); // switchType =-1 and tempReadHostAvailable =true
603-
604605
hostConf.setMaxCon(maxCon);
605606
hostConf.setMinCon(minCon);
606607
hostConf.setBalance(3); // all read host
607608
hostConf.setHearbeatSQL("select 1"); //for heartbeat
608609
dataHosts.put(hostConf.getName(), hostConf);
610+
} else {
611+
DBHostConfig[] writeDbConfs = new DBHostConfig[1];
612+
writeDbConfs[0] = new DBHostConfig("fakeHost", "-", 0, "-:0)", "-", "-");
613+
writeDbConfs[0].setFake(true);
614+
Map<Integer, DBHostConfig[]> readHostsMap = new HashMap<>(0);
615+
DataHostConfig hostConf = new DataHostConfig(name,
616+
writeDbConfs, readHostsMap, switchType, slaveThreshold, tempReadHostAvailable);
617+
618+
hostConf.setMaxCon(maxCon);
619+
hostConf.setMinCon(minCon);
620+
hostConf.setBalance(balance);
621+
hostConf.setHearbeatSQL(heartbeatSQL);
622+
dataHosts.put(hostConf.getName(), hostConf);
623+
dataHosts.put(hostConf.getName(), hostConf);
609624
}
610625
}
611626
}

src/main/java/com/actiontech/dble/manager/response/ReloadConfig.java

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -264,32 +264,35 @@ public static void reloadAll(final int loadAllMode) throws Exception {
264264
*/
265265
ConfigInitializer loader;
266266
try {
267-
loader = new ConfigInitializer(true, DbleServer.getInstance().getSystemVariables().isLowerCaseTableNames());
267+
loader = new ConfigInitializer(true, false);
268268
} catch (Exception e) {
269269
throw new Exception(e);
270270
}
271-
Map<String, UserConfig> newUsers = loader.getUsers();
272-
Map<String, SchemaConfig> newSchemas = loader.getSchemas();
273-
Map<String, PhysicalDBNode> newDataNodes = loader.getDataNodes();
274-
Map<String, PhysicalDBPool> newDataHosts = loader.getDataHosts();
275-
Map<ERTable, Set<ERTable>> newErRelations = loader.getErRelations();
276-
FirewallConfig newFirewall = loader.getFirewall();
277271

278272
SystemVariables newSystemVariables = null;
279-
if (!loader.isDataHostWithoutWH()) {
280-
VarsExtractorHandler handler = new VarsExtractorHandler(newDataHosts);
281-
newSystemVariables = handler.execute();
282-
if (newSystemVariables == null) {
273+
try {
274+
loader.testConnection(false);
275+
} catch (Exception e) {
276+
if (LOGGER.isDebugEnabled()) {
277+
LOGGER.debug("just test ,not stop reload, catch exception", e);
278+
}
279+
}
280+
VarsExtractorHandler handler = new VarsExtractorHandler(loader.getDataHosts());
281+
newSystemVariables = handler.execute();
282+
if (newSystemVariables == null) {
283+
if (!loader.isDataHostWithoutWH()) {
283284
throw new IOException("Can't get variables from data node");
285+
} else {
286+
newSystemVariables = DbleServer.getInstance().getSystemVariables();
284287
}
285-
ConfigInitializer confInit = new ConfigInitializer(newSystemVariables.isLowerCaseTableNames());
286-
newUsers = confInit.getUsers();
287-
newSchemas = confInit.getSchemas();
288-
newDataNodes = confInit.getDataNodes();
289-
newErRelations = confInit.getErRelations();
290-
newFirewall = confInit.getFirewall();
291-
newDataHosts = confInit.getDataHosts();
292288
}
289+
ConfigInitializer confInit = new ConfigInitializer(newSystemVariables.isLowerCaseTableNames());
290+
Map<String, UserConfig> newUsers = confInit.getUsers();
291+
Map<String, SchemaConfig> newSchemas = confInit.getSchemas();
292+
Map<String, PhysicalDBNode> newDataNodes = confInit.getDataNodes();
293+
Map<ERTable, Set<ERTable>> newErRelations = confInit.getErRelations();
294+
FirewallConfig newFirewall = confInit.getFirewall();
295+
Map<String, PhysicalDBPool> newDataHosts = confInit.getDataHosts();
293296

294297
if ((loadAllMode & ManagerParseConfig.OPTT_MODE) != 0) {
295298
try {

0 commit comments

Comments
 (0)