mirror of https://github.com/status-im/consul.git
Decouple xds capacity controller and raft-autopilot (#20511)
Decouple xds capacity controller and autopilot This prevents a potential bug where autopilot deadlocks while attempting to execute `AutopilotDelegate.NotifyState()` on an xdscapacity controller that stopped consuming messages.
This commit is contained in:
parent
26661a1c3b
commit
a1c8d4dd19
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:bug
|
||||||
|
connect: Remove code coupling where the xDS capacity controller could negatively affect raft autopilot performance.
|
||||||
|
```
|
|
@ -15,6 +15,7 @@ import (
|
||||||
"golang.org/x/time/rate"
|
"golang.org/x/time/rate"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/agent/structs"
|
"github.com/hashicorp/consul/agent/structs"
|
||||||
|
"github.com/hashicorp/consul/lib/channels"
|
||||||
"github.com/hashicorp/consul/lib/retry"
|
"github.com/hashicorp/consul/lib/retry"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -72,7 +73,7 @@ type SessionLimiter interface {
|
||||||
func NewController(cfg Config) *Controller {
|
func NewController(cfg Config) *Controller {
|
||||||
return &Controller{
|
return &Controller{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
serverCh: make(chan uint32),
|
serverCh: make(chan uint32, 1),
|
||||||
doneCh: make(chan struct{}),
|
doneCh: make(chan struct{}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,9 +110,9 @@ func (c *Controller) Run(ctx context.Context) {
|
||||||
// SetServerCount updates the number of healthy servers that is used when
|
// SetServerCount updates the number of healthy servers that is used when
|
||||||
// determining capacity. It is called by the autopilot delegate.
|
// determining capacity. It is called by the autopilot delegate.
|
||||||
func (c *Controller) SetServerCount(count uint32) {
|
func (c *Controller) SetServerCount(count uint32) {
|
||||||
select {
|
if err := channels.DeliverLatest(count, c.serverCh); err != nil {
|
||||||
case c.serverCh <- count:
|
// This should not be possible since only one producer should ever exist, but log anyway.
|
||||||
case <-c.doneCh:
|
c.cfg.Logger.Error("failed to deliver latest server count to xDS capacity controller")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue