-
Notifications
You must be signed in to change notification settings - Fork 2.3k
topology_watcher: Allow tablets to reuse old tablet addresses. #5244
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -688,6 +688,17 @@ func (hc *HealthCheckImpl) deleteConn(tablet *topodatapb.Tablet) { | |
| if !ok { | ||
| return | ||
| } | ||
| // Make sure the key still corresponds to the tablet we want to delete. | ||
| // If it doesn't match, we should do nothing. The tablet we were asked to | ||
| // delete is already gone, and some other tablet is using the key | ||
| // (host:port) that the original tablet used to use, which is fine. | ||
| if !topoproto.TabletAliasEqual(tablet.Alias, th.latestTabletStats.Tablet.Alias) { | ||
| return | ||
| } | ||
| hc.deleteConnLocked(key, th) | ||
| } | ||
|
|
||
| func (hc *HealthCheckImpl) deleteConnLocked(key string, th *tabletHealth) { | ||
| th.latestTabletStats.Up = false | ||
| th.cancelFunc() | ||
| delete(hc.addrToHealth, key) | ||
|
|
@@ -733,10 +744,18 @@ func (hc *HealthCheckImpl) AddTablet(tablet *topodatapb.Tablet, name string) { | |
| hc.mu.Unlock() | ||
| return | ||
| } | ||
| if _, ok := hc.addrToHealth[key]; ok { | ||
| hc.mu.Unlock() | ||
| log.Warningf("adding duplicate tablet %v for %v: %+v", name, tablet.Alias.Cell, tablet) | ||
| return | ||
| if th, ok := hc.addrToHealth[key]; ok { | ||
| // Something already exists at this key. | ||
| // If it's the same tablet, something is wrong. | ||
| if topoproto.TabletAliasEqual(th.latestTabletStats.Tablet.Alias, tablet.Alias) { | ||
| hc.mu.Unlock() | ||
| log.Warningf("refusing to add duplicate tablet %v for %v: %+v", name, tablet.Alias.Cell, tablet) | ||
| return | ||
| } | ||
| // If it's a different tablet, then we trust this new tablet that claims | ||
| // it has taken over the host:port that the old tablet used to be on. | ||
| // Remove the old tablet to clear the way. | ||
| hc.deleteConnLocked(key, th) | ||
| } | ||
| hc.addrToHealth[key] = &tabletHealth{ | ||
| cancelFunc: cancelFunc, | ||
|
|
@@ -752,15 +771,13 @@ func (hc *HealthCheckImpl) AddTablet(tablet *topodatapb.Tablet, name string) { | |
| // RemoveTablet removes the tablet, and stops the health check. | ||
| // It does not block. | ||
| func (hc *HealthCheckImpl) RemoveTablet(tablet *topodatapb.Tablet) { | ||
| go hc.deleteConn(tablet) | ||
| hc.deleteConn(tablet) | ||
| } | ||
|
|
||
| // ReplaceTablet removes the old tablet and adds the new tablet. | ||
| func (hc *HealthCheckImpl) ReplaceTablet(old, new *topodatapb.Tablet, name string) { | ||
| go func() { | ||
| hc.deleteConn(old) | ||
| hc.AddTablet(new, name) | ||
| }() | ||
| hc.deleteConn(old) | ||
| hc.AddTablet(new, name) | ||
|
Collaborator
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. Nice yeah this should hopefully eliminate a huge source of threading issues |
||
| } | ||
|
|
||
| // WaitForInitialStatsUpdates waits until all tablets added via AddTablet() call | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This should eventually become an acceptable state, which will allow us to "update if needed" kind of calls. But let the warning remain for now. It will allow us to find out if this really happens in the wild.
The other future improvement on this will be to add a timestamp that tracks when a tablet acquired the address to declare the true winner. Similar to how we're solving the mastership story.