From 5323816846830ddabe8da5a4ef91f423baef1a4f Mon Sep 17 00:00:00 2001 From: sunzhengfang Date: Tue, 19 Mar 2019 17:23:57 +0800 Subject: [PATCH] #1064 correct active into totalCount in physicalDatasource --- .../backend/datasource/PhysicalDBPool.java | 2 +- .../datasource/PhysicalDatasource.java | 19 +++++-------------- .../dble/manager/response/ShowDataSource.java | 5 +++-- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/actiontech/dble/backend/datasource/PhysicalDBPool.java b/src/main/java/com/actiontech/dble/backend/datasource/PhysicalDBPool.java index 24d4449eb..1cbb32d80 100644 --- a/src/main/java/com/actiontech/dble/backend/datasource/PhysicalDBPool.java +++ b/src/main/java/com/actiontech/dble/backend/datasource/PhysicalDBPool.java @@ -376,7 +376,7 @@ public class PhysicalDBPool { // long timeOut = start + 5000 * 1000L; boolean hasConnectionInPool = false; try { - if (ds.getActiveCount() <= 0) { + if (ds.getTotalConCount() <= 0) { ds.initMinConnection(null, true, getConHandler, null); } else { LOGGER.info("connection with null schema do not create,because testConnection in pool"); diff --git a/src/main/java/com/actiontech/dble/backend/datasource/PhysicalDatasource.java b/src/main/java/com/actiontech/dble/backend/datasource/PhysicalDatasource.java index 04e756ef1..08bf63ec1 100644 --- a/src/main/java/com/actiontech/dble/backend/datasource/PhysicalDatasource.java +++ b/src/main/java/com/actiontech/dble/backend/datasource/PhysicalDatasource.java @@ -184,22 +184,14 @@ public abstract class PhysicalDatasource { //the following is about the idle connection number control int idleCons = getIdleCount(); - int activeCons = this.getActiveCount(); + int totalCount = this.getTotalConCount(); int createCount = (hostConfig.getMinCon() - idleCons) / 3; // create if idle too little - if ((createCount > 0) && (idleCons + activeCons < size)) { + if ((createCount > 0) && totalCount < size) { createByIdleLittle(idleCons, createCount); } else if (idleCons > hostConfig.getMinCon()) { closeByIdleMany(idleCons - hostConfig.getMinCon(), idleCons); - } else { - int activeCount = this.getActiveCount(); - if (activeCount > size) { - String s = "DATASOURCE EXCEED [name=" + name + - ",active=" + activeCount + - ",size=" + size + ']'; - LOGGER.info(s); - } } } @@ -251,15 +243,14 @@ public abstract class PhysicalDatasource { final String[] schemas = dbPool.getSchemas(); for (int i = 0; i < createCount; i++) { - if (this.getActiveCount() + this.getIdleCount() >= size) { - break; - } NewConnectionRespHandler simpleHandler = new NewConnectionRespHandler(); try { if (this.createNewCount()) { // creat new connection this.createNewConnection(simpleHandler, null, schemas[i % schemas.length]); simpleHandler.getBackConn().release(); + } else { + break; } if (ToResolveContainer.CREATE_CONN_FAIL.contains(this.getHostConfig().getName() + "-" + this.getConfig().getHostName())) { Map labels = AlertUtil.genSingleLabel("data_host", this.getHostConfig().getName() + "-" + this.getConfig().getHostName()); @@ -277,7 +268,7 @@ public abstract class PhysicalDatasource { } } - public int getActiveCount() { + public int getTotalConCount() { return this.connectionCount.get(); } diff --git a/src/main/java/com/actiontech/dble/manager/response/ShowDataSource.java b/src/main/java/com/actiontech/dble/manager/response/ShowDataSource.java index 0cd228386..2db86d765 100644 --- a/src/main/java/com/actiontech/dble/manager/response/ShowDataSource.java +++ b/src/main/java/com/actiontech/dble/manager/response/ShowDataSource.java @@ -144,12 +144,13 @@ public final class ShowDataSource { String charset) { RowDataPacket row = new RowDataPacket(FIELD_COUNT); //row.add(StringUtil.encode(dataNode, charset)); + int idleCount = ds.getIdleCount(); row.add(StringUtil.encode(ds.getName(), charset)); row.add(StringUtil.encode(ds.getConfig().getIp(), charset)); row.add(IntegerUtil.toBytes(ds.getConfig().getPort())); row.add(StringUtil.encode(ds.isReadNode() ? "R" : "W", charset)); - row.add(IntegerUtil.toBytes(ds.getActiveCount())); - row.add(IntegerUtil.toBytes(ds.getIdleCount())); + row.add(IntegerUtil.toBytes(ds.getTotalConCount() - idleCount)); + row.add(IntegerUtil.toBytes(idleCount)); row.add(IntegerUtil.toBytes(ds.getSize())); row.add(LongUtil.toBytes(ds.getExecuteCount())); row.add(LongUtil.toBytes(ds.getReadCount()));