Search in sources :

Example 16 with PhysicalDBNode

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

the class NonBlockingSession method freshConn.

public MySQLConnection freshConn(MySQLConnection errConn, ResponseHandler queryHandler) {
    for (final RouteResultsetNode node : this.getTargetKeys()) {
        final MySQLConnection mysqlCon = (MySQLConnection) this.getTarget(node);
        if (errConn.equals(mysqlCon)) {
            ServerConfig conf = DbleServer.getInstance().getConfig();
            PhysicalDBNode dn = conf.getDataNodes().get(node.getName());
            try {
                MySQLConnection newConn = (MySQLConnection) dn.getConnection(dn.getDatabase(), errConn.isAutocommit(), false);
                newConn.setXaStatus(errConn.getXaStatus());
                if (!newConn.setResponseHandler(queryHandler)) {
                    return errConn;
                }
                this.bindConnection(node, newConn);
                return newConn;
            } catch (Exception e) {
                return errConn;
            }
        }
    }
    return errConn;
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) ServerConfig(com.actiontech.dble.config.ServerConfig) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 17 with PhysicalDBNode

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

the class FetchMySQLSequenceHandler method execute.

public void execute(SequenceVal seqVal) {
    ServerConfig conf = DbleServer.getInstance().getConfig();
    PhysicalDBNode mysqlDN = conf.getDataNodes().get(seqVal.dataNode);
    try {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("execute in data node " + seqVal.dataNode + " for fetch sequence sql " + seqVal.sql);
        }
        // change Select mode to Update mode. Make sure the query send to the write host
        mysqlDN.getConnection(mysqlDN.getDatabase(), true, true, new RouteResultsetNode(seqVal.dataNode, ServerParse.UPDATE, seqVal.sql), this, seqVal);
    } catch (Exception e) {
        LOGGER.info("get connection err " + e);
    }
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) ServerConfig(com.actiontech.dble.config.ServerConfig) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode)

Example 18 with PhysicalDBNode

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

the class HintDataNodeHandler method route.

@Override
public RouteResultset route(SchemaConfig schema, int sqlType, String realSQL, ServerConnection sc, LayerCachePool cachePool, String hintSQLValue, int hintSqlType, Map hintMap) throws SQLNonTransientException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("route datanode sql hint from " + realSQL);
    }
    RouteResultset rrs = new RouteResultset(realSQL, sqlType);
    PhysicalDBNode dataNode = DbleServer.getInstance().getConfig().getDataNodes().get(hintSQLValue);
    if (dataNode != null) {
        rrs = RouterUtil.routeToSingleNode(rrs, dataNode.getName());
    } else {
        String msg = "can't find hint datanode:" + hintSQLValue;
        LOGGER.info(msg);
        throw new SQLNonTransientException(msg);
    }
    return rrs;
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) SQLNonTransientException(java.sql.SQLNonTransientException) RouteResultset(com.actiontech.dble.route.RouteResultset)

Example 19 with PhysicalDBNode

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

the class ConfigInitializer method testConnection.

public void testConnection(boolean isStart) {
    if (this.dataNodes != null && this.dataHosts != null) {
        Map<String, Boolean> map = new HashMap<>();
        for (PhysicalDBNode dataNode : dataNodes.values()) {
            String database = dataNode.getDatabase();
            PhysicalDBPool pool = dataNode.getDbPool();
            if (isStart) {
                // start for first time, 1.you can set write host as empty
                if (pool.getSources() == null || pool.getSources().length == 0) {
                    continue;
                }
                DBHostConfig wHost = pool.getSource().getConfig();
                // start for first time, 2.you can set write host as yourself
                if (("localhost".equalsIgnoreCase(wHost.getIp()) || "127.0.0.1".equalsIgnoreCase(wHost.getIp())) && wHost.getPort() == this.system.getServerPort()) {
                    continue;
                }
            }
            for (PhysicalDatasource ds : pool.getAllDataSources()) {
                String key = ds.getName() + "_" + database;
                if (map.get(key) == null) {
                    map.put(key, false);
                    try {
                        boolean isConnected = ds.testConnection(database);
                        map.put(key, isConnected);
                    } catch (IOException e) {
                        LOGGER.info("test conn " + key + " error:", e);
                    }
                }
            }
        }
        boolean isConnectivity = true;
        for (Map.Entry<String, Boolean> entry : map.entrySet()) {
            String key = entry.getKey();
            Boolean value = entry.getValue();
            if (!value && isConnectivity) {
                LOGGER.info("SelfCheck### test " + key + " database connection failed ");
                isConnectivity = false;
            } else {
                LOGGER.info("SelfCheck### test " + key + " database connection success ");
            }
        }
        if (!isConnectivity) {
            throw new ConfigException("SelfCheck### there are some datasource connection failed, pls check!");
        }
    }
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) ConfigException(com.actiontech.dble.config.util.ConfigException) IOException(java.io.IOException) PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource)

Example 20 with PhysicalDBNode

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

the class ShowDataSource method execute.

public static void execute(ManagerConnection c, String name) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = HEADER.write(buffer, c, true);
    // write fields
    for (FieldPacket field : FIELDS) {
        buffer = field.write(buffer, c, true);
    }
    // write eof
    buffer = EOF.write(buffer, c, true);
    // write rows
    byte packetId = EOF.getPacketId();
    ServerConfig conf = DbleServer.getInstance().getConfig();
    if (null != name) {
        PhysicalDBNode dn = conf.getDataNodes().get(name);
        for (PhysicalDatasource w : dn.getDbPool().getAllDataSources()) {
            RowDataPacket row = getRow(w, c.getCharset().getResults());
            row.setPacketId(++packetId);
            buffer = row.write(buffer, c, true);
        }
    } else {
        // add all
        for (Map.Entry<String, PhysicalDBPool> entry : conf.getDataHosts().entrySet()) {
            PhysicalDBPool dataHost = entry.getValue();
            for (int i = 0; i < dataHost.getSources().length; i++) {
                RowDataPacket row = getRow(dataHost.getSources()[i], c.getCharset().getResults());
                row.setPacketId(++packetId);
                buffer = row.write(buffer, c, true);
                if (dataHost.getrReadSources().get(i) != null) {
                    for (PhysicalDatasource w : dataHost.getrReadSources().get(i)) {
                        RowDataPacket sRow = getRow(w, c.getCharset().getResults());
                        sRow.setPacketId(++packetId);
                        buffer = sRow.write(buffer, c, true);
                    }
                }
            }
        }
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);
    // post write
    c.write(buffer);
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) ByteBuffer(java.nio.ByteBuffer) ServerConfig(com.actiontech.dble.config.ServerConfig) PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket) Map(java.util.Map)

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