mirror of
https://github.com/actiontech/dble.git
synced 2026-01-05 20:30:40 -06:00
Merge pull request #3681 from actiontech/inner-2213/22.01
[inner-2213] adjust the basis of whether the 'readInstance' judgment
This commit is contained in:
@@ -302,10 +302,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();
|
||||
|
||||
@@ -229,6 +229,10 @@ public class BackendConnection extends PooledConnection {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public boolean isFromSlaveDB() {
|
||||
return instance.isReadInstance();
|
||||
}
|
||||
|
||||
public long getConnectionTimeout() {
|
||||
return getPoolRelated() != null ? getPoolRelated().getConnectionTimeout() : connectionTimeout;
|
||||
}
|
||||
|
||||
@@ -111,10 +111,6 @@ public abstract class PooledConnection extends AbstractConnection {
|
||||
this.poolRelated = poolRelated;
|
||||
}
|
||||
|
||||
public boolean isFromSlaveDB() {
|
||||
return poolRelated.isFromSlave();
|
||||
}
|
||||
|
||||
public String getOldSchema() {
|
||||
return oldSchema;
|
||||
}
|
||||
|
||||
@@ -56,11 +56,11 @@ public final class HintDbInstanceHandler {
|
||||
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.orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user