Search in sources :

Example 6 with MySQLClientSession

use of io.mycat.proxy.session.MySQLClientSession in project Mycat2 by MyCATApache.

the class MySQLTaskUtil method proxyBackend.

public static void proxyBackend(MycatSession session, String sql) {
    MySQLClientSession mySQLSession = session.getMySQLSession();
    MySQLPacketExchanger.MySQLProxyNIOHandler.INSTANCE.proxyBackend(mySQLSession, DEFAULT_BACKEND_SESSION_REQUEST_FAILED_CALLBACK, ResponseType.QUERY, session, MySQLPacketUtil.generateComQueryPacket(sql));
}
Also used : MySQLClientSession(io.mycat.proxy.session.MySQLClientSession)

Example 7 with MySQLClientSession

use of io.mycat.proxy.session.MySQLClientSession in project Mycat2 by MyCATApache.

the class MySQLDatasourcePool method waitForIdleSession.

private Future<MySQLClientSession> waitForIdleSession(boolean wait) {
    PromiseInternal<MySQLClientSession> promise = VertxUtil.newPromise();
    ReactorEnvThread reactorEnvThread;
    if (Thread.currentThread() instanceof ReactorEnvThread) {
        reactorEnvThread = (ReactorEnvThread) Thread.currentThread();
    } else {
        reactorEnvThread = this.server.getReactorManager().getRandomReactor();
    }
    if (wait) {
        ScheduleUtil.getTimer().schedule(() -> {
            nextStageForSession(promise, reactorEnvThread);
        }, datasourceConfig.getMaxConnectTimeout() / datasourceConfig.getMaxRetryCount(), TimeUnit.MILLISECONDS);
    } else {
        nextStageForSession(promise, reactorEnvThread);
    }
    return promise;
}
Also used : ReactorEnvThread(io.mycat.proxy.reactor.ReactorEnvThread) MySQLClientSession(io.mycat.proxy.session.MySQLClientSession)

Example 8 with MySQLClientSession

use of io.mycat.proxy.session.MySQLClientSession in project Mycat2 by MyCATApache.

the class MycatMonitorCallback method getSession.

static Session getSession() {
    SessionThread thread = getThread();
    Session curSession = thread.getCurSession();
    if (curSession instanceof MycatSession) {
        return curSession;
    } else if (curSession instanceof MySQLClientSession) {
        MycatSession mycatSession = ((MySQLClientSession) curSession).getMycat();
        if (mycatSession == null) {
            return curSession;
        } else {
            return mycatSession;
        }
    } else {
        throw new MycatException("unknown session");
    }
}
Also used : MycatSession(io.mycat.proxy.session.MycatSession) SessionThread(io.mycat.proxy.reactor.SessionThread) MycatException(io.mycat.MycatException) MySQLClientSession(io.mycat.proxy.session.MySQLClientSession) MycatSession(io.mycat.proxy.session.MycatSession) Session(io.mycat.proxy.session.Session) MySQLClientSession(io.mycat.proxy.session.MySQLClientSession)

Example 9 with MySQLClientSession

use of io.mycat.proxy.session.MySQLClientSession in project Mycat2 by MyCATApache.

the class LoaddataContext method proxy.

public void proxy(MycatSession mycat, String replicaName, String defaultDataBaseName) {
    int packetId = 2;
    MySQLPacketSplitter splitter = new PacketSplitterImpl();
    splitter.init(context.size());
    while (splitter.nextPacketInPacketSplitter()) {
        packetId++;
    }
    byte[] bytes = MySQLPacketUtil.generateMySQLPacket(2, context.toByteArray());
    context = null;
    splitter = null;
    int emptyPacketId = packetId;
    mycat.setHandleContentOfFilename(false);
    MySQLClientSession mySQLSession = mycat.getMySQLSession();
    mySQLSession.setMonopolizeType(MySQLSessionMonopolizeType.NONE);
    RequestHandler.INSTANCE.request(mycat.getMySQLSession(), bytes, new RequestCallback() {

        @Override
        public void onFinishedSend(MySQLClientSession session, Object sender, Object attr) {
            byte[] emptyPacket = MySQLPacketUtil.generateMySQLPacket(emptyPacketId, new byte[] {});
        // @todo
        // MySQLProxyNIOHandler
        // .INSTANCE.proxyBackend(mycat, emptyPacket, targetName,defaultDataBaseName, null, ResponseType.QUERY,
        // MySQLProxyNIOHandler.INSTANCE, DEFAULT_BACKEND_SESSION_REQUEST_FAILED_CALLBACK
        // );
        }

        @Override
        public void onFinishedSendException(Exception e, Object sender, Object attr) {
            mycat.setMySQLSession(null);
            mycat.setLastMessage(e.toString());
            mycat.writeErrorEndPacketBySyncInProcessError();
        }
    });
}
Also used : MySQLPacketSplitter(io.mycat.beans.mysql.packet.MySQLPacketSplitter) RequestCallback(io.mycat.proxy.callback.RequestCallback) PacketSplitterImpl(io.mycat.beans.mysql.packet.PacketSplitterImpl) MySQLClientSession(io.mycat.proxy.session.MySQLClientSession)

Aggregations

MySQLClientSession (io.mycat.proxy.session.MySQLClientSession)9 MycatException (io.mycat.MycatException)3 ReactorEnvThread (io.mycat.proxy.reactor.ReactorEnvThread)3 Future (io.vertx.core.Future)3 ErrorPacketImpl (io.mycat.beans.mysql.packet.ErrorPacketImpl)2 CompositeFuture (io.vertx.core.CompositeFuture)2 PromiseInternal (io.vertx.core.impl.future.PromiseInternal)2 ScheduledFuture (java.util.concurrent.ScheduledFuture)2 TextResultSetTransforCollector (io.mycat.api.collector.TextResultSetTransforCollector)1 MySQLDatasource (io.mycat.beans.MySQLDatasource)1 MySQLCommandType (io.mycat.beans.mysql.MySQLCommandType)1 MySQLErrorCode (io.mycat.beans.mysql.MySQLErrorCode)1 MySQLPacketSplitter (io.mycat.beans.mysql.packet.MySQLPacketSplitter)1 PacketSplitterImpl (io.mycat.beans.mysql.packet.PacketSplitterImpl)1 RequestCallback (io.mycat.proxy.callback.RequestCallback)1 ResultSetCallBack (io.mycat.proxy.callback.ResultSetCallBack)1 BackendConCreateHandler (io.mycat.proxy.handler.backend.BackendConCreateHandler)1 TextResultSetHandler (io.mycat.proxy.handler.backend.TextResultSetHandler)1 NIOJob (io.mycat.proxy.reactor.NIOJob)1 SessionThread (io.mycat.proxy.reactor.SessionThread)1