Search in sources :

Example 1 with DDLInfo

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

the class DDLChildListener method updateMeta.

private void updateMeta(ChildData childData) {
    String data = new String(childData.getData(), StandardCharsets.UTF_8);
    LOGGER.info("DDL node " + childData.getPath() + " updated , and data is " + data);
    DDLInfo ddlInfo = new DDLInfo(data);
    if (ddlInfo.getFrom().equals(ZkConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID))) {
        // self node
        return;
    }
    if (DDLStatus.INIT == ddlInfo.getStatus()) {
        return;
    }
    DbleServer.getInstance().getTmManager().updateMetaData(ddlInfo.getSchema(), ddlInfo.getSql(), DDLStatus.SUCCESS.equals(ddlInfo.getStatus()), false);
}
Also used : DDLInfo(com.actiontech.dble.config.loader.zkprocess.zookeeper.process.DDLInfo)

Example 2 with DDLInfo

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

the class DDLChildListener method lockTableByNewNode.

private void lockTableByNewNode(ChildData childData) throws Exception {
    String data = new String(childData.getData(), StandardCharsets.UTF_8);
    LOGGER.info("DDL node " + childData.getPath() + " created , and data is " + data);
    DDLInfo ddlInfo = new DDLInfo(data);
    final String fromNode = ddlInfo.getFrom();
    if (fromNode.equals(ZkConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID))) {
        // self node
        return;
    }
    if (DDLStatus.INIT != ddlInfo.getStatus()) {
        return;
    }
    String nodeName = childData.getPath().substring(childData.getPath().lastIndexOf("/") + 1);
    String[] tableInfo = nodeName.split("\\.");
    final String schema = StringUtil.removeBackQuote(tableInfo[0]);
    final String table = StringUtil.removeBackQuote(tableInfo[1]);
    try {
        DbleServer.getInstance().getTmManager().addMetaLock(schema, table);
    } catch (Exception t) {
        DbleServer.getInstance().getTmManager().removeMetaLock(schema, table);
        throw t;
    }
}
Also used : DDLInfo(com.actiontech.dble.config.loader.zkprocess.zookeeper.process.DDLInfo)

Example 3 with DDLInfo

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

the class ProxyMetaManager method notifyResponseZKDdl.

public void notifyResponseZKDdl(String schema, String table, String sql, DDLInfo.DDLStatus ddlStatus, boolean needNotifyOther) throws Exception {
    CuratorFramework zkConn = ZKUtils.getConnection();
    DDLInfo ddlInfo = new DDLInfo(schema, sql, ZkConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), ddlStatus);
    String nodeName = StringUtil.getFullName(schema, table);
    String nodePath = ZKPaths.makePath(KVPathUtil.getDDLPath(), nodeName);
    String instancePath = ZKPaths.makePath(nodePath, KVPathUtil.DDL_INSTANCE);
    String thisNode = ZkConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID);
    ZKUtils.createTempNode(instancePath, thisNode);
    if (needNotifyOther) {
        zkConn.setData().forPath(nodePath, ddlInfo.toString().getBytes(StandardCharsets.UTF_8));
        while (true) {
            List<String> preparedList = zkConn.getChildren().forPath(instancePath);
            List<String> onlineList = zkConn.getChildren().forPath(KVPathUtil.getOnlinePath());
            if (preparedList.size() >= onlineList.size()) {
                zkConn.delete().deletingChildrenIfNeeded().forPath(nodePath);
                break;
            }
            LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(100));
        }
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) DDLInfo(com.actiontech.dble.config.loader.zkprocess.zookeeper.process.DDLInfo)

Example 4 with DDLInfo

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

the class OfflineStatusListener method releaseForDDL.

private void releaseForDDL(String crashNode) {
    String ddlPath = KVPathUtil.getDDLPath();
    CuratorFramework zkConn = ZKUtils.getConnection();
    try {
        List<String> ddlList = zkConn.getChildren().forPath(ddlPath);
        if (ddlList == null) {
            return;
        }
        for (String ddlNode : ddlList) {
            String ddlNodePath = ZKPaths.makePath(ddlPath, ddlNode);
            byte[] ddlData = zkConn.getData().forPath(ddlNodePath);
            String data = new String(ddlData, StandardCharsets.UTF_8);
            DDLInfo ddlInfo = new DDLInfo(data);
            if (!ddlInfo.getFrom().equals(crashNode)) {
                continue;
            }
            if (DDLInfo.DDLStatus.INIT == ddlInfo.getStatus()) {
                String[] tableInfo = ddlNode.split("\\.");
                String schema = StringUtil.removeBackQuote(tableInfo[0]);
                String table = StringUtil.removeBackQuote(tableInfo[1]);
                DbleServer.getInstance().getTmManager().removeMetaLock(schema, table);
                LOGGER.info(" service instance[" + crashNode + "] has crashed. Remove MetaLock for " + ddlNode);
            }
            // other status should be unlocked
            LOGGER.warn(AlarmCode.CORE_CLUSTER_WARN + " service instance[" + crashNode + "] has crashed." + "Please manually check ddl status on every data node and delete ddl node [" + ddlNodePath + "]  from zookeeper " + "after every instance received this message");
        }
    } catch (Exception e) {
        LOGGER.warn(AlarmCode.CORE_ZK_WARN + " releaseForDDL error", e);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) DDLInfo(com.actiontech.dble.config.loader.zkprocess.zookeeper.process.DDLInfo)

Example 5 with DDLInfo

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

the class DDLChildListener method deleteNode.

private void deleteNode(ChildData childData) {
    String data = new String(childData.getData(), StandardCharsets.UTF_8);
    DDLInfo ddlInfo = new DDLInfo(data);
    LOGGER.info("DDL node " + childData.getPath() + " removed , and DDL info is " + ddlInfo.toString());
}
Also used : DDLInfo(com.actiontech.dble.config.loader.zkprocess.zookeeper.process.DDLInfo)

Aggregations

DDLInfo (com.actiontech.dble.config.loader.zkprocess.zookeeper.process.DDLInfo)8 CuratorFramework (org.apache.curator.framework.CuratorFramework)3 UKvBean (com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean)1 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1 SQLDropTableStatement (com.alibaba.druid.sql.ast.statement.SQLDropTableStatement)1 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)1 SQLStatementParser (com.alibaba.druid.sql.parser.SQLStatementParser)1