Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
a006fcb8
Commit
a006fcb8
authored
Mar 24, 2014
by
Salvatore Sanfilippo
Browse files
Merge pull request #1628 from mattsta/fix-trib-create
Cluster: Fix trib create when masters==replicas
parents
896e15f3
df4bdbf6
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/redis-trib.rb
View file @
a006fcb8
...
@@ -554,14 +554,28 @@ class RedisTrib
...
@@ -554,14 +554,28 @@ class RedisTrib
# We try to split the replicas among all the IPs with spare nodes
# We try to split the replicas among all the IPs with spare nodes
# trying to avoid the host where the master is running, if possible.
# trying to avoid the host where the master is running, if possible.
#
#
# Note that we loop two times, the first with spare_loop set to false,
# Note we loop two times. The first loop assigns the requested
# the second with the var set to true. The second loop changes the
# number of replicas to each master. The second loop assigns any
# while condition so to assign remaining slaves.
# remaining instances as extra replicas to masters. Some masters
[
false
,
true
].
each
{
|
spare_loop
|
# may end up with more than their requested number of replicas, but
# all nodes will be used.
assignment_verbose
=
false
[
:requested
,
:unused
].
each
{
|
assign
|
masters
.
each
{
|
m
|
masters
.
each
{
|
m
|
i
=
0
assigned_replicas
=
0
while
(
!
spare_loop
&&
i
<
@replicas
)
||
\
while
assigned_replicas
<
@replicas
(
spare_loop
&&
nodes_count
>
0
)
break
if
nodes_count
==
0
if
assignment_verbose
if
assign
==
:requested
puts
"Requesting total of
#{
@replicas
}
replicas "
\
"(
#{
assigned_replicas
}
replicas assigned "
\
"so far with
#{
nodes_count
}
total remaining)."
elsif
assign
==
:unused
puts
"Assigning extra instance to replication "
\
"role too (
#{
nodes_count
}
remaining)."
end
end
ips
.
each
{
|
ip
,
nodes_list
|
ips
.
each
{
|
ip
,
nodes_list
|
next
if
nodes_list
.
length
==
0
next
if
nodes_list
.
length
==
0
# Skip instances with the same IP as the master if we
# Skip instances with the same IP as the master if we
...
@@ -570,7 +584,7 @@ class RedisTrib
...
@@ -570,7 +584,7 @@ class RedisTrib
slave
=
nodes_list
.
shift
slave
=
nodes_list
.
shift
slave
.
set_as_replica
(
m
.
info
[
:name
])
slave
.
set_as_replica
(
m
.
info
[
:name
])
nodes_count
-=
1
nodes_count
-=
1
i
+=
1
assigned_replicas
+=
1
puts
"Adding replica
#{
slave
}
to
#{
m
}
"
puts
"Adding replica
#{
slave
}
to
#{
m
}
"
}
}
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment