Search in sources :

Example 1 with UDistributeLock

use of com.actiontech.dble.config.loader.ucoreprocess.UDistributeLock in project dble by actiontech.

the class ShowBinlogStatus method showBinlogWithUcore.

private static void showBinlogWithUcore(ManagerConnection c, long timeout) {
    // step 1 get the distributeLock of the ucore
    UDistributeLock distributeLock = new UDistributeLock(UcorePathUtil.getBinlogPauseLockPath(), UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID));
    try {
        if (!distributeLock.acquire()) {
            c.writeErrMessage(ErrorCode.ER_UNKNOWN_ERROR, "There is another command is showing BinlogStatus");
            return;
        }
        try {
            // step 2 try to lock all the commit flag in server
            if (!DbleServer.getInstance().getBackupLocked().compareAndSet(false, true)) {
                c.writeErrMessage(ErrorCode.ER_UNKNOWN_ERROR, "There is another command is showing BinlogStatus");
            } else {
                // step 3 notify other dble to stop the commit & set self status
                BinlogPause pauseOnInfo = new BinlogPause(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), BinlogPauseStatus.ON);
                ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getBinlogPauseStatus(), pauseOnInfo.toString());
                ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getBinlogPauseStatusSelf(), "true");
                // step 4 wait til other dbles to feedback the ucore flag
                long beginTime = TimeUtil.currentTimeMillis();
                boolean isAllSuccess = true;
                List<UKvBean> responseList = ClusterUcoreSender.getKeyTree(UcorePathUtil.getBinlogPauseStatus());
                List<UKvBean> onlineList = ClusterUcoreSender.getKeyTree(UcorePathUtil.getOnlinePath());
                while (responseList.size() < onlineList.size()) {
                    // if it is time out
                    if (TimeUtil.currentTimeMillis() > beginTime + 2 * timeout) {
                        isAllSuccess = false;
                        errMsg = "timeout while waiting for unfinished distributed transactions.";
                        logger.info(errMsg);
                        break;
                    }
                    LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(1000));
                    responseList = ClusterUcoreSender.getKeyTree(UcorePathUtil.getBinlogPauseStatus());
                    onlineList = ClusterUcoreSender.getKeyTree(UcorePathUtil.getOnlinePath());
                }
                // step 5 check the result if the all the dbles return sucess
                if (isAllSuccess) {
                    for (UKvBean reponseBean : responseList) {
                        if (!Boolean.parseBoolean(reponseBean.getValue())) {
                            isAllSuccess = false;
                        }
                    }
                }
                // step 6 query for the GTID and write back to frontend connections
                if (isAllSuccess) {
                    getQueryResult(c.getCharset().getResults());
                }
                writeResponse(c);
                // step 7 delete the KVtree and notify the cluster
                ClusterUcoreSender.deleteKVTree(UcorePathUtil.getBinlogPauseStatus() + SEPARATOR);
                BinlogPause pauseOffInfo = new BinlogPause(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), BinlogPauseStatus.OFF);
                ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getBinlogPauseStatus(), pauseOffInfo.toString());
            }
        } catch (Exception e) {
            logger.info("catch Exception", e);
        } finally {
            DbleServer.getInstance().getBackupLocked().compareAndSet(true, false);
            distributeLock.release();
        }
    } catch (Exception e) {
        c.writeErrMessage(ErrorCode.ER_UNKNOWN_ERROR, e.getMessage());
    }
}
Also used : BinlogPause(com.actiontech.dble.config.loader.zkprocess.zookeeper.process.BinlogPause) UDistributeLock(com.actiontech.dble.config.loader.ucoreprocess.UDistributeLock) UKvBean(com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean)

Aggregations

UDistributeLock (com.actiontech.dble.config.loader.ucoreprocess.UDistributeLock)1 UKvBean (com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean)1 BinlogPause (com.actiontech.dble.config.loader.zkprocess.zookeeper.process.BinlogPause)1