diff --git a/src/main/java/com/actiontech/dble/backend/datasource/PhysicalDbGroup.java b/src/main/java/com/actiontech/dble/backend/datasource/PhysicalDbGroup.java index 926616acc8..b82c721ea4 100644 --- a/src/main/java/com/actiontech/dble/backend/datasource/PhysicalDbGroup.java +++ b/src/main/java/com/actiontech/dble/backend/datasource/PhysicalDbGroup.java @@ -451,6 +451,10 @@ public String switchMaster(String writeHost, boolean syncWriteConf) { } newWriteHost.setReadInstance(false); writeDbInstance = newWriteHost; + if (!newWriteHost.isDisabled() && rwSplitMode == RW_SPLIT_OFF && newWriteHost.isConnectionPoolInActive()) { + //need init connection pool + newWriteHost.start("ha switch", false); + } return this.getClusterHaJson(); } catch (Exception e) { LOGGER.warn("switchMaster Exception ", e); diff --git a/src/main/java/com/actiontech/dble/backend/datasource/PhysicalDbInstance.java b/src/main/java/com/actiontech/dble/backend/datasource/PhysicalDbInstance.java index 4e398e12fe..76a60f7135 100644 --- a/src/main/java/com/actiontech/dble/backend/datasource/PhysicalDbInstance.java +++ b/src/main/java/com/actiontech/dble/backend/datasource/PhysicalDbInstance.java @@ -472,6 +472,10 @@ public final int getTotalConnections() { return connectionPool.size() - connectionPool.getCount(PooledConnection.STATE_REMOVED); } + public boolean isConnectionPoolInActive() { + return connectionPool.isInActive(); + } + @Override public boolean equals(Object other) { if (this == other) { diff --git a/src/main/java/com/actiontech/dble/backend/pool/ConnectionPool.java b/src/main/java/com/actiontech/dble/backend/pool/ConnectionPool.java index 2a34e2a440..4e143f6bcf 100644 --- a/src/main/java/com/actiontech/dble/backend/pool/ConnectionPool.java +++ b/src/main/java/com/actiontech/dble/backend/pool/ConnectionPool.java @@ -143,7 +143,7 @@ public PooledConnection borrow(final String schema, long timeout, final TimeUnit } private void newPooledEntry(final String schema, final int waiting, boolean createByWaiter) { - if (instance.isDisabled() || isClosed.get()) { + if (isInActive()) { return; } @@ -423,6 +423,10 @@ public void startEvictor() { } } + public boolean isInActive() { + return instance.isDisabled() || isClosed.get(); + } + /** * Stops the evictor. */