private void rewriteSql(boolean toReplicationMode) {
if (session.isRoot()) {
oldHostIds = db.getHostIds();
if (parameters != null && parameters.containsKey("hostIds")) {
newHostIds = StringUtils.arraySplit(parameters.get("hostIds"), ',', true);
} else {
if (toReplicationMode)
newHostIds = NetEndpointManagerHolder.get().getReplicationEndpoints(db);
else
newHostIds = NetEndpointManagerHolder.get().getShardingEndpoints(db);
}
String hostIds = StringUtils.arrayCombine(oldHostIds, ',') + ","
+ StringUtils.arrayCombine(newHostIds, ',');
db.getParameters().put("hostIds", hostIds);
rewriteSql();
} else {
if (super.isTargetEndpoint(db)) {
oldHostIds = db.getHostIds();
HashSet<String> oldSet = new HashSet<>(Arrays.asList(oldHostIds));
if (parameters != null && parameters.containsKey("hostIds")) {
String[] hostIds = StringUtils.arraySplit(parameters.get("hostIds"), ',', true);
HashSet<String> newSet = new HashSet<>(Arrays.asList(hostIds));
newSet.removeAll(oldSet);
newHostIds = newSet.toArray(new String[0]);
} else {
DbException.throwInternalError();
}
}
}
}