From d5a13aafe82320773fb77305265a6613a50a0202 Mon Sep 17 00:00:00 2001 From: Zed Date: Thu, 22 Oct 2020 11:41:43 +0800 Subject: [PATCH 1/5] =?UTF-8?q?DEC-15495=20redis=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=9B=BF=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../third/redis/clients/jedis/Protocol.java | 84 ++++++++++++++----- 1 file changed, 64 insertions(+), 20 deletions(-) diff --git a/fine-jedis/src/main/java/com/fr/third/redis/clients/jedis/Protocol.java b/fine-jedis/src/main/java/com/fr/third/redis/clients/jedis/Protocol.java index e9dc5c1a4..347961433 100644 --- a/fine-jedis/src/main/java/com/fr/third/redis/clients/jedis/Protocol.java +++ b/fine-jedis/src/main/java/com/fr/third/redis/clients/jedis/Protocol.java @@ -1,10 +1,5 @@ package com.fr.third.redis.clients.jedis; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - import com.fr.third.redis.clients.jedis.commands.ProtocolCommand; import com.fr.third.redis.clients.jedis.exceptions.JedisAskDataException; import com.fr.third.redis.clients.jedis.exceptions.JedisBusyException; @@ -17,6 +12,13 @@ import com.fr.third.redis.clients.jedis.util.RedisInputStream; import com.fr.third.redis.clients.jedis.util.RedisOutputStream; import com.fr.third.redis.clients.jedis.util.SafeEncoder; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + public final class Protocol { private static final String ASK_RESPONSE = "ASK"; @@ -79,13 +81,44 @@ public final class Protocol { public static final byte[] POSITIVE_INFINITY_BYTES = "+inf".getBytes(); public static final byte[] NEGATIVE_INFINITY_BYTES = "-inf".getBytes(); + public static Map commandMapping = new HashMap(); + + public static volatile int commandMappingSize = 0; + + public static synchronized void initCommandMapping(Map mapping) { + + commandMapping.clear(); + for (Map.Entry entry : mapping.entrySet()) { + ProtocolCommand defaultCommand = Command.fromName(entry.getKey()); + if (defaultCommand != null) { + commandMapping.put(defaultCommand, new ProtocolCommand() { + @Override + public byte[] getRaw() { + return SafeEncoder.encode(entry.getValue()); + } + }); + } + } + + commandMappingSize = commandMapping.size(); + } + private Protocol() { // this prevent the class from instantiation } public static void sendCommand(final RedisOutputStream os, final ProtocolCommand command, final byte[]... args) { - sendCommand(os, command.getRaw(), args); + ProtocolCommand realCommand = getRealCommand(command); + sendCommand(os, realCommand.getRaw(), args); + } + + private static ProtocolCommand getRealCommand(ProtocolCommand command) { + if (commandMappingSize > 0 && commandMapping.containsKey(command)) { + return commandMapping.get(command); + } + + return command; } private static void sendCommand(final RedisOutputStream os, final byte[] command, @@ -242,20 +275,20 @@ public final class Protocol { } public static enum Command implements ProtocolCommand { - PING, SET, GET, QUIT, EXISTS, DEL, UNLINK, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, - DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, - DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, - HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, - RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, - SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, - ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, - SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, PUBSUB, ZCOUNT, ZRANGEBYSCORE, - ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, ZLEXCOUNT, - ZRANGEBYLEX, ZREVRANGEBYLEX, ZREMRANGEBYLEX, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, - INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, - SETBIT, GETBIT, BITPOS, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG, OBJECT, BITCOUNT, BITOP, - SENTINEL, DUMP, RESTORE, PEXPIRE, PEXPIREAT, PTTL, INCRBYFLOAT, PSETEX, CLIENT, TIME, MIGRATE, HINCRBYFLOAT, - SCAN, HSCAN, SSCAN, ZSCAN, WAIT, CLUSTER, ASKING, PFADD, PFCOUNT, PFMERGE, READONLY, GEOADD, GEODIST, + PING, SET, GET, QUIT, EXISTS, DEL, UNLINK, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, + DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, + DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, + HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, + RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, + SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, + ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, + SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, PUBSUB, ZCOUNT, ZRANGEBYSCORE, + ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, ZLEXCOUNT, + ZRANGEBYLEX, ZREVRANGEBYLEX, ZREMRANGEBYLEX, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, + INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, + SETBIT, GETBIT, BITPOS, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG, OBJECT, BITCOUNT, BITOP, + SENTINEL, DUMP, RESTORE, PEXPIRE, PEXPIREAT, PTTL, INCRBYFLOAT, PSETEX, CLIENT, TIME, MIGRATE, HINCRBYFLOAT, + SCAN, HSCAN, SSCAN, ZSCAN, WAIT, CLUSTER, ASKING, PFADD, PFCOUNT, PFMERGE, READONLY, GEOADD, GEODIST, GEOHASH, GEOPOS, GEORADIUS, GEORADIUSBYMEMBER, MODULE, BITFIELD, HSTRLEN, TOUCH, SWAPDB; private final byte[] raw; @@ -268,6 +301,17 @@ public final class Protocol { public byte[] getRaw() { return raw; } + + public static ProtocolCommand fromName(String commandName) { + Command[] commands = values(); + for (Command command : commands) { + if (command.name().equals(commandName)) { + return command; + } + } + + return null; + } } public static enum Keyword { From c21d6f29e6ebcee8cff3316f46f7c678e734753a Mon Sep 17 00:00:00 2001 From: Zed Date: Fri, 23 Oct 2020 09:28:54 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=97=A0jira=E4=BB=BB=E5=8A=A1=EF=BC=8Cfix?= =?UTF-8?q?:=20=E6=89=93=E5=8C=85=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/fr/third/redis/clients/jedis/Protocol.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fine-jedis/src/main/java/com/fr/third/redis/clients/jedis/Protocol.java b/fine-jedis/src/main/java/com/fr/third/redis/clients/jedis/Protocol.java index 347961433..31036953f 100644 --- a/fine-jedis/src/main/java/com/fr/third/redis/clients/jedis/Protocol.java +++ b/fine-jedis/src/main/java/com/fr/third/redis/clients/jedis/Protocol.java @@ -85,10 +85,10 @@ public final class Protocol { public static volatile int commandMappingSize = 0; - public static synchronized void initCommandMapping(Map mapping) { + public static synchronized void initCommandMapping(final Map mapping) { commandMapping.clear(); - for (Map.Entry entry : mapping.entrySet()) { + for (final Map.Entry entry : mapping.entrySet()) { ProtocolCommand defaultCommand = Command.fromName(entry.getKey()); if (defaultCommand != null) { commandMapping.put(defaultCommand, new ProtocolCommand() { From b491fbc111d65d5090f26500f3d90f3aa8fe9181 Mon Sep 17 00:00:00 2001 From: "Roger.Chen" Date: Tue, 27 Oct 2020 16:29:11 +0800 Subject: [PATCH 3/5] =?UTF-8?q?BI-74885=20fix:=20clickhouse=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=BF=9E=E6=8E=A5=E5=87=BA=E9=94=99=E6=97=B6=E4=B8=80?= =?UTF-8?q?=E7=9B=B4=E5=B0=9D=E8=AF=95=E8=BF=9E=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/third/alibaba/druid/pool/DruidDataSource.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/fine-druid/src/main/java/com/fr/third/alibaba/druid/pool/DruidDataSource.java b/fine-druid/src/main/java/com/fr/third/alibaba/druid/pool/DruidDataSource.java index 13c9ecdd6..873ad3818 100644 --- a/fine-druid/src/main/java/com/fr/third/alibaba/druid/pool/DruidDataSource.java +++ b/fine-druid/src/main/java/com/fr/third/alibaba/druid/pool/DruidDataSource.java @@ -2193,10 +2193,6 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat DruidDataSource.this.doSomethingBeforeCreationThreadBreak(); break; } - } catch (RuntimeException e) { - LOG.error("create connection error", e); - setFailContinuous(true); - continue; } catch (Error e) { LOG.error("create connection error", e); setFailContinuous(true); From 013ec71c298296e9d6a312068d897424780cd835 Mon Sep 17 00:00:00 2001 From: "Roger.Chen" Date: Tue, 27 Oct 2020 16:50:34 +0800 Subject: [PATCH 4/5] =?UTF-8?q?BI-74885=20fix:=20clickhouse=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=BF=9E=E6=8E=A5=E5=87=BA=E9=94=99=E6=97=B6=E4=B8=80?= =?UTF-8?q?=E7=9B=B4=E5=B0=9D=E8=AF=95=E8=BF=9E=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/third/alibaba/druid/pool/DruidDataSource.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fine-druid/src/main/java/com/fr/third/alibaba/druid/pool/DruidDataSource.java b/fine-druid/src/main/java/com/fr/third/alibaba/druid/pool/DruidDataSource.java index 873ad3818..31e47f25d 100644 --- a/fine-druid/src/main/java/com/fr/third/alibaba/druid/pool/DruidDataSource.java +++ b/fine-druid/src/main/java/com/fr/third/alibaba/druid/pool/DruidDataSource.java @@ -2193,6 +2193,11 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat DruidDataSource.this.doSomethingBeforeCreationThreadBreak(); break; } + } catch (Exception e) { + LOG.error("create connection error", e); + setFailContinuous(true); + DruidDataSource.this.doSomethingBeforeCreationThreadBreak(); + break; } catch (Error e) { LOG.error("create connection error", e); setFailContinuous(true); From 24d0d82701eb183460fd48092b1c504471dcfb97 Mon Sep 17 00:00:00 2001 From: "Roger.Chen" Date: Wed, 28 Oct 2020 09:33:41 +0800 Subject: [PATCH 5/5] =?UTF-8?q?BI-74885=20fix:=20clickhouse=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=BF=9E=E6=8E=A5=E5=87=BA=E9=94=99=E6=97=B6=E4=B8=80?= =?UTF-8?q?=E7=9B=B4=E5=B0=9D=E8=AF=95=E8=BF=9E=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alibaba/druid/pool/DruidDataSource.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/fine-druid/src/main/java/com/fr/third/alibaba/druid/pool/DruidDataSource.java b/fine-druid/src/main/java/com/fr/third/alibaba/druid/pool/DruidDataSource.java index 31e47f25d..4cba25d96 100644 --- a/fine-druid/src/main/java/com/fr/third/alibaba/druid/pool/DruidDataSource.java +++ b/fine-druid/src/main/java/com/fr/third/alibaba/druid/pool/DruidDataSource.java @@ -2164,10 +2164,13 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat try { connection = createPhysicalConnection(); setFailContinuous(false); - } catch (SQLException e) { - LOG.error("create connection error, url: " + jdbcUrl + ", errorCode " + e.getErrorCode() - + ", state " + e.getSQLState(), e); - + } catch (SQLException | RuntimeException e) { + if (e instanceof SQLException) { + LOG.error("create connection error, url: " + jdbcUrl + ", errorCode " + ((SQLException)e).getErrorCode() + + ", state " + ((SQLException)e).getSQLState(), e); + } else { + LOG.error("create connection error", e); + } errorCount++; if (errorCount > connectionErrorRetryAttempts && timeBetweenConnectErrorMillis > 0) { // fail over retry attempts @@ -2193,11 +2196,6 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat DruidDataSource.this.doSomethingBeforeCreationThreadBreak(); break; } - } catch (Exception e) { - LOG.error("create connection error", e); - setFailContinuous(true); - DruidDataSource.this.doSomethingBeforeCreationThreadBreak(); - break; } catch (Error e) { LOG.error("create connection error", e); setFailContinuous(true);