Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_57962205
redisson
提交
b777fed7
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,发现更多精彩内容 >>
提交
b777fed7
编写于
5月 23, 2019
作者:
N
Nikita Koksharov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improvement - reduced memory consumption by ClusterConnectionManager. #2105
上级
18a6cea3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
44 addition
and
25 deletion
+44
-25
redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java
...n/java/org/redisson/cluster/ClusterConnectionManager.java
+18
-17
redisson/src/main/java/org/redisson/cluster/ClusterPartition.java
.../src/main/java/org/redisson/cluster/ClusterPartition.java
+26
-8
未找到文件。
redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java
浏览文件 @
b777fed7
...
...
@@ -19,6 +19,7 @@ import java.net.InetSocketAddress;
import
java.net.URI
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.BitSet
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.HashMap
;
...
...
@@ -399,7 +400,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
continue
;
}
MasterSlaveEntry
entry
=
getEntry
(
currentPart
.
getSlots
().
iterator
().
next
(
));
MasterSlaveEntry
entry
=
getEntry
(
currentPart
.
slots
().
nextSetBit
(
0
));
// should be invoked first in order to remove stale failedSlaveAddresses
Set
<
URI
>
addedSlaves
=
addRemoveSlaves
(
entry
,
currentPart
,
newPart
);
// Do some slaves have changed state from failed to alive?
...
...
@@ -464,7 +465,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
private
int
slotsAmount
(
Collection
<
ClusterPartition
>
partitions
)
{
int
result
=
0
;
for
(
ClusterPartition
clusterPartition
:
partitions
)
{
result
+=
clusterPartition
.
getSlots
().
size
();
result
+=
clusterPartition
.
getSlots
Amount
();
}
return
result
;
}
...
...
@@ -558,7 +559,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
for
(
Integer
slot
:
lastPartitions
.
keySet
())
{
boolean
found
=
false
;
for
(
ClusterPartition
clusterPartition
:
newPartitions
)
{
if
(
clusterPartition
.
getSlots
().
contains
(
slot
))
{
if
(
clusterPartition
.
hasSlot
(
slot
))
{
found
=
true
;
break
;
}
...
...
@@ -580,34 +581,34 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
}
}
Set
<
Integer
>
addedSlots
=
new
HashSet
<
Integer
>
();
BitSet
addedSlots
=
new
BitSet
();
for
(
ClusterPartition
clusterPartition
:
newPartitions
)
{
for
(
Integer
slot
:
clusterPartition
.
getSlots
())
{
if
(!
lastPartitions
.
containsKey
(
slot
))
{
addedSlots
.
add
(
slot
);
addedSlots
.
set
(
slot
);
}
}
}
if
(!
addedSlots
.
isEmpty
())
{
log
.
info
(
"{} slots found to add"
,
addedSlots
.
size
());
}
for
(
Integer
slot
:
addedSlots
)
{
for
(
Integer
slot
:
(
Iterable
<
Integer
>)
addedSlots
.
stream
()::
iterator
)
{
ClusterPartition
partition
=
find
(
newPartitions
,
slot
);
Set
<
Integer
>
oldSlots
=
new
HashSet
<
Integer
>(
partition
.
getSlots
()
);
oldSlots
.
removeAll
(
addedSlots
);
BitSet
oldSlots
=
partition
.
copySlots
(
);
oldSlots
.
andNot
(
addedSlots
);
if
(
oldSlots
.
isEmpty
())
{
continue
;
}
MasterSlaveEntry
entry
=
getEntry
(
oldSlots
.
iterator
().
next
(
));
MasterSlaveEntry
entry
=
getEntry
(
oldSlots
.
nextSetBit
(
0
));
if
(
entry
!=
null
)
{
addEntry
(
slot
,
entry
);
lastPartitions
.
put
(
slot
,
partition
);
}
}
}
private
void
checkSlotsMigration
(
Collection
<
ClusterPartition
>
newPartitions
)
{
for
(
ClusterPartition
currentPartition
:
getLastPartitions
())
{
for
(
ClusterPartition
newPartition
:
newPartitions
)
{
...
...
@@ -615,13 +616,13 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
continue
;
}
MasterSlaveEntry
entry
=
getEntry
(
currentPartition
.
getSlots
().
iterator
().
next
(
));
Set
<
Integer
>
addedSlots
=
new
HashSet
<
Integer
>(
newPartition
.
getSlots
()
);
addedSlots
.
removeAll
(
currentPartition
.
getS
lots
());
MasterSlaveEntry
entry
=
getEntry
(
currentPartition
.
slots
().
nextSetBit
(
0
));
BitSet
addedSlots
=
newPartition
.
copySlots
(
);
addedSlots
.
andNot
(
currentPartition
.
s
lots
());
currentPartition
.
addSlots
(
addedSlots
);
for
(
Integer
slot
:
addedSlots
)
{
for
(
Integer
slot
:
(
Iterable
<
Integer
>)
addedSlots
.
stream
()::
iterator
)
{
addEntry
(
slot
,
entry
);
lastPartitions
.
put
(
slot
,
currentPartition
);
}
...
...
@@ -629,9 +630,9 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
log
.
info
(
"{} slots added to {}"
,
addedSlots
.
size
(),
currentPartition
.
getMasterAddress
());
}
Set
<
Integer
>
removedSlots
=
new
HashSet
<
Integer
>(
currentPartition
.
getSlots
()
);
removedSlots
.
removeAll
(
newPartition
.
getS
lots
());
for
(
Integer
removeSlot
:
removedSlots
)
{
BitSet
removedSlots
=
currentPartition
.
copySlots
(
);
removedSlots
.
andNot
(
newPartition
.
s
lots
());
for
(
Integer
removeSlot
:
(
Iterable
<
Integer
>)
removedSlots
.
stream
()::
iterator
)
{
if
(
lastPartitions
.
remove
(
removeSlot
,
currentPartition
))
{
removeEntry
(
removeSlot
);
}
...
...
redisson/src/main/java/org/redisson/cluster/ClusterPartition.java
浏览文件 @
b777fed7
...
...
@@ -16,6 +16,7 @@
package
org.redisson.cluster
;
import
java.net.URI
;
import
java.util.BitSet
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.Set
;
...
...
@@ -37,7 +38,7 @@ public class ClusterPartition {
private
final
Set
<
URI
>
slaveAddresses
=
new
HashSet
<
URI
>();
private
final
Set
<
URI
>
failedSlaves
=
new
HashSet
<
URI
>();
private
final
Set
<
Integer
>
slots
=
new
HashSet
<
Integer
>
();
private
final
BitSet
slots
=
new
BitSet
();
private
final
Set
<
ClusterSlotRange
>
slotRanges
=
new
HashSet
<
ClusterSlotRange
>();
private
ClusterPartition
parent
;
...
...
@@ -74,18 +75,18 @@ public class ClusterPartition {
return
masterFail
;
}
public
void
addSlots
(
Set
<
Integer
>
slots
)
{
this
.
slots
.
addAll
(
slots
);
public
void
addSlots
(
BitSet
slots
)
{
this
.
slots
.
or
(
slots
);
}
public
void
removeSlots
(
Set
<
Integer
>
slots
)
{
this
.
slots
.
removeAll
(
slots
);
public
void
removeSlots
(
BitSet
slots
)
{
this
.
slots
.
andNot
(
slots
);
}
public
void
addSlotRanges
(
Set
<
ClusterSlotRange
>
ranges
)
{
for
(
ClusterSlotRange
clusterSlotRange
:
ranges
)
{
for
(
int
i
=
clusterSlotRange
.
getStartSlot
();
i
<
clusterSlotRange
.
getEndSlot
()
+
1
;
i
++)
{
slots
.
add
(
i
);
slots
.
set
(
i
);
}
}
slotRanges
.
addAll
(
ranges
);
...
...
@@ -93,7 +94,7 @@ public class ClusterPartition {
public
void
removeSlotRanges
(
Set
<
ClusterSlotRange
>
ranges
)
{
for
(
ClusterSlotRange
clusterSlotRange
:
ranges
)
{
for
(
int
i
=
clusterSlotRange
.
getStartSlot
();
i
<
clusterSlotRange
.
getEndSlot
()
+
1
;
i
++)
{
slots
.
remove
(
i
);
slots
.
clear
(
i
);
}
}
slotRanges
.
removeAll
(
ranges
);
...
...
@@ -101,9 +102,26 @@ public class ClusterPartition {
public
Set
<
ClusterSlotRange
>
getSlotRanges
()
{
return
slotRanges
;
}
public
Set
<
Integer
>
getSlots
()
{
public
Iterable
<
Integer
>
getSlots
()
{
return
(
Iterable
<
Integer
>)
slots
.
stream
()::
iterator
;
}
public
BitSet
slots
()
{
return
slots
;
}
public
BitSet
copySlots
()
{
return
(
BitSet
)
slots
.
clone
();
}
public
boolean
hasSlot
(
int
slot
)
{
return
slots
.
get
(
slot
);
}
public
int
getSlotsAmount
()
{
return
slots
.
cardinality
();
}
public
URI
getMasterAddress
()
{
return
masterAddress
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录