Search in sources :

Example 11 with PhysicalDBNode

use of com.actiontech.dble.backend.datasource.PhysicalDBNode in project dble by actiontech.

the class ProxyMetaManager method getSelfNodes.

private Set<String> getSelfNodes(ServerConfig config) {
    Set<String> selfNode = null;
    for (Map.Entry<String, PhysicalDBPool> entry : config.getDataHosts().entrySet()) {
        PhysicalDBPool host = entry.getValue();
        DBHostConfig wHost = host.getSource().getConfig();
        if (("localhost".equalsIgnoreCase(wHost.getIp()) || "127.0.0.1".equalsIgnoreCase(wHost.getIp())) && wHost.getPort() == config.getSystem().getServerPort()) {
            for (Map.Entry<String, PhysicalDBNode> nodeEntry : config.getDataNodes().entrySet()) {
                if (nodeEntry.getValue().getDbPool().getHostName().equals(host.getHostName())) {
                    if (selfNode == null) {
                        selfNode = new HashSet<>(2);
                    }
                    selfNode.add(nodeEntry.getKey());
                }
            }
            break;
        }
    }
    return selfNode;
}
Also used : DBHostConfig(com.actiontech.dble.config.model.DBHostConfig) PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool)

Example 12 with PhysicalDBNode

use of com.actiontech.dble.backend.datasource.PhysicalDBNode in project dble by actiontech.

the class AbstractTableMetaHandler method execute.

public void execute() {
    for (String dataNode : dataNodes) {
        if (selfNode != null && selfNode.contains(dataNode)) {
            this.countdown();
            return;
        }
        OneRawSQLQueryResultHandler resultHandler = new OneRawSQLQueryResultHandler(MYSQL_SHOW_CREATE_TABLE_COLS, new MySQLTableStructureListener(dataNode, System.currentTimeMillis(), new ConcurrentHashMap<String, List<String>>()));
        PhysicalDBNode dn = DbleServer.getInstance().getConfig().getDataNodes().get(dataNode);
        SQLJob sqlJob = new SQLJob(SQL_PREFIX + tableName, dn.getDatabase(), resultHandler, dn.getDbPool().getSource());
        sqlJob.run();
    }
}
Also used : OneRawSQLQueryResultHandler(com.actiontech.dble.sqlengine.OneRawSQLQueryResultHandler) PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) SQLJob(com.actiontech.dble.sqlengine.SQLJob) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 13 with PhysicalDBNode

use of com.actiontech.dble.backend.datasource.PhysicalDBNode in project dble by actiontech.

the class ShowTablesHandler method execute.

public void execute() {
    PhysicalDBNode dn = DbleServer.getInstance().getConfig().getDataNodes().get(config.getDataNode());
    String mysqlShowTableCol = "Tables_in_" + dn.getDatabase();
    String[] mysqlShowTableCols = new String[] { mysqlShowTableCol };
    MultiRowSQLQueryResultHandler resultHandler = new MultiRowSQLQueryResultHandler(mysqlShowTableCols, new MySQLShowTablesListener(mysqlShowTableCol));
    SQLJob sqlJob = new SQLJob(SQL, dn.getDatabase(), resultHandler, dn.getDbPool().getSource());
    sqlJob.run();
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) MultiRowSQLQueryResultHandler(com.actiontech.dble.sqlengine.MultiRowSQLQueryResultHandler) SQLJob(com.actiontech.dble.sqlengine.SQLJob)

Example 14 with PhysicalDBNode

use of com.actiontech.dble.backend.datasource.PhysicalDBNode in project dble by actiontech.

the class GlobalTableUtil method consistencyCheck.

