mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Allows cluster filtering in account subject mapping (#4175)
- [X] Branch rebased on top of current main (`git pull --rebase origin main`) - [X] Changes squashed to a single commit (described [here](http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html)) - [ ] Build is green in Travis CI - [X] You have certified that the contribution is your original work and that you license the work to the project under the [Apache 2 license](https://github.com/nats-io/nats-server/blob/main/LICENSE) ### Changes proposed in this pull request: Allows (exposes) the existing cluster filtering option of account level subject mapping, thereby allowing you to define different mapping destination per cluster (e.g. to insert the cluster name as a subject token). Example: ``` mappings { "foo":[ {destination:"foo-east", cluster: "east", weight:100}, {destination:"foo-west", cluster: "west", weight:100}, ] } ```
This commit is contained in:
@@ -597,7 +597,6 @@ func (a *Account) AddMapping(src, dest string) error {
|
||||
}
|
||||
|
||||
// AddWeightedMappings will add in a weighted mappings for the destinations.
|
||||
// TODO(dlc) - Allow cluster filtering
|
||||
func (a *Account) AddWeightedMappings(src string, dests ...*MapDest) error {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
@@ -614,7 +613,7 @@ func (a *Account) AddWeightedMappings(src string, dests ...*MapDest) error {
|
||||
m := &mapping{src: src, wc: subjectHasWildcard(src), dests: make([]*destination, 0, len(dests)+1)}
|
||||
seen := make(map[string]struct{})
|
||||
|
||||
var tw uint8
|
||||
var tw = make(map[string]uint8)
|
||||
for _, d := range dests {
|
||||
if _, ok := seen[d.Subject]; ok {
|
||||
return fmt.Errorf("duplicate entry for %q", d.Subject)
|
||||
@@ -623,8 +622,8 @@ func (a *Account) AddWeightedMappings(src string, dests ...*MapDest) error {
|
||||
if d.Weight > 100 {
|
||||
return fmt.Errorf("individual weights need to be <= 100")
|
||||
}
|
||||
tw += d.Weight
|
||||
if tw > 100 {
|
||||
tw[d.Cluster] += d.Weight
|
||||
if tw[d.Cluster] > 100 {
|
||||
return fmt.Errorf("total weight needs to be <= 100")
|
||||
}
|
||||
err := ValidateMappingDestination(d.Subject)
|
||||
|
||||
Reference in New Issue
Block a user