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
a517c893
Commit
a517c893
authored
Feb 25, 2013
by
antirez
Browse files
Cluster: verifyClusterConfigWithData() implemented.
parent
9947b0d9
Changes
1
Show whitespace changes
Inline
Side-by-side
src/cluster.c
View file @
a517c893
...
...
@@ -1299,6 +1299,43 @@ void clusterUpdateState(void) {
* about desynchronizations between the data we have in memory and the
* cluster configuration. */
int
verifyClusterConfigWithData
(
void
)
{
int
j
;
int
update_config
=
0
;
/* Make sure we only have keys in DB0. */
for
(
j
=
1
;
j
<
server
.
dbnum
;
j
++
)
{
if
(
dictSize
(
server
.
db
[
j
].
dict
))
return
REDIS_ERR
;
}
/* Check that all the slots we see populated memory have a corresponding
* entry in the cluster table. Otherwise fix the table. */
for
(
j
=
0
;
j
<
REDIS_CLUSTER_SLOTS
;
j
++
)
{
if
(
!
countKeysInSlot
(
j
))
continue
;
/* No keys in this slot. */
/* Check if we are assigned to this slot or if we are importing it.
* In both cases check the next slot as the configuration makes
* sense. */
if
(
server
.
cluster
->
slots
[
j
]
==
server
.
cluster
->
myself
||
server
.
cluster
->
importing_slots_from
[
j
]
!=
NULL
)
continue
;
/* If we are here data and cluster config don't agree, and we have
* slot 'j' populated even if we are not importing it, nor we are
* assigned to this slot. Fix this condition. */
update_config
++
;
/* Case A: slot is unassigned. Take responsability for it. */
if
(
server
.
cluster
->
slots
[
j
]
==
NULL
)
{
redisLog
(
REDIS_WARNING
,
"I've keys about slot %d that is "
"unassigned. Taking responsability "
"for it."
,
j
);
clusterAddSlot
(
server
.
cluster
->
myself
,
j
);
}
else
{
redisLog
(
REDIS_WARNING
,
"I've keys about slot %d that is "
"already assigned to a different node. "
"Setting it in importing state."
,
j
);
server
.
cluster
->
importing_slots_from
[
j
]
=
server
.
cluster
->
slots
[
j
];
}
}
if
(
update_config
)
clusterSaveConfigOrDie
();
return
REDIS_OK
;
}
...
...
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