Search in sources :

Example 16 with ServerConfig

use of com.actiontech.dble.config.ServerConfig in project dble by actiontech.

the class NonBlockingSession method kill.

protected void kill() {
    AtomicInteger count = new AtomicInteger(0);
    Map<RouteResultsetNode, BackendConnection> toKilled = new HashMap<>();
    for (Map.Entry<RouteResultsetNode, BackendConnection> entry : target.entrySet()) {
        BackendConnection c = entry.getValue();
        if (c != null && !c.isDDL()) {
            toKilled.put(entry.getKey(), c);
            count.incrementAndGet();
        } else if (c != null && c.isDDL()) {
            // if the sql executing is a ddl,do not kill the query,just close the connection
            this.terminate();
            return;
        }
    }
    for (Entry<RouteResultsetNode, BackendConnection> en : toKilled.entrySet()) {
        KillConnectionHandler kill = new KillConnectionHandler(en.getValue(), this);
        ServerConfig conf = DbleServer.getInstance().getConfig();
        PhysicalDBNode dn = conf.getDataNodes().get(en.getKey().getName());
        try {
            dn.getConnectionFromSameSource(en.getValue().getSchema(), true, en.getValue(), kill, en.getKey());
        } catch (Exception e) {
            LOGGER.info("get killer connection failed for " + en.getKey(), e);
            kill.connectionError(e, null);
        }
    }
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) ServerConfig(com.actiontech.dble.config.ServerConfig) BackendConnection(com.actiontech.dble.backend.BackendConnection) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) ConcurrentMap(java.util.concurrent.ConcurrentMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 17 with ServerConfig

use of com.actiontech.dble.config.ServerConfig in project dble by actiontech.

the class GlobalTableUtil method getGlobalTable.

private static void getGlobalTable() {
    ServerConfig config = DbleServer.getInstance().getConfig();
    for (Map.Entry<String, SchemaConfig> entry : config.getSchemas().entrySet()) {
        for (TableConfig table : entry.getValue().getTables().values()) {
            if (table.isGlobalTable()) {
                String tableName = table.getName();
                if (DbleServer.getInstance().getSystemVariables().isLowerCaseTableNames()) {
                    tableName = tableName.toLowerCase();
                }
                globalTableMap.put(entry.getKey() + "." + tableName, table);
            }
        }
    }
}
Also used : ServerConfig(com.actiontech.dble.config.ServerConfig) SchemaConfig(com.actiontech.dble.config.model.SchemaConfig) TableConfig(com.actiontech.dble.config.model.TableConfig) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 18 with ServerConfig

use of com.actiontech.dble.config.ServerConfig in project dble by actiontech.

the class ShowDatabases method response.

public static void response(ServerConnection c) {
    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();
    Map<String, UserConfig> users = conf.getUsers();
    UserConfig user = users == null ? null : users.get(c.getUser());
    if (user != null) {
        TreeSet<String> schemaSet = new TreeSet<>();
        Set<String> schemaList = user.getSchemas();
        if (schemaList == null || schemaList.size() == 0) {
            schemaSet.addAll(conf.getSchemas().keySet());
        } else {
            for (String schema : schemaList) {
                schemaSet.add(schema);
            }
        }
        for (String name : schemaSet) {
            RowDataPacket row = new RowDataPacket(FIELD_COUNT);
            row.add(StringUtil.encode(name, c.getCharset().getResults()));
            row.setPacketId(++packetId);
            buffer = row.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 : ServerConfig(com.actiontech.dble.config.ServerConfig) TreeSet(java.util.TreeSet) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) UserConfig(com.actiontech.dble.config.model.UserConfig) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 19 with ServerConfig

use of com.actiontech.dble.config.ServerConfig in project dble by actiontech.

the class SingleNodeHandler method execute.

public void execute() throws Exception {
    startTime = System.currentTimeMillis();
    ServerConnection sc = session.getSource();
    waitingResponse = true;
    this.packetId = 0;
    final BackendConnection conn = session.getTarget(node);
    node.setRunOnSlave(rrs.getRunOnSlave());
    if (session.tryExistsCon(conn, node)) {
        execute(conn);
    } else {
        // create new connection
        node.setRunOnSlave(rrs.getRunOnSlave());
        ServerConfig conf = DbleServer.getInstance().getConfig();
        PhysicalDBNode dn = conf.getDataNodes().get(node.getName());
        dn.getConnection(dn.getDatabase(), session.getSource().isTxStart(), sc.isAutocommit(), node, this, node);
    }
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) ServerConfig(com.actiontech.dble.config.ServerConfig) BackendConnection(com.actiontech.dble.backend.BackendConnection) ServerConnection(com.actiontech.dble.server.ServerConnection)

Aggregations

ServerConfig (com.actiontech.dble.config.ServerConfig)19 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)9 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)9 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)8 PhysicalDatasource (com.actiontech.dble.backend.datasource.PhysicalDatasource)7 DBHeartbeat (com.actiontech.dble.backend.heartbeat.DBHeartbeat)5 SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)5 UserConfig (com.actiontech.dble.config.model.UserConfig)5 LinkedList (java.util.LinkedList)4 TableConfig (com.actiontech.dble.config.model.TableConfig)3 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)3 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)3 RouteResultsetNode (com.actiontech.dble.route.RouteResultsetNode)3 DataSourceSyncRecorder (com.actiontech.dble.statistic.DataSourceSyncRecorder)3 ByteBuffer (java.nio.ByteBuffer)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 BackendConnection (com.actiontech.dble.backend.BackendConnection)2 ERTable (com.actiontech.dble.config.model.ERTable)2 FirewallConfig (com.actiontech.dble.config.model.FirewallConfig)2 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)2