-
Notifications
You must be signed in to change notification settings - Fork 75
Ring: reduce allocations and copies when Merge()-ing states. #77
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
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 |
|---|---|---|
|
|
@@ -173,6 +173,8 @@ func (i *InstanceDesc) IsReady(now time.Time, heartbeatTimeout time.Duration) er | |
| // (see resolveConflicts). | ||
| // | ||
| // This method is part of memberlist.Mergeable interface, and is only used by gossiping ring. | ||
| // | ||
| // Note: This method modifies d and mergeable to reduce allocations and copies. | ||
| func (d *Desc) Merge(mergeable memberlist.Mergeable, localCAS bool) (memberlist.Mergeable, error) { | ||
| return d.mergeWithTime(mergeable, localCAS, time.Now()) | ||
| } | ||
|
|
@@ -192,8 +194,11 @@ func (d *Desc) mergeWithTime(mergeable memberlist.Mergeable, localCAS bool, now | |
| return nil, nil | ||
| } | ||
|
|
||
| thisIngesterMap := buildNormalizedIngestersMap(d) | ||
| otherIngesterMap := buildNormalizedIngestersMap(other) | ||
| normalizeIngestersMap(d) | ||
|
Contributor
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. Shouldn't the current value which we retrieved from
Contributor
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. It is a decent win, I have numbers somewhere. It's just a bit hard to reason about so it's on the riskier end of the optimization spectrum.
Contributor
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. |
||
| normalizeIngestersMap(other) | ||
stevesg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| thisIngesterMap := d.Ingesters | ||
| otherIngesterMap := other.Ingesters | ||
|
|
||
| var updated []string | ||
|
|
||
|
|
@@ -261,22 +266,18 @@ func (d *Desc) MergeContent() []string { | |
| return result | ||
| } | ||
|
|
||
| // buildNormalizedIngestersMap will do the following: | ||
| // normalizeIngestersMap will do the following: | ||
| // - sorts tokens and removes duplicates (only within single ingester) | ||
| // - it doesn't modify input ring | ||
| func buildNormalizedIngestersMap(inputRing *Desc) map[string]InstanceDesc { | ||
| out := map[string]InstanceDesc{} | ||
|
|
||
| // - modifies the input ring | ||
| func normalizeIngestersMap(inputRing *Desc) { | ||
| // Make sure LEFT ingesters have no tokens | ||
| for n, ing := range inputRing.Ingesters { | ||
| if ing.State == LEFT { | ||
| ing.Tokens = nil | ||
| inputRing.Ingesters[n] = ing | ||
| } | ||
| out[n] = ing | ||
| } | ||
|
|
||
| // Sort tokens, and remove duplicates | ||
| for name, ing := range out { | ||
| // Sort tokens, and remove duplicates | ||
| if len(ing.Tokens) == 0 { | ||
| continue | ||
| } | ||
|
|
@@ -297,10 +298,8 @@ func buildNormalizedIngestersMap(inputRing *Desc) map[string]InstanceDesc { | |
| } | ||
|
|
||
| // write updated value back to map | ||
| out[name] = ing | ||
| inputRing.Ingesters[n] = ing | ||
| } | ||
|
|
||
| return out | ||
| } | ||
|
|
||
| func conflictingTokensExist(normalizedIngesters map[string]InstanceDesc) bool { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.