Skip to content

fix(controller): parse master_host on the first colon only - #618

Open
arpitjain099 wants to merge 2 commits into
dragonflydb:mainfrom
arpitjain099:fix/ipv6-master-host-parse
Open

arpitjain099 wants to merge 2 commits into
dragonflydb:mainfrom
arpitjain099:fix/ipv6-master-host-parse

Conversation

@arpitjain099

@arpitjain099 arpitjain099 commented Nov 5, 2026 •

Copy link
Copy Markdown

checkReplicaRole reads master_host from INFO replication with strings.Split(line, ":")[1], so an IPv6 address such as fd00:10:244::5 comes back as fd00. The comparison against the expected master can then never match, and the outcome rests on the IPv4-only master-ip label (#313) and on the annotation. REPLICAOF is re-issued once, on the first reconcile where the annotation is missing or stale, and the annotation replicaOf writes masks the mismatch after that.

parseInfoToMap in the same file splits on the first colon, and isReplicaStable and getMasterCandidate already use it, so checkReplicaRole now goes through it too. The tests are table driven, with the IPv6 case, an IPv4 control, and two negatives.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
Comment on lines 207 to 211
if masterIp != redisMasterIp {
if masterIp != pod.Labels[resources.MasterIpLabelKey] && masterIp != pod.Annotations[resources.MasterIpAnnotationKey] {
return false, nil
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arpitjain099 do we now need resources.MasterIpLabelKey and resources.MasterIpAnnotationKey?

@arpitjain099 arpitjain099 Nov 25, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tjovicic The annotation is still needed: a label value cannot contain colons, so it is the only one that can hold an IPv6 master. The label is already IPv4-only and marked for removal. Please say if you would like it dropped here or separately.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arpitjain099 the change look ok to me. Could you improve the tests a bit:

  • make them table driven and add a negative test
  • reuse fakeTakeoverServer instead of creating fakeInfoServer
  • is this line in the PR description A replica with no annotation then has REPLICAOF re-issued on every reconcile. correct? Is it on every reconcile or the first reconcile?

Except that i think we can merge it. @Abhra303 wdyt?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tjovicic Both done: the table now has two negatives, a replica pointed at another master and a pod reporting the master role, and it uses fakeTakeoverServer, which I extended to answer INFO.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tjovicic You were right to question that line. It is the first reconcile, not every one: replicaOf writes the masterIP annotation, which matches on the next pass and hides the mismatch. I have corrected the description, so please take another look.

Comment on lines +194 to +195
// Split on the first colon only: an IPv6 master_host contains colons of its
// own, and splitting on every one of them keeps just the first group.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe move this comment to parseInfoToMap func

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tjovicic Moved, it is the doc comment on parseInfoToMap now, which is where the split actually happens.

Comment on lines 207 to 211
if masterIp != redisMasterIp {
if masterIp != pod.Labels[resources.MasterIpLabelKey] && masterIp != pod.Annotations[resources.MasterIpAnnotationKey] {
return false, nil
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arpitjain099 the change look ok to me. Could you improve the tests a bit:

  • make them table driven and add a negative test
  • reuse fakeTakeoverServer instead of creating fakeInfoServer
  • is this line in the PR description A replica with no annotation then has REPLICAOF re-issued on every reconcile. correct? Is it on every reconcile or the first reconcile?

Except that i think we can merge it. @Abhra303 wdyt?

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants