From a2acbe732e56897437e1f065e1ab13952b4bb093 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Fri, 18 Apr 2014 17:49:01 -0700 Subject: [PATCH] consul: Adding a method to enforce consistent read --- consul/rpc.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/consul/rpc.go b/consul/rpc.go index 46f01b4166..a80840e22a 100644 --- a/consul/rpc.go +++ b/consul/rpc.go @@ -264,3 +264,11 @@ func (s *Server) setQueryMeta(m *structs.QueryMeta) { m.KnownLeader = (s.raft.Leader() != nil) } } + +// consistentRead is used to ensure we do not perform a stale +// read. This is done by verifying leadership before the read. +func (s *Server) consistentRead() error { + defer metrics.MeasureSince([]string{"consul", "rpc", "consistentRead"}, time.Now()) + future := s.raft.VerifyLeader() + return future.Error() +}