Search in sources :

Example 1 with ConQueue

use of io.mycat.backend.ConQueue in project Mycat-Server by MyCATApache.

the class PhysicalDatasource method closeByIdleMany.

private void closeByIdleMany(int ildeCloseCount) {
    LOGGER.info("too many ilde cons ,close some for datasouce  " + name);
    List<BackendConnection> readyCloseCons = new ArrayList<BackendConnection>(ildeCloseCount);
    for (ConQueue queue : conMap.getAllConQueue()) {
        readyCloseCons.addAll(queue.getIdleConsToClose(ildeCloseCount));
        if (readyCloseCons.size() >= ildeCloseCount) {
            break;
        }
    }
    for (BackendConnection idleCon : readyCloseCons) {
        if (idleCon.isBorrowed()) {
            LOGGER.warn("find idle con is using " + idleCon);
        }
        idleCon.close("too many idle con");
    }
}
Also used : BackendConnection(io.mycat.backend.BackendConnection) ArrayList(java.util.ArrayList) ConQueue(io.mycat.backend.ConQueue)

Example 2 with ConQueue

use of io.mycat.backend.ConQueue in project Mycat-Server by MyCATApache.

the class PhysicalDatasource method returnCon.

private void returnCon(BackendConnection c) {
    c.setAttachment(null);
    c.setBorrowed(false);
    c.setLastTime(TimeUtil.currentTimeMillis());
    ConQueue queue = this.conMap.getSchemaConQueue(c.getSchema());
    boolean ok = false;
    if (c.isAutocommit()) {
        ok = queue.getAutoCommitCons().offer(c);
    } else {
        ok = queue.getManCommitCons().offer(c);
    }
    if (!ok) {
        LOGGER.warn("can't return to pool ,so close con " + c);
        c.close("can't return to pool ");
    }
}
Also used : ConQueue(io.mycat.backend.ConQueue)

Example 3 with ConQueue

use of io.mycat.backend.ConQueue in project Mycat-Server by MyCATApache.

the class PhysicalDatasource method takeCon.

private BackendConnection takeCon(BackendConnection conn, final ResponseHandler handler, final Object attachment, String schema) {
    conn.setBorrowed(true);
    if (!conn.getSchema().equals(schema)) {
        // need do schema syn in before sql send
        conn.setSchema(schema);
    }
    ConQueue queue = conMap.getSchemaConQueue(schema);
    queue.incExecuteCount();
    conn.setAttachment(attachment);
    // 每次取连接的时候,更新下lasttime,防止在前端连接检查的时候,关闭连接,导致sql执行失败
    conn.setLastTime(System.currentTimeMillis());
    handler.connectionAcquired(conn);
    return conn;
}
Also used : ConQueue(io.mycat.backend.ConQueue)

Example 4 with ConQueue

use of io.mycat.backend.ConQueue in project Mycat-Server by MyCATApache.

the class PhysicalDatasource method heatBeatCheck.

public void heatBeatCheck(long timeout, long conHeartBeatPeriod) {
    //		int ildeCloseCount = hostConfig.getMinCon() * 3;
    int maxConsInOneCheck = 5;
    LinkedList<BackendConnection> heartBeatCons = new LinkedList<BackendConnection>();
    long hearBeatTime = TimeUtil.currentTimeMillis() - conHeartBeatPeriod;
    long hearBeatTime2 = TimeUtil.currentTimeMillis() - 2 * conHeartBeatPeriod;
    for (ConQueue queue : conMap.getAllConQueue()) {
        checkIfNeedHeartBeat(heartBeatCons, queue, queue.getAutoCommitCons(), hearBeatTime, hearBeatTime2);
        if (heartBeatCons.size() < maxConsInOneCheck) {
            checkIfNeedHeartBeat(heartBeatCons, queue, queue.getManCommitCons(), hearBeatTime, hearBeatTime2);
        } else if (heartBeatCons.size() >= maxConsInOneCheck) {
            break;
        }
    }
    if (!heartBeatCons.isEmpty()) {
        for (BackendConnection con : heartBeatCons) {
            conHeartBeatHanler.doHeartBeat(con, hostConfig.getHearbeatSQL());
        }
    }
    // check if there has timeouted heatbeat cons
    conHeartBeatHanler.abandTimeOuttedConns();
    int idleCons = getIdleCount();
    int activeCons = this.getActiveCount();
    int createCount = (hostConfig.getMinCon() - idleCons) / 3;
    // create if idle too little
    if ((createCount > 0) && (idleCons + activeCons < size) && (idleCons < hostConfig.getMinCon())) {
        createByIdleLitte(idleCons, createCount);
    } else if (idleCons > hostConfig.getMinCon()) {
        closeByIdleMany(idleCons - hostConfig.getMinCon());
    } else {
        int activeCount = this.getActiveCount();
        if (activeCount > size) {
            StringBuilder s = new StringBuilder();
            s.append(Alarms.DEFAULT).append("DATASOURCE EXCEED [name=").append(name).append(",active=");
            s.append(activeCount).append(",size=").append(size).append(']');
            LOGGER.warn(s.toString());
        }
    }
}
Also used : BackendConnection(io.mycat.backend.BackendConnection) ConQueue(io.mycat.backend.ConQueue) LinkedList(java.util.LinkedList)

Example 5 with ConQueue

use of io.mycat.backend.ConQueue in project Mycat-Server by MyCATApache.

the class PhysicalDatasource method getIdleCountForSchema.

public int getIdleCountForSchema(String schema) {
    ConQueue queue = conMap.getSchemaConQueue(schema);
    int total = 0;
    total += queue.getAutoCommitCons().size() + queue.getManCommitCons().size();
    return total;
}
Also used : ConQueue(io.mycat.backend.ConQueue)

Aggregations

ConQueue (io.mycat.backend.ConQueue)5 BackendConnection (io.mycat.backend.BackendConnection)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1