Search in sources :

Example 1 with ConfStatus

use of com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ConfStatus in project dble by actiontech.

the class ReloadConfig method reloadWithUcore.

/**
 * reload the config with ucore notify
 *
 * @param loadAll
 * @param loadAllMode
 * @param c
 */
private static void reloadWithUcore(final boolean loadAll, final int loadAllMode, ManagerConnection c) {
    // step 1 lock the local meta ,than all the query depends on meta will be hanging
    final ReentrantLock lock = DbleServer.getInstance().getConfig().getLock();
    lock.lock();
    try {
        // step 2 reload the local config file
        load(loadAll, loadAllMode);
        // step 3 if the reload with no error ,than write the config file into ucore remote
        XmltoUcore.initFileToUcore();
        // step 4 write the reload flag and self reload result into ucore,notify the other dble to reload
        ConfStatus status = new ConfStatus(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), loadAll ? ConfStatus.Status.RELOAD_ALL : ConfStatus.Status.RELOAD, loadAll ? String.valueOf(loadAllMode) : null);
        ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getConfStatusPath(), status.toString());
        ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getSelfConfStatusPath(), UConfigStatusResponse.SUCCESS);
        // step 5 start a loop to check if all the dble in cluster is reload finished
        while (ClusterUcoreSender.getKeyTreeSize(UcorePathUtil.getConfStatusPath() + SEPARATOR) < ClusterUcoreSender.getKeyTreeSize(UcorePathUtil.getOnlinePath() + SEPARATOR)) {
            LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(1000));
        }
        // step 6 delete the reload flag
        ClusterUcoreSender.deleteKVTree(UcorePathUtil.getConfStatusPath() + SEPARATOR);
        writeOKResult(c);
    } catch (Exception e) {
        LOGGER.warn("reload config failure", e);
        writeErrorResult(c, e.getMessage() == null ? e.toString() : e.getMessage());
    } finally {
        lock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) ConfStatus(com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ConfStatus)

Example 2 with ConfStatus

use of com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ConfStatus in project dble by actiontech.

the class RollbackConfig method rollbackWithUcore.

private static void rollbackWithUcore(ManagerConnection c) {
    // step 1 lock the local meta ,than all the query depends on meta will be hanging
    final ReentrantLock lock = DbleServer.getInstance().getConfig().getLock();
    lock.lock();
    try {
        // step 2 rollback self config
        rollback();
        // step 3 tail the ucore & notify the other dble
        ConfStatus status = new ConfStatus(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), ConfStatus.Status.ROLLBACK, null);
        ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getConfStatusPath(), status.toString());
        // step 4 set self status success
        ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getSelfConfStatusPath(), UConfigStatusResponse.SUCCESS);
        // step 5 start a loop to check if all the dble in cluster is reload finished
        while (ClusterUcoreSender.getKeyTreeSize(UcorePathUtil.getConfStatusPath()) < ClusterUcoreSender.getKeyTreeSize(UcorePathUtil.getOnlinePath())) {
            LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(1000));
        }
        // step 6 delete the reload flag
        ClusterUcoreSender.deleteKVTree(UcorePathUtil.getConfStatusPath());
    } catch (Exception e) {
        LOGGER.warn("reload config failure", e);
        writeErrorResult(c, e.getMessage() == null ? e.toString() : e.getMessage());
    } finally {
        lock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) ConfStatus(com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ConfStatus)

Example 3 with ConfStatus

use of com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ConfStatus in project dble by actiontech.

the class ConfigStatusListener method notifyProcess.

@Override
public boolean notifyProcess() throws Exception {
    if (DbleServer.getInstance().getFrontProcessors() != null) {
        DirectoryInf statusDirectory = new ZkDirectoryImpl(currZkPath, null);
        this.getTreeDirectory(currZkPath, KVPathUtil.CONF_STATUS, statusDirectory);
        ZkDataImpl zkData = (ZkDataImpl) statusDirectory.getSubordinateInfo().get(0);
        ConfStatus status = new ConfStatus(zkData.getValue());
        if (status.getFrom().equals(ZkConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID))) {
            // self node
            return true;
        }
        LOGGER.info("ConfigStatusListener notifyProcess zk to object  :" + status);
        if (status.getStatus() == ConfStatus.Status.ROLLBACK) {
            try {
                RollbackConfig.rollback();
                ZKUtils.createTempNode(KVPathUtil.getConfStatusPath(), ZkConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), SUCCESS.getBytes(StandardCharsets.UTF_8));
            } catch (Exception e) {
                String errorinfo = e.getMessage() == null ? e.toString() : e.getMessage();
                ZKUtils.createTempNode(KVPathUtil.getConfStatusPath(), ZkConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), errorinfo.getBytes(StandardCharsets.UTF_8));
            }
            return true;
        }
        for (NotifyService service : childService) {
            try {
                service.notifyProcess();
            } catch (Exception e) {
                LOGGER.warn(AlarmCode.CORE_ZK_WARN + "ConfigStatusListener notify  error :" + service + " ,Exception info:", e);
            }
        }
        try {
            if (status.getStatus() == ConfStatus.Status.RELOAD_ALL) {
                ReloadConfig.reloadAll(Integer.parseInt(status.getParams()));
            } else {
                ReloadConfig.reload();
            }
            ZKUtils.createTempNode(KVPathUtil.getConfStatusPath(), ZkConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), SUCCESS.getBytes(StandardCharsets.UTF_8));
        } catch (Exception e) {
            String errorinfo = e.getMessage() == null ? e.toString() : e.getMessage();
            ZKUtils.createTempNode(KVPathUtil.getConfStatusPath(), ZkConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), errorinfo.getBytes(StandardCharsets.UTF_8));
        }
    }
    return true;
}
Also used : ConfStatus(com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ConfStatus) DirectoryInf(com.actiontech.dble.config.loader.zkprocess.zookeeper.DirectoryInf) ZkDirectoryImpl(com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ZkDirectoryImpl) NotifyService(com.actiontech.dble.config.loader.zkprocess.comm.NotifyService) ZkDataImpl(com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ZkDataImpl)

