2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2020-09-09 20:37:43 +00:00
|
|
|
package router
|
|
|
|
|
2021-12-06 15:55:54 +00:00
|
|
|
import (
|
|
|
|
"github.com/hashicorp/consul/agent/metadata"
|
|
|
|
"github.com/hashicorp/consul/types"
|
|
|
|
)
|
2020-09-09 20:37:43 +00:00
|
|
|
|
2020-09-14 20:16:44 +00:00
|
|
|
// ServerTracker is called when Router is notified of a server being added or
|
|
|
|
// removed.
|
2020-09-09 20:37:43 +00:00
|
|
|
type ServerTracker interface {
|
2020-09-14 20:16:44 +00:00
|
|
|
NewRebalancer(dc string) func()
|
2021-12-06 15:55:54 +00:00
|
|
|
AddServer(types.AreaID, *metadata.Server)
|
|
|
|
RemoveServer(types.AreaID, *metadata.Server)
|
2020-09-09 20:37:43 +00:00
|
|
|
}
|
|
|
|
|
2020-09-14 20:16:44 +00:00
|
|
|
// Rebalancer is called periodically to re-order the servers so that the load on the
|
|
|
|
// servers is evenly balanced.
|
|
|
|
type Rebalancer func()
|
|
|
|
|
2020-09-09 20:37:43 +00:00
|
|
|
// NoOpServerTracker is a ServerTracker that does nothing. Used when gRPC is not
|
|
|
|
// enabled.
|
|
|
|
type NoOpServerTracker struct{}
|
|
|
|
|
2020-09-14 20:16:44 +00:00
|
|
|
// Rebalance does nothing
|
|
|
|
func (NoOpServerTracker) NewRebalancer(string) func() {
|
|
|
|
return func() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddServer does nothing
|
2021-12-06 15:55:54 +00:00
|
|
|
func (NoOpServerTracker) AddServer(types.AreaID, *metadata.Server) {}
|
2020-09-09 20:37:43 +00:00
|
|
|
|
2020-09-14 20:16:44 +00:00
|
|
|
// RemoveServer does nothing
|
2021-12-06 15:55:54 +00:00
|
|
|
func (NoOpServerTracker) RemoveServer(types.AreaID, *metadata.Server) {}
|