Skip to content
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

WIP: Demonstration of potential memberlist optimizations. #75

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kv/memberlist/memberlist_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ func (m *KV) mergeValueForKey(key string, incomingValue Mergeable, casVersion ui
m.storeMu.Lock()
defer m.storeMu.Unlock()

curr := m.store[key].Clone()
curr := m.store[key]
// if casVersion is 0, then there was no previous value, so we will just do normal merge, without localCAS flag set.
if casVersion > 0 && curr.version != casVersion {
return nil, 0, errVersionMismatch
Expand Down
38 changes: 37 additions & 1 deletion ring/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ func (d *Desc) mergeWithTime(mergeable memberlist.Mergeable, localCAS bool, now
return nil, nil
}

thisIngesterMap := buildNormalizedIngestersMap(d)
normalizeIngestersMap(d)
thisIngesterMap := d.Ingesters
otherIngesterMap := buildNormalizedIngestersMap(other)

var updated []string
Expand Down Expand Up @@ -303,6 +304,41 @@ func buildNormalizedIngestersMap(inputRing *Desc) map[string]InstanceDesc {
return out
}

// normalizeIngestersMap will do the following:
// - sorts tokens and removes duplicates (only within single ingester)
// - modifies the input ring
func normalizeIngestersMap(inputRing *Desc) {
for n, ing := range inputRing.Ingesters {
// Make sure LEFT ingesters have no tokens
if ing.State == LEFT {
ing.Tokens = nil
}

// Sort tokens, and remove duplicates
if len(ing.Tokens) == 0 {
inputRing.Ingesters[n] = ing
continue
}

if !sort.IsSorted(Tokens(ing.Tokens)) {
sort.Sort(Tokens(ing.Tokens))
}

// tokens are sorted now, we can easily remove duplicates.
prev := ing.Tokens[0]
for ix := 1; ix < len(ing.Tokens); {
if ing.Tokens[ix] == prev {
ing.Tokens = append(ing.Tokens[:ix], ing.Tokens[ix+1:]...)
} else {
prev = ing.Tokens[ix]
ix++
}
}

inputRing.Ingesters[n] = ing
}
}

func conflictingTokensExist(normalizedIngesters map[string]InstanceDesc) bool {
count := 0
for _, ing := range normalizedIngesters {
Expand Down