Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 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;
 }