public static void consistencyCheck() {
    ServerConfig config = DbleServer.getInstance().getConfig();
    for (TableConfig table : globalTableMap.values()) {
        Map<String, ArrayList<PhysicalDBNode>> executedMap = new HashMap<>();
        // <table name="travelrecord" dataNode="dn1,dn2,dn3"
        for (String nodeName : table.getDataNodes()) {
            Map<String, PhysicalDBNode> map = config.getDataNodes();
            for (PhysicalDBNode dbNode : map.values()) {
                // <dataNode name="dn1" dataHost="localhost1" database="db1" />
                if (nodeName.equals(dbNode.getName())) {
                    // dn1,dn2,dn3
                    PhysicalDBPool pool = dbNode.getDbPool();
                    Collection<PhysicalDatasource> allDS = pool.getAllDataSources();
                    for (PhysicalDatasource pds : allDS) {
                        if (pds instanceof MySQLDataSource) {
                            ArrayList<PhysicalDBNode> nodes = executedMap.get(pds.getName());
                            if (nodes == null) {
                                nodes = new ArrayList<>();
                            }
                            nodes.add(dbNode);
                            executedMap.put(pds.getName(), nodes);
                        }
                    }
                }
            }
        }
        for (Map.Entry<String, ArrayList<PhysicalDBNode>> entry : executedMap.entrySet()) {
            ArrayList<PhysicalDBNode> nodes = entry.getValue();
            String[] schemas = new String[nodes.size()];
            for (int index = 0; index < nodes.size(); index++) {
                schemas[index] = StringUtil.removeBackQuote(nodes.get(index).getDatabase());
            }
            Collection<PhysicalDatasource> allDS = nodes.get(0).getDbPool().getAllDataSources();
            for (PhysicalDatasource pds : allDS) {
                if (pds instanceof MySQLDataSource && entry.getKey().equals(pds.getName())) {
                    MySQLDataSource mds = (MySQLDataSource) pds;
                    MySQLConsistencyChecker checker = new MySQLConsistencyChecker(mds, schemas, table.getName());
                    isInnerColumnCheckFinished = 0;
                    checker.checkInnerColumnExist();
                    while (isInnerColumnCheckFinished <= 0) {
                        LOGGER.debug("isInnerColumnCheckFinished:" + isInnerColumnCheckFinished);
                        try {
                            TimeUnit.SECONDS.sleep(1);
                        } catch (InterruptedException e) {
                            LOGGER.info(e.getMessage());
                        }
                    }
                    LOGGER.debug("isInnerColumnCheckFinished:" + isInnerColumnCheckFinished);
                    // check another measure
                    checker = new MySQLConsistencyChecker(mds, schemas, table.getName());
                    isColumnCountCheckFinished = 0;
                    checker.checkRecordCount();
                    while (isColumnCountCheckFinished <= 0) {
                        LOGGER.debug("isColumnCountCheckFinished:" + isColumnCountCheckFinished);
                        try {
                            TimeUnit.SECONDS.sleep(1);
                        } catch (InterruptedException e) {
                            LOGGER.info(e.getMessage());
                        }
                    }
                    LOGGER.debug("isColumnCountCheckFinished:" + isColumnCountCheckFinished);
                    checker = new MySQLConsistencyChecker(mds, schemas, table.getName());
                    checker.checkMaxTimeStamp();
                }
            }
        }
    }
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) ServerConfig(com.actiontech.dble.config.ServerConfig) MySQLConsistencyChecker(com.actiontech.dble.backend.heartbeat.MySQLConsistencyChecker) PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) MySQLDataSource(com.actiontech.dble.backend.mysql.nio.MySQLDataSource) TableConfig(com.actiontech.dble.config.model.TableConfig) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 15 with PhysicalDBNode

use of com.actiontech.dble.backend.datasource.PhysicalDBNode in project dble by actiontech.

the class TransformSQLJob method run.

@Override
public void run() {
    try {
        if (ds == null) {
            RouteResultsetNode node = new RouteResultsetNode(databaseName, ServerParse.SELECT, sql);
            // create new connection
            PhysicalDBNode dn = DbleServer.getInstance().getConfig().getDataNodes().get(node.getName());
            dn.getConnection(dn.getDatabase(), false, true, node, this, node);
        } else {
            ds.getConnection(databaseName, true, this, null);
        }
    } catch (Exception e) {
        LOGGER.info("can't get connection for sql ,error:" + e);
        ErrorPacket errPacket = new ErrorPacket();
        errPacket.setPacketId(0);
        errPacket.setErrNo(ErrorCode.ER_YES);
        errPacket.setMessage(StringUtil.encode(e.toString(), StandardCharsets.UTF_8.toString()));
        writeError(errPacket.toBytes());
    }
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode)

Aggregations

PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)27 ServerConfig (com.actiontech.dble.config.ServerConfig)9 RouteResultsetNode (com.actiontech.dble.route.RouteResultsetNode)9 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)8 BackendConnection (com.actiontech.dble.backend.BackendConnection)7 SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)5 SQLJob (com.actiontech.dble.sqlengine.SQLJob)4 PhysicalDatasource (com.actiontech.dble.backend.datasource.PhysicalDatasource)3 MySQLConnection (com.actiontech.dble.backend.mysql.nio.MySQLConnection)3 ERTable (com.actiontech.dble.config.model.ERTable)3 FirewallConfig (com.actiontech.dble.config.model.FirewallConfig)3 UserConfig (com.actiontech.dble.config.model.UserConfig)3 ConfigException (com.actiontech.dble.config.util.ConfigException)3 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)3 OneRawSQLQueryResultHandler (com.actiontech.dble.sqlengine.OneRawSQLQueryResultHandler)3 Map (java.util.Map)3 Set (java.util.Set)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ConfigInitializer (com.actiontech.dble.config.ConfigInitializer)2 DBHostConfig (com.actiontech.dble.config.model.DBHostConfig)2