Example 4 with ConfStatus

use of com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ConfStatus in project dble by actiontech.

the class XmltoZkMain method writeConfFileToZK.

public static void writeConfFileToZK(boolean isAll, final int allMode) throws Exception {
    ZookeeperProcessListen zkListen = new ZookeeperProcessListen();
    CuratorFramework zkConn = ZKUtils.getConnection();
    XmlProcessBase xmlProcess = new XmlProcessBase();
    // xmltozk for schema
    new SchemasxmlTozkLoader(zkListen, zkConn, xmlProcess);
    // xmltozk for server
    new ServerxmlTozkLoader(zkListen, zkConn, xmlProcess);
    // xmltozk for rule
    new RulesxmlTozkLoader(zkListen, zkConn, xmlProcess);
    xmlProcess.initJaxbClass();
    zkListen.initAllNode();
    zkListen.clearInited();
    // write flag
    ConfStatus status = new ConfStatus(ZkConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), isAll ? ConfStatus.Status.RELOAD_ALL : ConfStatus.Status.RELOAD, isAll ? String.valueOf(allMode) : null);
    zkConn.setData().forPath(KVPathUtil.getConfStatusPath(), status.toString().getBytes(StandardCharsets.UTF_8));
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ConfStatus(com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ConfStatus) XmlProcessBase(com.actiontech.dble.config.loader.zkprocess.parse.XmlProcessBase) ZookeeperProcessListen(com.actiontech.dble.config.loader.zkprocess.comm.ZookeeperProcessListen)

Example 5 with ConfStatus

use of com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ConfStatus in project dble by actiontech.

the class UConfigStatusResponse method notifyProcess.

@Override
public void notifyProcess(UKvBean pathValue) throws Exception {
    if (DbleServer.getInstance().getFrontProcessors() != null) {
        // step 1 check if the change is from itself
        LOGGER.debug("notify " + pathValue.getKey() + " " + pathValue.getValue() + " " + pathValue.getChangeType());
        ConfStatus status = new ConfStatus(pathValue.getValue());
        if (status.getFrom().equals(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID))) {
            // self node
            return;
        }
        // check if the reload is already be done by this node
        if (!"".equals(ClusterUcoreSender.getKey(UcorePathUtil.getSelfConfStatusPath()).getValue()) || "".equals(ClusterUcoreSender.getKey(UcorePathUtil.getConfStatusPath()).getValue())) {
            return;
        }
        // step 2 check the change type /rollback /reload
        if (status.getStatus() == ConfStatus.Status.ROLLBACK) {
            LOGGER.debug("rollback " + pathValue.getKey() + " " + pathValue.getValue() + " " + pathValue.getChangeType());
            try {
                RollbackConfig.rollback();
                ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getSelfConfStatusPath(), UConfigStatusResponse.SUCCESS);
            } catch (Exception e) {
                String errorinfo = e.getMessage() == null ? e.toString() : e.getMessage();
                ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getSelfConfStatusPath(), errorinfo);
            }
            return;
        }
        // step 3 reload the config and set the self config status
        try {
            if (status.getStatus() == ConfStatus.Status.RELOAD_ALL) {
                LOGGER.debug("reload_all " + pathValue.getKey() + " " + pathValue.getValue() + " " + pathValue.getChangeType());
                ReloadConfig.reloadAll(Integer.parseInt(status.getParams()));
            } else {
                LOGGER.debug("reload " + pathValue.getKey() + " " + pathValue.getValue() + " " + pathValue.getChangeType());
                ReloadConfig.reload();
            }
            ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getSelfConfStatusPath(), UConfigStatusResponse.SUCCESS);
        } catch (Exception e) {
            String errorinfo = e.getMessage() == null ? e.toString() : e.getMessage();
            ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getSelfConfStatusPath(), errorinfo);
        }
    }
}
Also used : ConfStatus(com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ConfStatus)

Aggregations

ConfStatus (com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ConfStatus)6 ReentrantLock (java.util.concurrent.locks.ReentrantLock)2 CuratorFramework (org.apache.curator.framework.CuratorFramework)2 NotifyService (com.actiontech.dble.config.loader.zkprocess.comm.NotifyService)1 ZookeeperProcessListen (com.actiontech.dble.config.loader.zkprocess.comm.ZookeeperProcessListen)1 XmlProcessBase (com.actiontech.dble.config.loader.zkprocess.parse.XmlProcessBase)1 DirectoryInf (com.actiontech.dble.config.loader.zkprocess.zookeeper.DirectoryInf)1 ZkDataImpl (com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ZkDataImpl)1 ZkDirectoryImpl (com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ZkDirectoryImpl)1