countTokens returns the number of tokens and tokens within the range for each instance. The ring read lock must be already taken when calling this function.
()
| 636 | // countTokens returns the number of tokens and tokens within the range for each instance. |
| 637 | // The ring read lock must be already taken when calling this function. |
| 638 | func (r *Ring) countTokens() (map[string]uint32, map[string]int64) { |
| 639 | owned := map[string]int64{} |
| 640 | numTokens := map[string]uint32{} |
| 641 | for i := 1; i <= len(r.ringTokens); i++ { // Compute how many tokens are within the range. |
| 642 | index := i % len(r.ringTokens) |
| 643 | diff := tokenDistance(r.ringTokens[i-1], r.ringTokens[index]) |
| 644 | |
| 645 | info := r.ringInstanceByToken[r.ringTokens[index]] |
| 646 | numTokens[info.InstanceID] = numTokens[info.InstanceID] + 1 |
| 647 | owned[info.InstanceID] = owned[info.InstanceID] + diff |
| 648 | } |
| 649 | |
| 650 | // Set to 0 the number of owned tokens by instances which don't have tokens yet. |
| 651 | for id := range r.ringDesc.Ingesters { |
| 652 | if _, ok := owned[id]; !ok { |
| 653 | owned[id] = 0 |
| 654 | numTokens[id] = 0 |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | return numTokens, owned |
| 659 | } |
| 660 | |
| 661 | // updateRingMetrics updates ring metrics. Caller must be holding the Write lock! |
| 662 | func (r *Ring) updateRingMetrics(compareResult CompareResult) { |
no test coverage detected