ae: use stale requests when performing full sync (#5873)

Read requests performed during anti antropy full sync currently target
the leader only. This generates a non-negligible load on the leader when
the DC is large enough and can be offloaded to the followers following
the "eventually consistent" policy for the agent state.
We switch the AE read calls to use stale requests with a small (2s)
MaxStaleDuration value and make sure we do not read too fast after a
write.
This commit is contained in:
Aestek 2019-06-17 18:05:47 +02:00 committed by Hans Hasselberg
parent 7ff9308e6d
commit 97bb907b69

View file

@ -22,6 +22,8 @@ import (
uuid "github.com/hashicorp/go-uuid" uuid "github.com/hashicorp/go-uuid"
) )
const fullSyncReadMaxStale = 2 * time.Second
// Config is the configuration for the State. // Config is the configuration for the State.
type Config struct { type Config struct {
AdvertiseAddr string AdvertiseAddr string
@ -1046,9 +1048,13 @@ func (l *State) Stats() map[string]string {
func (l *State) updateSyncState() error { func (l *State) updateSyncState() error {
// Get all checks and services from the master // Get all checks and services from the master
req := structs.NodeSpecificRequest{ req := structs.NodeSpecificRequest{
Datacenter: l.config.Datacenter, Datacenter: l.config.Datacenter,
Node: l.config.NodeName, Node: l.config.NodeName,
QueryOptions: structs.QueryOptions{Token: l.tokens.AgentToken()}, QueryOptions: structs.QueryOptions{
Token: l.tokens.AgentToken(),
AllowStale: true,
MaxStaleDuration: fullSyncReadMaxStale,
},
} }
var out1 structs.IndexedNodeServices var out1 structs.IndexedNodeServices