-
Notifications
You must be signed in to change notification settings - Fork 955
Check for duplicate nodeids when loading nodes.conf #2852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: unstable
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -607,6 +607,7 @@ int clusterLoadConfig(char *filename) { | |
| struct stat sb; | ||
| char *line; | ||
| int maxline, j; | ||
| dict *tmp_cluster_nodes; | ||
|
|
||
| if (fp == NULL) { | ||
| if (errno == ENOENT) { | ||
|
|
@@ -637,6 +638,7 @@ int clusterLoadConfig(char *filename) { | |
| * To simplify we allocate 1024+CLUSTER_SLOTS*128 bytes per line. */ | ||
| maxline = 1024 + CLUSTER_SLOTS * 128; | ||
| line = zmalloc(maxline); | ||
| tmp_cluster_nodes = dictCreate(&clusterNodesDictType); | ||
| while (fgets(line, maxline, fp) != NULL) { | ||
| int argc, aux_argc; | ||
| sds *argv, *aux_argv; | ||
|
|
@@ -684,6 +686,19 @@ int clusterLoadConfig(char *filename) { | |
| if (!n) { | ||
| n = createClusterNode(argv[0], 0); | ||
| clusterAddNode(n); | ||
| dictAdd(tmp_cluster_nodes, sdsnewlen(argv[0], sdslen(argv[0])), NULL); | ||
| } else { | ||
| /* Check if the node (nodeid) has already been loaded. The nodeid is used to | ||
| * identify every node across the entire cluster, we do not expect to find | ||
| * duplicate nodeids in nodes.conf. */ | ||
| sds nodename = sdsnewlen(argv[0], sdslen(argv[0])); | ||
| dictEntry *de = dictFind(tmp_cluster_nodes, nodename); | ||
| sdsfree(nodename); | ||
| if (de != NULL) { | ||
| serverLog(LL_WARNING, "Duplicate nodeid detected: %s", argv[0]); | ||
| sdsfreesplitres(argv, argc); | ||
| goto fmterr; | ||
| } | ||
| } | ||
| /* Format for the node address and auxiliary argument information: | ||
| * ip:port[@cport][,hostname][,aux=val]*] */ | ||
|
|
@@ -940,6 +955,7 @@ int clusterLoadConfig(char *filename) { | |
|
|
||
| zfree(line); | ||
| fclose(fp); | ||
| if (tmp_cluster_nodes) dictRelease(tmp_cluster_nodes); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, you are right. I will remove it later.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a |
||
|
|
||
| serverLog(LL_NOTICE, "Node configuration loaded, I'm %.40s", myself->name); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to create a new sds for dictfind?