mirror of
https://github.com/actiontech/dble.git
synced 2026-01-05 20:30:40 -06:00
[inner-2213] adjust the basis of whether the 'readInstance' judgment (cherry pick from #3681)
This commit is contained in:
@@ -298,10 +298,6 @@ public class ConnectionPool extends PoolBase implements PooledConnectionListener
|
||||
return allConnections.size();
|
||||
}
|
||||
|
||||
public boolean isFromSlave() {
|
||||
return !config.isPrimary();
|
||||
}
|
||||
|
||||
public void close(final PooledConnection conn) {
|
||||
if (remove(conn)) {
|
||||
final int tc = totalConnections.decrementAndGet();
|
||||
|
||||
@@ -173,6 +173,10 @@ public class BackendConnection extends PooledConnection {
|
||||
return getPoolRelated() != null ? getPoolRelated().getConnectionTimeout() : connectionTimeout;
|
||||
}
|
||||
|
||||
public boolean isFromSlaveDB() {
|
||||
return instance.isReadInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BackendConnection[id = " + id + " host = " + host + " port = " + port + " localPort = " + localPort + " mysqlId = " + threadId + " db config = " + instance;
|
||||
|
||||
@@ -106,10 +106,6 @@ public abstract class PooledConnection extends AbstractConnection {
|
||||
this.poolRelated = poolRelated;
|
||||
}
|
||||
|
||||
public boolean isFromSlaveDB() {
|
||||
return poolRelated.isFromSlave();
|
||||
}
|
||||
|
||||
public String getOldSchema() {
|
||||
return oldSchema;
|
||||
}
|
||||
|
||||
@@ -57,11 +57,11 @@ public class HintDbInstanceHandler implements HintHandler {
|
||||
getDbInstances(true).stream().
|
||||
filter(dbInstance -> StringUtil.equals(dbInstance.getConfig().getUrl().trim(), dbInstanceUrl.trim())).
|
||||
collect(Collectors.toSet());
|
||||
Optional<PhysicalDbInstance> slaveInstance = dbInstanceSet.stream().filter(instance -> !instance.getConfig().isPrimary()).findFirst();
|
||||
Optional<PhysicalDbInstance> slaveInstance = dbInstanceSet.stream().filter(instance -> instance.isReadInstance()).findFirst();
|
||||
if (slaveInstance.isPresent()) {
|
||||
return slaveInstance.get();
|
||||
} else {
|
||||
Optional<PhysicalDbInstance> masterInstance = dbInstanceSet.stream().filter(instance -> instance.getConfig().isPrimary()).findFirst();
|
||||
Optional<PhysicalDbInstance> masterInstance = dbInstanceSet.stream().filter(instance -> !instance.isReadInstance()).findFirst();
|
||||
return masterInstance.isPresent() ? masterInstance.get() : null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user