Skip to content

Commit

Permalink
support AllowStale reads for consul topo when polling
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Demmer <mdemmer@slack-corp.com>
  • Loading branch information
demmer committed Nov 15, 2024
1 parent f93a9a1 commit a1889da
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion go/vt/topo/consultopo/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ func (s *Server) Get(ctx context.Context, filePath string) ([]byte, topo.Version
func (s *Server) List(ctx context.Context, filePathPrefix string, polling bool) ([]topo.KVInfo, error) {
nodePathPrefix := path.Join(s.root, filePathPrefix)

pairs, _, err := s.kv.List(nodePathPrefix, nil)
opts := api.QueryOptions{}
if consulAllowStalePolling && polling {
opts.AllowStale = true
}

pairs, _, err := s.kv.List(nodePathPrefix, &opts)
if err != nil {
return []topo.KVInfo{}, err
}
Expand Down
2 changes: 2 additions & 0 deletions go/vt/topo/consultopo/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var (
consulLockSessionChecks = "serfHealth"
consulLockSessionTTL string
consulLockDelay = 15 * time.Second
consulAllowStalePolling bool
)

func init() {
Expand All @@ -52,6 +53,7 @@ func registerServerFlags(fs *pflag.FlagSet) {
fs.StringVar(&consulLockSessionChecks, "topo_consul_lock_session_checks", consulLockSessionChecks, "List of checks for consul session.")
fs.StringVar(&consulLockSessionTTL, "topo_consul_lock_session_ttl", consulLockSessionTTL, "TTL for consul session.")
fs.DurationVar(&consulLockDelay, "topo_consul_lock_delay", consulLockDelay, "LockDelay for consul session.")
fs.BoolVar(&consulAllowStalePolling, "topo_consul_allow_stale_polling", consulAllowStalePolling, "Set AllowStale as an option when reading in a polling context.")
}

// ClientAuthCred credential to use for consul clusters
Expand Down

0 comments on commit a1889da

Please sign in to comment.