From 97bb907b69e89ce464a3d0bdb791ee3913404cfd Mon Sep 17 00:00:00 2001 From: Aestek Date: Mon, 17 Jun 2019 18:05:47 +0200 Subject: [PATCH] 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. --- agent/local/state.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/agent/local/state.go b/agent/local/state.go index faceaf222..c8821d982 100644 --- a/agent/local/state.go +++ b/agent/local/state.go @@ -22,6 +22,8 @@ import ( uuid "github.com/hashicorp/go-uuid" ) +const fullSyncReadMaxStale = 2 * time.Second + // Config is the configuration for the State. type Config struct { AdvertiseAddr string @@ -1046,9 +1048,13 @@ func (l *State) Stats() map[string]string { func (l *State) updateSyncState() error { // Get all checks and services from the master req := structs.NodeSpecificRequest{ - Datacenter: l.config.Datacenter, - Node: l.config.NodeName, - QueryOptions: structs.QueryOptions{Token: l.tokens.AgentToken()}, + Datacenter: l.config.Datacenter, + Node: l.config.NodeName, + QueryOptions: structs.QueryOptions{ + Token: l.tokens.AgentToken(), + AllowStale: true, + MaxStaleDuration: fullSyncReadMaxStale, + }, } var out1 structs.IndexedNodeServices