Browse Source

Merge pull request #1248 in CORE/base-third from release/10.0 to final/10.0

* commit '528211bb685f11b30ba1e4346ab8c1635e91bd6b':
  BI-74885 fix: clickhouse数据连接出错时一直尝试连接
  BI-74885 fix: clickhouse数据连接出错时一直尝试连接
  BI-74885 fix: clickhouse数据连接出错时一直尝试连接
  无jira任务,fix: 打包失败
  DEC-15495 redis命令支持替换
final/10.0
superman 4 years ago
parent
commit
85bf59343a
  1. 15
      fine-druid/src/main/java/com/fr/third/alibaba/druid/pool/DruidDataSource.java
  2. 56
      fine-jedis/src/main/java/com/fr/third/redis/clients/jedis/Protocol.java

15
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,10 +2196,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);

56
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<ProtocolCommand, ProtocolCommand> commandMapping = new HashMap<ProtocolCommand, ProtocolCommand>();
public static volatile int commandMappingSize = 0;
public static synchronized void initCommandMapping(final Map<String, String> mapping) {
commandMapping.clear();
for (final Map.Entry<String, String> 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,
@ -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 {

Loading…
Cancel
Save