Skip to content

Commit

Permalink
camellia-redis-proxy optimize error reply in sharding-pubsub (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
caojiajun committed Nov 8, 2023
1 parent 1de2b53 commit 5bf23bf
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class ErrorReply implements Reply {
public static final ErrorReply REDIS_CLUSTER_ASK_ERROR = new ErrorReply("ERR redis cluster ASK error");
public static final ErrorReply SYNTAX_ERROR = new ErrorReply(Utils.syntaxError);
public static final ErrorReply TOO_MANY_CLIENTS = new ErrorReply("ERR max number of clients reached");
public static final ErrorReply COMMAND_MOVED_BY_UPSTREAM_SERVER = new ErrorReply("ERR command moved by upstream server");

private static final char MARKER = Marker.ErrorReply.getMarker();
private final String error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
import com.netease.nim.camellia.redis.proxy.monitor.ProxyMonitorCollector;
import com.netease.nim.camellia.redis.proxy.monitor.UpstreamFailMonitor;
import com.netease.nim.camellia.redis.proxy.netty.ChannelInfo;
import com.netease.nim.camellia.redis.proxy.reply.*;
import com.netease.nim.camellia.redis.proxy.upstream.connection.RedisConnection;
import com.netease.nim.camellia.redis.proxy.plugin.converter.KeyConverter;
import com.netease.nim.camellia.redis.proxy.enums.RedisCommand;
import com.netease.nim.camellia.redis.proxy.reply.BulkReply;
import com.netease.nim.camellia.redis.proxy.reply.IntegerReply;
import com.netease.nim.camellia.redis.proxy.reply.MultiBulkReply;
import com.netease.nim.camellia.redis.proxy.reply.Reply;
import com.netease.nim.camellia.redis.proxy.util.ErrorLogCollector;
import com.netease.nim.camellia.redis.proxy.util.Utils;

Expand All @@ -40,6 +37,12 @@ private static void sendByBindClient(Resource resource, RedisConnection connecti
CompletableFuture<Reply> completableFuture = new CompletableFuture<>();
futures.add(completableFuture);
completableFuture.thenAccept(reply -> {
if (reply instanceof ErrorReply) {
String error = ((ErrorReply) reply).getError();
if (error != null && error.startsWith("MOVED")) {
reply = ErrorReply.COMMAND_MOVED_BY_UPSTREAM_SERVER;
}
}
//parse reply must before send reply to connection
SubscribeCount subscribeCount = tryGetSubscribeChannelCount(reply);
future.complete(reply);
Expand All @@ -66,6 +69,12 @@ private static void sendByBindClient(Resource resource, RedisConnection connecti
if (connection.queueSize() < 8 && connection.isValid()) {
sendByBindClient(resource, connection, taskQueue, null, null, false, redisCommand);
}
if (reply instanceof ErrorReply) {
String error = ((ErrorReply) reply).getError();
if (error != null && error.startsWith("MOVED")) {
reply = ErrorReply.COMMAND_MOVED_BY_UPSTREAM_SERVER;
}
}
//parse reply must before send reply to connection
SubscribeCount subscribeCount = tryGetSubscribeChannelCount(reply);
taskQueue.reply(redisCommand, reply, false);
Expand Down
12 changes: 12 additions & 0 deletions update-en.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
[中文版](update-zh.md)


# 1.2.20(2023/11/xx)
### add
* none

### update
* camellia-redis-proxy optimize error reply in sharding-pubsub

### fix
* none


# 1.2.19(2023/11/07)
### add
* provide camellia-redis-proxy-nacos-bootstrap, so Operations Engineer can use nacos to manager camellia-redis-proxy cluster without java development
Expand Down
12 changes: 12 additions & 0 deletions update-zh.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
[ENGLISH](update-en.md)


# 1.2.20(2023/11/xx)
### 新增
*

### 更新
* camellia-redis-proxy,当使用shard-pubsub命令时,后端可能返回`MOVED XXX`错误信息,proxy应该重写error信息,避免上游的ip被暴露给客户端

### fix
*


# 1.2.19(2023/11/07)
### 新增
* 新增camellia-redis-proxy-nacos-bootstrap,从而方便运维人员不需要进行java开发即可使用nacos管理proxy集群
Expand Down

0 comments on commit 5bf23bf

Please sign in to comment.