use of com.actiontech.dble.backend.BackendConnection in project dble by actiontech.
the class PhysicalDBPool method initSource.
private boolean initSource(int index, PhysicalDatasource ds) {
int initSize = ds.getConfig().getMinCon();
LOGGER.info("init backend mysql source ,create connections total " + initSize + " for " + ds.getName() + " index :" + index);
CopyOnWriteArrayList<BackendConnection> list = new CopyOnWriteArrayList<>();
GetConnectionHandler getConHandler = new GetConnectionHandler(list, initSize);
for (int i = 0; i < initSize; i++) {
try {
ds.initMinConnection(this.schemas[i % schemas.length], true, getConHandler, null);
} catch (Exception e) {
LOGGER.info(getMessage(index, " init connection error."), e);
}
}
long timeOut = System.currentTimeMillis() + 60 * 1000;
// waiting for finish
while (!getConHandler.finished() && (System.currentTimeMillis() < timeOut)) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
/**
* hardly triggered no error is needed
*/
LOGGER.info("initError", e);
}
}
LOGGER.info("init result :" + getConHandler.getStatusInfo());
return !list.isEmpty();
}
use of com.actiontech.dble.backend.BackendConnection in project dble by actiontech.
the class NIOProcessor method backendCheck.
private void backendCheck() {
long sqlTimeout = DbleServer.getInstance().getConfig().getSystem().getSqlExecuteTimeout() * 1000L;
Iterator<Entry<Long, BackendConnection>> it = backends.entrySet().iterator();
while (it.hasNext()) {
BackendConnection c = it.next().getValue();
// remove empty
if (c == null) {
it.remove();
continue;
}
// Active/IDLE/PREPARED XA backends will not be checked
if (c instanceof MySQLConnection) {
MySQLConnection m = (MySQLConnection) c;
if (m.isClosedOrQuit()) {
it.remove();
continue;
}
if (m.getXaStatus() != null && m.getXaStatus() != TxState.TX_INITIALIZE_STATE) {
continue;
}
}
// close the conn which executeTimeOut
if (!c.isDDL() && c.isBorrowed() && c.getLastTime() < TimeUtil.currentTimeMillis() - sqlTimeout) {
LOGGER.info("found backend connection SQL timeout ,close it " + c);
c.close("sql timeout");
}
// clean closed conn or check time out
if (c.isClosed()) {
it.remove();
} else {
// very important ,for some data maybe not sent
if (c instanceof AbstractConnection) {
checkConSendQueue((AbstractConnection) c);
}
c.idleCheck();
}
}
}
use of com.actiontech.dble.backend.BackendConnection in project dble by actiontech.
the class NonBlockingSession method initiativeTerminate.
/**
* Only used when kill @@connection is Issued
*/
void initiativeTerminate() {
for (BackendConnection node : target.values()) {
node.terminate("client closed ");
}
target.clear();
clearHandlesResources();
}
use of com.actiontech.dble.backend.BackendConnection in project dble by actiontech.
the class NonBlockingSession method closeAndClearResources.
public void closeAndClearResources(String reason) {
// XA MUST BE FINISHED
if (source.isTxStart() && this.getXaState() != null && this.getXaState() != TxState.TX_INITIALIZE_STATE) {
return;
}
for (BackendConnection node : target.values()) {
node.terminate(reason);
}
target.clear();
clearHandlesResources();
}
use of com.actiontech.dble.backend.BackendConnection in project dble by actiontech.
the class NonBlockingSession method releaseConnection.
public void releaseConnection(BackendConnection con) {
Iterator<Entry<RouteResultsetNode, BackendConnection>> iterator = target.entrySet().iterator();
while (iterator.hasNext()) {
BackendConnection theCon = iterator.next().getValue();
if (theCon == con) {
iterator.remove();
con.release();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("realse connection " + con);
}
break;
}
}
}
Aggregations