Search in sources :

Example 61 with EOFPacket

use of com.actiontech.dble.net.mysql.EOFPacket in project dble by actiontech.

the class PreparedStmtResponse method response.

public static void response(PreparedStatement pStmt, FrontendConnection c) {
    byte packetId = 0;
    // write preparedOk packet
    PreparedOkPacket preparedOk = new PreparedOkPacket();
    preparedOk.setPacketId(++packetId);
    preparedOk.setStatementId(pStmt.getId());
    preparedOk.setColumnsNumber(pStmt.getColumnsNumber());
    preparedOk.setParametersNumber(pStmt.getParametersNumber());
    ByteBuffer buffer = preparedOk.write(c.allocate(), c, true);
    // write parameter field packet
    int parametersNumber = preparedOk.getParametersNumber();
    if (parametersNumber > 0) {
        for (int i = 0; i < parametersNumber; i++) {
            FieldPacket field = new FieldPacket();
            field.setPacketId(++packetId);
            buffer = field.write(buffer, c, true);
        }
        EOFPacket eof = new EOFPacket();
        eof.setPacketId(++packetId);
        buffer = eof.write(buffer, c, true);
    }
    // write column field packet
    int columnsNumber = preparedOk.getColumnsNumber();
    if (columnsNumber > 0) {
        for (int i = 0; i < columnsNumber; i++) {
            FieldPacket field = new FieldPacket();
            field.setPacketId(++packetId);
            buffer = field.write(buffer, c, true);
        }
        EOFPacket eof = new EOFPacket();
        eof.setPacketId(++packetId);
        buffer = eof.write(buffer, c, true);
    }
    // send buffer
    c.write(buffer);
}
Also used : EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) PreparedOkPacket(com.actiontech.dble.net.mysql.PreparedOkPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 62 with EOFPacket

use of com.actiontech.dble.net.mysql.EOFPacket in project dble by actiontech.

the class SelectDatabase method response.

public static void response(ServerConnection c) {
    ByteBuffer buffer = c.allocate();
    buffer = HEADER.write(buffer, c, true);
    for (FieldPacket field : FIELDS) {
        buffer = field.write(buffer, c, true);
    }
    buffer = EOF.write(buffer, c, true);
    byte packetId = EOF.getPacketId();
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(StringUtil.encode(c.getSchema(), c.getCharset().getResults()));
    row.setPacketId(++packetId);
    buffer = row.write(buffer, c, true);
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);
    c.write(buffer);
}
Also used : RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 63 with EOFPacket

use of com.actiontech.dble.net.mysql.EOFPacket in project dble by actiontech.

the class ShowSysParam method execute.

