Skip to content

Commit

Permalink
inner-2407: need init connection pool when switch with config rwsplit…
Browse files Browse the repository at this point in the history
…Mode=0
  • Loading branch information
dcy10000 committed Sep 13, 2024
1 parent 17b7a8a commit 3766c94
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -423,6 +423,10 @@ public void startEvictor() {
}
}

public boolean isInActive() {
return instance.isDisabled() || isClosed.get();
}

/**
* Stops the evictor.
*/
Expand Down

0 comments on commit 3766c94

Please sign in to comment.