-
Notifications
You must be signed in to change notification settings - Fork 840
limits: distributor user subrings #1947
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 1 commit
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 |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ type ReadRing interface { | |
| GetAll() (ReplicationSet, error) | ||
| ReplicationFactor() int | ||
| IngesterCount() int | ||
| Subring(key uint32, n int) (ReadRing, error) | ||
| } | ||
|
|
||
| // Operation can be Read or Write | ||
|
|
@@ -377,3 +378,66 @@ func (r *Ring) Collect(ch chan<- prometheus.Metric) { | |
| r.name, | ||
| ) | ||
| } | ||
|
|
||
| // Subring returns a ring of n ingesters from the given ring | ||
| // Subrings are meant only for ingestor lookup and should have their data externalized. | ||
| func (r *Ring) Subring(key uint32, n int) (ReadRing, error) { | ||
|
||
| r.mtx.RLock() | ||
| defer r.mtx.RUnlock() | ||
| if r.ringDesc == nil || len(r.ringTokens) == 0 || n <= 0 { | ||
| return nil, ErrEmptyRing | ||
| } | ||
|
|
||
| if n > len(r.ringDesc.Ingesters) { | ||
thorfour marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return nil, fmt.Errorf("subring too large") | ||
| } | ||
|
|
||
| var ( | ||
| ingesters = make(map[string]IngesterDesc, n) | ||
| distinctHosts = map[string]struct{}{} | ||
| start = r.search(key) | ||
| iterations = 0 | ||
| ) | ||
| for i := start; len(distinctHosts) < n && iterations < len(r.ringTokens); i++ { | ||
| iterations++ | ||
| // Wrap i around in the ring. | ||
| i %= len(r.ringTokens) | ||
|
|
||
| // We want n *distinct* ingesters. | ||
| token := r.ringTokens[i] | ||
| if _, ok := distinctHosts[token.Ingester]; ok { | ||
| continue | ||
| } | ||
| distinctHosts[token.Ingester] = struct{}{} | ||
| ingester := r.ringDesc.Ingesters[token.Ingester] | ||
|
|
||
| ingesters[token.Ingester] = ingester | ||
| } | ||
|
|
||
| if n > len(ingesters) { | ||
| return nil, fmt.Errorf("too few ingesters found") | ||
| } | ||
|
|
||
| numTokens := 0 | ||
| for _, ing := range ingesters { | ||
| numTokens += len(ing.Tokens) | ||
| } | ||
|
|
||
| sub := &Ring{ | ||
| name: "subring", | ||
| cfg: r.cfg, | ||
| ringDesc: &Desc{ | ||
| Ingesters: ingesters, | ||
| }, | ||
| ringTokens: make([]TokenDesc, 0, numTokens), | ||
| } | ||
|
|
||
| // add tokens for the ingesters in the subring, they should already be sorted, so no need to re-sort | ||
| for _, t := range r.ringTokens { | ||
| if _, ok := ingesters[t.Ingester]; ok { | ||
| sub.ringTokens = append(sub.ringTokens, t) | ||
| } | ||
| } | ||
|
|
||
| return sub, nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.