public static void execute(ManagerConnection 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();
    SystemConfig sysConfig = DbleServer.getInstance().getConfig().getSystem();
    List<String> paramValues = new ArrayList<>();
    paramValues.add(sysConfig.getProcessors() + "");
    paramValues.add(sysConfig.getBackendProcessors() + "");
    paramValues.add(sysConfig.getBufferPoolChunkSize() + "B");
    paramValues.add(sysConfig.getBufferPoolPageSize() + "B");
    paramValues.add(sysConfig.getBufferPoolPageNumber() + "B");
    paramValues.add(sysConfig.getProcessorExecutor() + "");
    paramValues.add(sysConfig.getBackendProcessorExecutor() + "");
    paramValues.add(sysConfig.getBindIp() + "");
    paramValues.add(sysConfig.getServerPort() + "");
    paramValues.add(sysConfig.getManagerPort() + "");
    paramValues.add(sysConfig.getFakeMySQLVersion());
    paramValues.add(sysConfig.getUsingAIO() + "");
    paramValues.add(sysConfig.getUseCompression() + "");
    paramValues.add(sysConfig.getServerNodeId() + "");
    paramValues.add(sysConfig.isUseZKSwitch() + "");
    paramValues.add(sysConfig.getSequnceHandlerType() > 4 || sysConfig.getSequnceHandlerType() < 1 ? "Incorrect Sequence Type" : SEQUENCES[sysConfig.getSequnceHandlerType()]);
    paramValues.add(sysConfig.getMaxPacketSize() / 1024 / 1024 + "M");
    paramValues.add(sysConfig.getServerBacklog() + "");
    paramValues.add(sysConfig.getIdleTimeout() / 1000 / 60 + " Minutes");
    paramValues.add(sysConfig.getCharset() + "");
    paramValues.add(sysConfig.getTxIsolation() > 4 || sysConfig.getTxIsolation() < 1 ? "Incorrect isolation" : ISOLATION_LEVELS[sysConfig.getTxIsolation()]);
    paramValues.add(sysConfig.getSqlExecuteTimeout() + " Seconds");
    paramValues.add(sysConfig.getProcessorCheckPeriod() / 1000 + " Seconds");
    paramValues.add(sysConfig.getDataNodeIdleCheckPeriod() / 1000 + " Seconds");
    paramValues.add(sysConfig.getDataNodeHeartbeatPeriod() / 1000 + " Seconds");
    paramValues.add(sysConfig.getBackSocketSoRcvbuf() + "B");
    paramValues.add(sysConfig.getBackSocketSoSndbuf() + "B");
    paramValues.add(sysConfig.getBackSocketNoDelay() + "");
    paramValues.add(sysConfig.getFrontSocketSoRcvbuf() + "B");
    paramValues.add(sysConfig.getFrontSocketSoSndbuf() + "B");
    paramValues.add(sysConfig.getFrontSocketNoDelay() + "");
    paramValues.add(sysConfig.getBufferUsagePercent() + "%");
    paramValues.add(sysConfig.getUseSqlStat() + "");
    paramValues.add(sysConfig.getClearBigSqLResultSetMapMs() + "ms");
    paramValues.add(sysConfig.getSqlRecordCount() + "");
    paramValues.add(sysConfig.getMaxResultSet() + "B");
    paramValues.add(sysConfig.getShowBinlogStatusTimeout() + "ms");
    paramValues.add(sysConfig.getCheckTableConsistency() + "");
    paramValues.add(sysConfig.getCheckTableConsistencyPeriod() + "ms");
    paramValues.add(sysConfig.getUseGlobleTableCheck() + "");
    paramValues.add(sysConfig.getGlableTableCheckPeriod() + "ms");
    paramValues.add(sysConfig.getDataNodeIdleCheckPeriod() + "ms");
    paramValues.add(sysConfig.getDataNodeHeartbeatPeriod() + "ms");
    paramValues.add(sysConfig.getRecordTxn() + "");
    paramValues.add(sysConfig.getTransactionLogBaseDir());
    paramValues.add(sysConfig.getTransactionLogBaseName());
    paramValues.add(sysConfig.getTransactionRatateSize() + "M");
    paramValues.add(sysConfig.getXaRecoveryLogBaseDir());
    paramValues.add(sysConfig.getXaRecoveryLogBaseName());
    paramValues.add(sysConfig.getXaSessionCheckPeriod() + "ms");
    paramValues.add(sysConfig.getXaLogCleanPeriod() + "ms");
    paramValues.add(sysConfig.isUseJoinStrategy() + "");
    paramValues.add(sysConfig.getNestLoopConnSize() + "");
    paramValues.add(sysConfig.getNestLoopRowsSize() + "");
    paramValues.add(sysConfig.getViewPersistenceConfBaseDir());
    paramValues.add(sysConfig.getViewPersistenceConfBaseName());
    paramValues.add(sysConfig.getComplexExecutor() + "");
    paramValues.add(sysConfig.getOtherMemSize() + "M");
    paramValues.add(sysConfig.getOrderMemSize() + "M");
    paramValues.add(sysConfig.getJoinMemSize() + "M");
    paramValues.add(sysConfig.getCostTimeStat() + "");
    paramValues.add(sysConfig.getMaxCostStatSize() + "");
    paramValues.add(sysConfig.getCostSamplePercent() + "");
    paramValues.add(sysConfig.getUseThreadUsageStat() + "");
    paramValues.add(sysConfig.getUsePerformanceMode() + "");
    for (int i = 0; i < PARAM_NAMES.length; i++) {
        RowDataPacket row = new RowDataPacket(FIELD_COUNT);
        row.add(StringUtil.encode(PARAM_NAMES[i], c.getCharset().getResults()));
        row.add(StringUtil.encode(paramValues.get(i), c.getCharset().getResults()));
        row.add(StringUtil.encode(PARAM_DESCRIPTION[i], 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);
    // write buffer
    c.write(buffer);
}
Also used : SystemConfig(com.actiontech.dble.config.model.SystemConfig) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) ArrayList(java.util.ArrayList) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 64 with EOFPacket

use of com.actiontech.dble.net.mysql.EOFPacket in project dble by actiontech.

the class ShowTableAlgorithm method execute.

public static void execute(ManagerConnection c, String tableInfo) {
    Matcher ma = PATTERN_FOR_TABLE_INFO.matcher(tableInfo);
    if (!ma.matches()) {
        c.writeErrMessage(ErrorCode.ER_UNKNOWN_ERROR, "The Correct Query Format Is:show @@algorithm where schema=? and table =?");
        return;
    }
    String schemaName = ma.group(2);
    String tableName = ma.group(4);
    if (DbleServer.getInstance().getSystemVariables().isLowerCaseTableNames()) {
        schemaName = schemaName.toLowerCase();
        tableName = tableName.toLowerCase();
    }
    SchemaConfig schemaConfig = DbleServer.getInstance().getConfig().getSchemas().get(schemaName);
    TableType tableType;
    TableConfig tableConfig = null;
    if (schemaConfig == null) {
        c.writeErrMessage(ErrorCode.ER_UNKNOWN_ERROR, "the schema [" + schemaName + "] does not exists");
        return;
    } else if (schemaConfig.isNoSharding()) {
        tableType = TableType.BASE;
    } else {
        tableConfig = schemaConfig.getTables().get(tableName);
        if (tableConfig == null) {
            if (schemaConfig.getDataNode() == null) {
                c.writeErrMessage(ErrorCode.ER_UNKNOWN_ERROR, "the table [" + tableName + "] in schema [" + schemaName + "] does not exists");
                return;
            } else {
                tableType = TableType.BASE;
            }
        } else if (tableConfig.isGlobalTable()) {
            tableType = TableType.GLOBAL;
        } else if (tableConfig.getParentTC() != null) {
            tableType = TableType.CHILD;
        } else if (tableConfig.getRule() == null) {
            tableType = TableType.SHARDING_SINGLE;
        } else {
            tableType = TableType.SHARDING;
        }
    }
    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();
    for (RowDataPacket row : getRows(tableConfig, tableType, 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 : SchemaConfig(com.actiontech.dble.config.model.SchemaConfig) Matcher(java.util.regex.Matcher) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) TableConfig(com.actiontech.dble.config.model.TableConfig) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 65 with EOFPacket

use of com.actiontech.dble.net.mysql.EOFPacket in project dble by actiontech.

the class ShowThreadPool method execute.

public static void execute(ManagerConnection 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();
    List<ExecutorService> executors = getExecutors();
    for (ExecutorService exec : executors) {
        if (exec != null) {
            RowDataPacket row = getRow((NameableExecutor) exec, 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);
    // write buffer
    c.write(buffer);
}
Also used : RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) ExecutorService(java.util.concurrent.ExecutorService) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Aggregations

EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)67 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)66 ByteBuffer (java.nio.ByteBuffer)64 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)59 Map (java.util.Map)8 NIOProcessor (com.actiontech.dble.net.NIOProcessor)6 ResultSetHeaderPacket (com.actiontech.dble.net.mysql.ResultSetHeaderPacket)6 UserStat (com.actiontech.dble.statistic.stat.UserStat)6 SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)4 ServerConfig (com.actiontech.dble.config.ServerConfig)3 FrontendConnection (com.actiontech.dble.net.FrontendConnection)3 BackendConnection (com.actiontech.dble.backend.BackendConnection)2 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)2 TableConfig (com.actiontech.dble.config.model.TableConfig)2 UserConfig (com.actiontech.dble.config.model.UserConfig)2 PackageBufINf (com.actiontech.dble.manager.handler.PackageBufINf)2 PreparedOkPacket (com.actiontech.dble.net.mysql.PreparedOkPacket)2 TreeSet (java.util.TreeSet)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 Matcher (java.util.regex.Matcher)2