Skip to content

Commit

Permalink
Receive: Allow setting hashing algorithm per tenant in hashrings config
Browse files Browse the repository at this point in the history
Signed-off-by: haanhvu <[email protected]>
  • Loading branch information
haanhvu committed Sep 25, 2022
1 parent f4ffce6 commit 8067669
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
- [#5702](https://github.com/thanos-io/thanos/pull/5702) Store: Upgrade minio-go/v7 to fix panic caused by leaked goroutines.

### Added
* [#5654](https://github.com/thanos-io/thanos/pull/5654) Query: add `--grpc-compression` flag that controls the compression used in gRPC client. With the flag it is now possible to compress the traffic between Query and StoreAPI nodes - you get lower network usage in exchange for a bit higher CPU/RAM usage.
- [#5654](https://github.com/thanos-io/thanos/pull/5654) Query: add `--grpc-compression` flag that controls the compression used in gRPC client. With the flag it is now possible to compress the traffic between Query and StoreAPI nodes - you get lower network usage in exchange for a bit higher CPU/RAM usage.
- [#5650](https://github.com/thanos-io/thanos/pull/5650) Query Frontend: Add sharded queries metrics.
- [#5658](https://github.com/thanos-io/thanos/pull/5658) Query Frontend: Introduce new optional parameters (`query-range.min-split-interval`, `query-range.max-split-interval`, `query-range.horizontal-shards`) to implement more dynamic horizontal query splitting.
- [#5653](https://github.com/thanos-io/thanos/pull/5653) Receive: Allow setting hashing algorithm per tenant in hashrings config

### Changed

Expand Down
7 changes: 4 additions & 3 deletions pkg/receive/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ const (
// HashringConfig represents the configuration for a hashring
// a receive node knows about.
type HashringConfig struct {
Hashring string `json:"hashring,omitempty"`
Tenants []string `json:"tenants,omitempty"`
Endpoints []string `json:"endpoints"`
Hashring string `json:"hashring,omitempty"`
Tenants []string `json:"tenants,omitempty"`
Endpoints []string `json:"endpoints"`
Algorithm HashringAlgorithm `json:"algorithm,omitempty"`
}

// ConfigWatcher is able to watch a file containing a hashring configuration
Expand Down
30 changes: 18 additions & 12 deletions pkg/receive/hashring.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,19 +236,14 @@ func newMultiHashring(algorithm HashringAlgorithm, replicationFactor uint64, cfg
cache: make(map[string]Hashring),
}

newHashring := func(endpoints []string) Hashring {
switch algorithm {
case AlgorithmHashmod:
return simpleHashring(endpoints)
case AlgorithmKetama:
return newKetamaHashring(endpoints, SectionsPerNode, replicationFactor)
default:
return simpleHashring(endpoints)
}
}

for _, h := range cfg {
m.hashrings = append(m.hashrings, newHashring(h.Endpoints))
var hashring Hashring
if h.Algorithm != "" {
hashring = newHashring(h.Algorithm, h.Endpoints, replicationFactor)
} else {
hashring = newHashring(algorithm, h.Endpoints, replicationFactor)
}
m.hashrings = append(m.hashrings, hashring)
var t map[string]struct{}
if len(h.Tenants) != 0 {
t = make(map[string]struct{})
Expand Down Expand Up @@ -299,3 +294,14 @@ func HashringFromConfig(algorithm HashringAlgorithm, replicationFactor uint64, c

return newMultiHashring(algorithm, replicationFactor, config), err
}

func newHashring(algorithm HashringAlgorithm, endpoints []string, replicationFactor uint64) Hashring {
switch algorithm {
case AlgorithmHashmod:
return simpleHashring(endpoints)
case AlgorithmKetama:
return newKetamaHashring(endpoints, SectionsPerNode, replicationFactor)
default:
return simpleHashring(endpoints)
}
}

0 comments on commit 8067669

Please sign in to comment.