Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_57962205
redisson
提交
ab71d42c
R
redisson
项目概览
weixin_57962205
/
redisson
与 Fork 源项目一致
从无法访问的项目Fork
通知
10
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redisson
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
ab71d42c
编写于
8月 26, 2021
作者:
N
Nikita Koksharov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Feature - resolve hostnames used in Redis Cluster topology #3771
上级
f707f10a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
85 addition
and
41 deletion
+85
-41
redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java
...n/java/org/redisson/cluster/ClusterConnectionManager.java
+59
-37
redisson/src/main/java/org/redisson/connection/MasterSlaveConnectionManager.java
...org/redisson/connection/MasterSlaveConnectionManager.java
+26
-4
未找到文件。
redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java
浏览文件 @
ab71d42c
...
...
@@ -16,7 +16,6 @@
package
org.redisson.cluster
;
import
io.netty.resolver.AddressResolver
;
import
io.netty.util.NetUtil
;
import
io.netty.util.concurrent.Future
;
import
io.netty.util.concurrent.FutureListener
;
import
io.netty.util.concurrent.ScheduledFuture
;
...
...
@@ -32,8 +31,12 @@ import org.redisson.config.ClusterServersConfig;
import
org.redisson.config.Config
;
import
org.redisson.config.MasterSlaveServersConfig
;
import
org.redisson.config.ReadMode
;
import
org.redisson.connection.
*
;
import
org.redisson.connection.
CRC16
;
import
org.redisson.connection.ClientConnectionsEntry.FreezeReason
;
import
org.redisson.connection.MasterSlaveConnectionManager
;
import
org.redisson.connection.MasterSlaveEntry
;
import
org.redisson.connection.SingleEntry
;
import
org.redisson.misc.AsyncCountDownLatch
;
import
org.redisson.misc.RPromise
;
import
org.redisson.misc.RedisURI
;
import
org.redisson.misc.RedissonPromise
;
...
...
@@ -94,7 +97,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
try
{
RedisConnection
connection
=
connectionFuture
.
syncUninterruptibly
().
getNow
();
if
(
cfg
.
getNodeAddresses
().
size
()
==
1
&&
NetUtil
.
createByteArrayFromIpAddressString
(
addr
.
getHost
())
==
null
)
{
if
(
cfg
.
getNodeAddresses
().
size
()
==
1
&&
!
addr
.
isIP
()
)
{
configEndpointHostName
=
addr
.
getHost
();
}
...
...
@@ -113,7 +116,8 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
lastClusterNode
=
addr
;
Collection
<
ClusterPartition
>
partitions
=
parsePartitions
(
nodes
);
RFuture
<
Collection
<
ClusterPartition
>>
partitionsFuture
=
parsePartitions
(
nodes
);
Collection
<
ClusterPartition
>
partitions
=
partitionsFuture
.
syncUninterruptibly
().
getNow
();
List
<
RFuture
<
Void
>>
masterFutures
=
new
ArrayList
<>();
for
(
ClusterPartition
partition
:
partitions
)
{
if
(
partition
.
isMasterFail
())
{
...
...
@@ -466,14 +470,16 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
log
.
debug
(
"cluster nodes state got from {}:\n{}"
,
connection
.
getRedisClient
().
getAddr
(),
nodesValue
);
}
Collection
<
ClusterPartition
>
newPartitions
=
parsePartitions
(
nodes
);
RFuture
<
Void
>
masterFuture
=
checkMasterNodesChange
(
cfg
,
newPartitions
);
checkSlaveNodesChange
(
newPartitions
);
masterFuture
.
onComplete
((
res
,
ex
)
->
{
checkSlotsMigration
(
newPartitions
);
checkSlotsChange
(
newPartitions
);
getShutdownLatch
().
release
();
scheduleClusterChangeCheck
(
cfg
);
RFuture
<
Collection
<
ClusterPartition
>>
newPartitionsFuture
=
parsePartitions
(
nodes
);
newPartitionsFuture
.
onComplete
((
newPartitions
,
ex
)
->
{
RFuture
<
Void
>
masterFuture
=
checkMasterNodesChange
(
cfg
,
newPartitions
);
checkSlaveNodesChange
(
newPartitions
);
masterFuture
.
onComplete
((
res
,
exc
)
->
{
checkSlotsMigration
(
newPartitions
);
checkSlotsChange
(
newPartitions
);
getShutdownLatch
().
release
();
scheduleClusterChangeCheck
(
cfg
);
});
});
});
}
...
...
@@ -764,12 +770,15 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
return
natMapper
.
map
(
address
);
}
private
Collection
<
ClusterPartition
>
parsePartitions
(
List
<
ClusterNodeInfo
>
nodes
)
{
private
RFuture
<
Collection
<
ClusterPartition
>
>
parsePartitions
(
List
<
ClusterNodeInfo
>
nodes
)
{
Map
<
String
,
ClusterPartition
>
partitions
=
new
HashMap
<>();
AsyncCountDownLatch
latch
=
new
AsyncCountDownLatch
();
int
counter
=
0
;
for
(
ClusterNodeInfo
clusterNodeInfo
:
nodes
)
{
if
(
clusterNodeInfo
.
containsFlag
(
Flag
.
NOADDR
)
||
clusterNodeInfo
.
containsFlag
(
Flag
.
HANDSHAKE
)
||
clusterNodeInfo
.
getAddress
()
==
null
)
{
||
clusterNodeInfo
.
getAddress
()
==
null
||
(
clusterNodeInfo
.
getSlotRanges
().
isEmpty
()
&&
clusterNodeInfo
.
containsFlag
(
Flag
.
MASTER
)))
{
// skip it
continue
;
}
...
...
@@ -786,32 +795,45 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
continue
;
}
RedisURI
address
=
applyNatMap
(
clusterNodeInfo
.
getAddress
());
if
(
clusterNodeInfo
.
containsFlag
(
Flag
.
SLAVE
))
{
ClusterPartition
masterPartition
=
partitions
.
computeIfAbsent
(
masterId
,
k
->
new
ClusterPartition
(
masterId
));
ClusterPartition
slavePartition
=
partitions
.
computeIfAbsent
(
clusterNodeInfo
.
getNodeId
(),
k
->
new
ClusterPartition
(
clusterNodeInfo
.
getNodeId
()));
slavePartition
.
setType
(
Type
.
SLAVE
);
slavePartition
.
setParent
(
masterPartition
);
masterPartition
.
addSlaveAddress
(
address
);
if
(
clusterNodeInfo
.
containsFlag
(
Flag
.
FAIL
))
{
masterPartition
.
addFailedSlaveAddress
(
address
);
RFuture
<
RedisURI
>
ipFuture
=
resolveIP
(
clusterNodeInfo
.
getAddress
());
counter
++;
ipFuture
.
onComplete
((
addr
,
e
)
->
{
if
(
e
!=
null
)
{
latch
.
countDown
();
return
;
}
}
else
if
(
clusterNodeInfo
.
containsFlag
(
Flag
.
MASTER
))
{
ClusterPartition
masterPartition
=
partitions
.
computeIfAbsent
(
masterId
,
k
->
new
ClusterPartition
(
masterId
));
masterPartition
.
addSlotRanges
(
clusterNodeInfo
.
getSlotRanges
());
masterPartition
.
setMasterAddress
(
address
);
masterPartition
.
setType
(
Type
.
MASTER
);
if
(
clusterNodeInfo
.
containsFlag
(
Flag
.
FAIL
))
{
masterPartition
.
setMasterFail
(
true
);
RedisURI
address
=
applyNatMap
(
addr
);
if
(
clusterNodeInfo
.
containsFlag
(
Flag
.
SLAVE
))
{
ClusterPartition
masterPartition
=
partitions
.
computeIfAbsent
(
masterId
,
k
->
new
ClusterPartition
(
masterId
));
ClusterPartition
slavePartition
=
partitions
.
computeIfAbsent
(
clusterNodeInfo
.
getNodeId
(),
k
->
new
ClusterPartition
(
clusterNodeInfo
.
getNodeId
()));
slavePartition
.
setType
(
Type
.
SLAVE
);
slavePartition
.
setParent
(
masterPartition
);
masterPartition
.
addSlaveAddress
(
address
);
if
(
clusterNodeInfo
.
containsFlag
(
Flag
.
FAIL
))
{
masterPartition
.
addFailedSlaveAddress
(
address
);
}
}
else
if
(
clusterNodeInfo
.
containsFlag
(
Flag
.
MASTER
))
{
ClusterPartition
masterPartition
=
partitions
.
computeIfAbsent
(
masterId
,
k
->
new
ClusterPartition
(
masterId
));
masterPartition
.
addSlotRanges
(
clusterNodeInfo
.
getSlotRanges
());
masterPartition
.
setMasterAddress
(
address
);
masterPartition
.
setType
(
Type
.
MASTER
);
if
(
clusterNodeInfo
.
containsFlag
(
Flag
.
FAIL
))
{
masterPartition
.
setMasterFail
(
true
);
}
}
}
latch
.
countDown
();
});
}
addCascadeSlaves
(
partitions
);
return
partitions
.
values
();
RPromise
<
Collection
<
ClusterPartition
>>
result
=
new
RedissonPromise
<>();
latch
.
latch
(()
->
{
addCascadeSlaves
(
partitions
);
result
.
trySuccess
(
partitions
.
values
());
},
counter
);
return
result
;
}
private
void
addCascadeSlaves
(
Map
<
String
,
ClusterPartition
>
partitions
)
{
...
...
redisson/src/main/java/org/redisson/connection/MasterSlaveConnectionManager.java
浏览文件 @
ab71d42c
...
...
@@ -26,16 +26,14 @@ import io.netty.channel.nio.NioEventLoopGroup;
import
io.netty.channel.socket.SocketChannel
;
import
io.netty.channel.socket.nio.NioDatagramChannel
;
import
io.netty.channel.socket.nio.NioSocketChannel
;
import
io.netty.resolver.AddressResolver
;
import
io.netty.resolver.AddressResolverGroup
;
import
io.netty.resolver.DefaultAddressResolverGroup
;
import
io.netty.resolver.dns.DnsServerAddressStreamProviders
;
import
io.netty.util.Timer
;
import
io.netty.util.TimerTask
;
import
io.netty.util.*
;
import
io.netty.util.concurrent.DefaultThreadFactory
;
import
io.netty.util.concurrent.Future
;
import
io.netty.util.concurrent.ImmediateEventExecutor
;
import
io.netty.util.concurrent.Promise
;
import
io.netty.util.concurrent.*
;
import
io.netty.util.internal.PlatformDependent
;
import
org.redisson.ElementsSubscribeService
;
import
org.redisson.Version
;
...
...
@@ -691,4 +689,28 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
public
RedisURI
applyNatMap
(
RedisURI
address
)
{
return
address
;
}
protected
RFuture
<
RedisURI
>
resolveIP
(
RedisURI
address
)
{
if
(
address
.
isIP
())
{
return
RedissonPromise
.
newSucceededFuture
(
address
);
}
RPromise
<
RedisURI
>
result
=
new
RedissonPromise
<>();
AddressResolver
<
InetSocketAddress
>
resolver
=
resolverGroup
.
getResolver
(
getGroup
().
next
());
InetSocketAddress
addr
=
InetSocketAddress
.
createUnresolved
(
address
.
getHost
(),
address
.
getPort
());
Future
<
InetSocketAddress
>
future
=
resolver
.
resolve
(
addr
);
future
.
addListener
((
FutureListener
<
InetSocketAddress
>)
f
->
{
if
(!
f
.
isSuccess
())
{
log
.
error
(
"Unable to resolve "
+
address
,
f
.
cause
());
result
.
tryFailure
(
f
.
cause
());
return
;
}
InetSocketAddress
s
=
f
.
getNow
();
RedisURI
uri
=
new
RedisURI
(
address
.
getScheme
()
+
"://"
+
s
.
getAddress
().
getHostAddress
()
+
":"
+
address
.
getPort
());
result
.
trySuccess
(
uri
);
});
return
result
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录