From ec9794bc3587237e470467d733b511902c1caaba Mon Sep 17 00:00:00 2001 From: chen-czywj Date: Thu, 11 May 2023 14:37:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=9B=86=E7=BE=A4=E6=8E=A2?= =?UTF-8?q?=E6=B5=8B=E4=B8=BB=E8=8A=82=E7=82=B9=E6=89=A7=E8=A1=8Csql?= =?UTF-8?q?=E6=97=B6=E6=B2=A1=E6=9C=89=E5=AD=97=E7=AC=A6=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../clusterhealthy/ClusterHeartBeat.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pgjdbc/src/main/java/org/postgresql/clusterhealthy/ClusterHeartBeat.java b/pgjdbc/src/main/java/org/postgresql/clusterhealthy/ClusterHeartBeat.java index fad5279..4c1f280 100644 --- a/pgjdbc/src/main/java/org/postgresql/clusterhealthy/ClusterHeartBeat.java +++ b/pgjdbc/src/main/java/org/postgresql/clusterhealthy/ClusterHeartBeat.java @@ -52,10 +52,11 @@ public class ClusterHeartBeat { public static final Map> CLUSTER_PROPERTIES = new ConcurrentHashMap<>(); private Log LOGGER = Logger.getLogger(ClusterHeartBeat.class.getName()); private final ConnectionFactoryImpl FACTORY = new ConnectionFactoryImpl(); + private final String clientEncoding = "UTF8"; private volatile boolean detection; - private final Long DEFAULT_INTERVAL = 5000L; + private final Long defaultInterval = 5000L; private final String DEFAULT_TIMEOUT = "30000"; - private volatile AtomicLong periodTime = new AtomicLong(DEFAULT_INTERVAL); + private volatile AtomicLong periodTime = new AtomicLong(defaultInterval); /** @@ -93,7 +94,7 @@ public class ClusterHeartBeat { } public void initPeriodTime() { - periodTime.set(DEFAULT_INTERVAL); + periodTime.set(defaultInterval); } /** @@ -216,22 +217,21 @@ public class ClusterHeartBeat { String user = props.getProperty("user", ""); String database = props.getProperty("PGDBNAME", ""); PGStream pgStream = FACTORY.tryConnect(user, database, props, socketFactory, hostSpec, sslMode); - return new QueryExecutorImpl(pgStream, user, database, + QueryExecutor queryExecutor = new QueryExecutorImpl(pgStream, user, database, 1000, new Properties()); + queryExecutor.setClientEncoding(pgStream.getEncoding() != null + ? pgStream.getEncoding().name() : clientEncoding); + return queryExecutor; } } catch (SQLException e) { String sqlState = e.getSQLState(); if (CONNECTION_REJECTED.getState().equals(sqlState) || "28P01".equals(sqlState)) { - LOGGER.debug("node " + hostSpec + " is active, and connenction authentication fails."); - LOGGER.debug("remove before propSet size :" + propSet.size()); + LOGGER.error("node " + hostSpec + " is active, and connenction authentication fails."); removeProperties(hostSpec, props); - LOGGER.debug("remove after propSet size :" + propSet.size()); } - - LOGGER.debug("acquire QueryExecutor failure " + e.getMessage()); + LOGGER.error("acquire QueryExecutor failure " + e.getMessage()); } catch (IOException e) { - LOGGER.debug("acquire QueryExecutor failure " + e.getMessage()); - LOGGER.debug(e.getCause()); + LOGGER.error(e.getCause()); } throw new SQLException(); } -- Gitee