Search in sources :

Example 6 with ServerConfig

use of com.actiontech.dble.config.ServerConfig 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 7 with ServerConfig

use of com.actiontech.dble.config.ServerConfig 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 8 with ServerConfig

use of com.actiontech.dble.config.ServerConfig 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 9 with ServerConfig

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

the class ServerConnection method routeSystemInfoAndExecuteSQL.

public void routeSystemInfoAndExecuteSQL(String stmt, SchemaUtil.SchemaInfo schemaInfo, int sqlType) {
    ServerConfig conf = DbleServer.getInstance().getConfig();
    UserConfig user = conf.getUsers().get(this.getUser());
    if (user == null || !user.getSchemas().contains(schemaInfo.getSchema())) {
        writeErrMessage("42000", "Access denied for user '" + this.getUser() + "' to database '" + schemaInfo.getSchema() + "'", ErrorCode.ER_DBACCESS_DENIED_ERROR);
        return;
    }
    RouteResultset rrs = new RouteResultset(stmt, sqlType);
    try {
        if (RouterUtil.isNoSharding(schemaInfo.getSchemaConfig(), schemaInfo.getTable())) {
            RouterUtil.routeToSingleNode(rrs, schemaInfo.getSchemaConfig().getDataNode());
        } else {
            TableConfig tc = schemaInfo.getSchemaConfig().getTables().get(schemaInfo.getTable());
            if (tc == null) {
                String msg = "Table '" + schemaInfo.getSchema() + "." + schemaInfo.getTable() + "' doesn't exist";
                writeErrMessage("42S02", msg, ErrorCode.ER_NO_SUCH_TABLE);
                return;
            }
            RouterUtil.routeToRandomNode(rrs, schemaInfo.getSchemaConfig(), schemaInfo.getTable());
        }
        session.execute(rrs);
    } catch (Exception e) {
        executeException(e, stmt);
    }
}
Also used : ServerConfig(com.actiontech.dble.config.ServerConfig) TableConfig(com.actiontech.dble.config.model.TableConfig) UserConfig(com.actiontech.dble.config.model.UserConfig) SQLNonTransientException(java.sql.SQLNonTransientException) SQLException(java.sql.SQLException) IOException(java.io.IOException) RouteResultset(com.actiontech.dble.route.RouteResultset)

Example 10 with ServerConfig

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

the class FileSystemRepository method init.

/**
 * init the file read & create the viewMap
 */
public void init() {
    try {
        ServerConfig config = DbleServer.getInstance().getConfig();
        SystemConfig systemConfig = config.getSystem();
        baseDir = systemConfig.getViewPersistenceConfBaseDir();
        baseName = systemConfig.getViewPersistenceConfBaseName();
        // Judge whether exist the basedir
        createBaseDir();
        // open a channel of the view config file
        RandomAccessFile randomAccessFile = new RandomAccessFile(baseDir + baseName, "rw");
        rwChannel = randomAccessFile.getChannel();
        viewCreateSqlMap = this.getObject();
    } catch (Exception e) {
        LOGGER.info("init view from file error make sure the file is correct :" + e.getMessage());
    }
}
Also used : ServerConfig(com.actiontech.dble.config.ServerConfig) SystemConfig(com.actiontech.dble.config.model.SystemConfig)

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