Search in sources :

Example 1 with UnknownDataNodeException

use of com.alibaba.cobar.exception.UnknownDataNodeException in project cobar by alibaba.

the class SingleNodeExecutor method newExecute.

/**
     * 新数据通道的执行
     */
private void newExecute(final RouteResultsetNode rrn, final BlockingSession ss, final int flag) {
    final ServerConnection sc = ss.getSource();
    // 检查数据节点是否存在
    CobarConfig conf = CobarServer.getInstance().getConfig();
    final MySQLDataNode dn = conf.getDataNodes().get(rrn.getName());
    if (dn == null) {
        LOGGER.warn(new StringBuilder().append(sc).append(rrn).toString(), new UnknownDataNodeException());
        handleError(ErrorCode.ER_BAD_DB_ERROR, "Unknown dataNode '" + rrn.getName() + "'", ss);
        return;
    }
    // 提交执行任务
    sc.getProcessor().getExecutor().execute(new Runnable() {

        @Override
        public void run() {
            // 取得数据通道
            int i = rrn.getReplicaIndex();
            Channel c = null;
            try {
                c = (i == DEFAULT_REPLICA_INDEX) ? dn.getChannel() : dn.getChannel(i);
            } catch (Exception e) {
                LOGGER.warn(new StringBuilder().append(sc).append(rrn).toString(), e);
                String msg = e.getMessage();
                handleError(ErrorCode.ER_BAD_DB_ERROR, msg == null ? e.getClass().getSimpleName() : msg, ss);
                return;
            }
            // 检查连接是否已关闭。
            if (sc.isClosed()) {
                c.release();
                endRunning();
                return;
            }
            // 绑定数据通道
            c.setRunning(true);
            Channel old = ss.getTarget().put(rrn, c);
            if (old != null && old != c) {
                old.close();
            }
            // 执行
            execute0(rrn, ss, c, flag);
        }
    });
}
Also used : MySQLDataNode(com.alibaba.cobar.mysql.MySQLDataNode) UnknownDataNodeException(com.alibaba.cobar.exception.UnknownDataNodeException) MySQLChannel(com.alibaba.cobar.mysql.bio.MySQLChannel) Channel(com.alibaba.cobar.mysql.bio.Channel) ServerConnection(com.alibaba.cobar.server.ServerConnection) CobarConfig(com.alibaba.cobar.CobarConfig) UnknownDataNodeException(com.alibaba.cobar.exception.UnknownDataNodeException) IOException(java.io.IOException)

Example 2 with UnknownDataNodeException

use of com.alibaba.cobar.exception.UnknownDataNodeException in project cobar by alibaba.

the class MultiNodeExecutor method newExecute.

/**
     * 新通道的执行
     */
private void newExecute(final RouteResultsetNode rrn, final boolean autocommit, final BlockingSession ss, final int flag) {
    final ServerConnection sc = ss.getSource();
    // 检查数据节点是否存在
    CobarConfig conf = CobarServer.getInstance().getConfig();
    final MySQLDataNode dn = conf.getDataNodes().get(rrn.getName());
    if (dn == null) {
        handleFailure(ss, rrn, new SimpleErrInfo(new UnknownDataNodeException("Unknown dataNode '" + rrn.getName() + "'"), ErrorCode.ER_BAD_DB_ERROR, sc, rrn));
        return;
    }
    // 提交执行任务
    sc.getProcessor().getExecutor().execute(new Runnable() {

        @Override
        public void run() {
            // 取得数据通道
            int i = rrn.getReplicaIndex();
            Channel c = null;
            try {
                c = (i == DEFAULT_REPLICA_INDEX) ? dn.getChannel() : dn.getChannel(i);
            } catch (final Exception e) {
                handleFailure(ss, rrn, new SimpleErrInfo(e, ErrorCode.ER_BAD_DB_ERROR, sc, rrn));
                return;
            }
            c.setRunning(true);
            Channel old = ss.getTarget().put(rrn, c);
            if (old != null && c != old) {
                old.close();
            }
            // 执行
            execute0(rrn, c, autocommit, ss, flag);
        }
    });
}
Also used : MySQLDataNode(com.alibaba.cobar.mysql.MySQLDataNode) UnknownDataNodeException(com.alibaba.cobar.exception.UnknownDataNodeException) MySQLChannel(com.alibaba.cobar.mysql.bio.MySQLChannel) Channel(com.alibaba.cobar.mysql.bio.Channel) ServerConnection(com.alibaba.cobar.server.ServerConnection) CobarConfig(com.alibaba.cobar.CobarConfig) UnknownDataNodeException(com.alibaba.cobar.exception.UnknownDataNodeException) IOException(java.io.IOException)

Aggregations

CobarConfig (com.alibaba.cobar.CobarConfig)2 UnknownDataNodeException (com.alibaba.cobar.exception.UnknownDataNodeException)2 MySQLDataNode (com.alibaba.cobar.mysql.MySQLDataNode)2 Channel (com.alibaba.cobar.mysql.bio.Channel)2 MySQLChannel (com.alibaba.cobar.mysql.bio.MySQLChannel)2 ServerConnection (com.alibaba.cobar.server.ServerConnection)2 IOException (java.io.IOException)2