private static Set<String> getTableSet(ServerConnection c, Map<String, String> parm) { TreeSet<String> tableSet = new TreeSet<String>(); CloudbConfig conf = CloudbServer.getInstance().getConfig(); Map<String, UserConfig> users = conf.getUsers(); UserConfig user = users == null ? null : users.get(c.getUser()); if (user != null) { Map<String, SchemaConfig> schemas = conf.getSchemas(); for (String name : schemas.keySet()) { if (null != parm.get(SCHEMA_KEY) && parm.get(SCHEMA_KEY).toUpperCase().equals(name.toUpperCase())) { if (null == parm.get("LIKE_KEY")) { tableSet.addAll(schemas.get(name).getTables().keySet()); } else { String p = "^" + parm.get("LIKE_KEY").replaceAll("%", ".*"); Pattern pattern = Pattern.compile(p, Pattern.CASE_INSENSITIVE); Matcher ma; for (String tname : schemas.get(name).getTables().keySet()) { ma = pattern.matcher(tname); if (ma.matches()) { tableSet.add(tname); } } } } } ; } return tableSet; }
private static boolean reload_all() { // 载入新的配置 ConfigInitializer loader = new ConfigInitializer(true); Map<String, UserConfig> users = loader.getUsers(); Map<String, SchemaConfig> schemas = loader.getSchemas(); Map<String, PhysicalDBNode> dataNodes = loader.getDataNodes(); Map<String, PhysicalDBPool> dataHosts = loader.getDataHosts(); CloudbCluster cluster = loader.getCluster(); QuarantineConfig quarantine = loader.getQuarantine(); // 应用新配置 CloudbConfig conf = CloudbServer.getInstance().getConfig(); conf.setDataNodes(dataNodes); Map<String, PhysicalDBPool> cNodes = conf.getDataHosts(); boolean reloadStatus = true; for (PhysicalDBPool dn : dataHosts.values()) { dn.setSchemas( CloudbServer.getInstance().getConfig().getDataNodeSchemasOfDataHost(dn.getHostName())); // init datahost String index = DnPropertyUtil.loadDnIndexProps().getProperty(dn.getHostName(), "0"); if (!"0".equals(index)) { LOGGER.info("init datahost: " + dn.getHostName() + " to use datasource index:" + index); } dn.init(Integer.valueOf(index)); // dn.init(0); if (!dn.isInitSuccess()) { reloadStatus = false; break; } } // 如果重载不成功,则清理已初始化的资源。 if (!reloadStatus) { LOGGER.warn("reload failed ,clear previously created datasources "); for (PhysicalDBPool dn : dataHosts.values()) { dn.clearDataSources("reload config"); dn.stopHeartbeat(); } return false; } // 应用重载 conf.reload(users, schemas, dataNodes, dataHosts, cluster, quarantine, true); // 处理旧的资源 for (PhysicalDBPool dn : cNodes.values()) { dn.clearDataSources("reload config clear old datasources"); dn.stopHeartbeat(); } // 清理缓存 CloudbServer.getInstance().getCacheService().clearCache(); return true; }
private static boolean reload() { // 载入新的配置 ConfigInitializer loader = new ConfigInitializer(false); Map<String, UserConfig> users = loader.getUsers(); Map<String, SchemaConfig> schemas = loader.getSchemas(); Map<String, PhysicalDBNode> dataNodes = loader.getDataNodes(); Map<String, PhysicalDBPool> dataHosts = loader.getDataHosts(); CloudbCluster cluster = loader.getCluster(); QuarantineConfig quarantine = loader.getQuarantine(); // 应用新配置 CloudbServer instance = CloudbServer.getInstance(); CloudbConfig conf = instance.getConfig(); // 应用重载 conf.reload(users, schemas, dataNodes, dataHosts, cluster, quarantine, false); // 清理缓存 instance.getCacheService().clearCache(); return true; }