mirror of https://github.com/status-im/consul.git
consul: Merging BlockingQuery into QueryOptions
This commit is contained in:
parent
180cc33030
commit
e706c988b8
|
@ -97,7 +97,7 @@ func (c *Catalog) ListNodes(args *structs.DCSpecificRequest, reply *structs.Inde
|
||||||
|
|
||||||
// Get the local state
|
// Get the local state
|
||||||
state := c.srv.fsm.State()
|
state := c.srv.fsm.State()
|
||||||
return c.srv.blockingRPC(&args.BlockingQuery,
|
return c.srv.blockingRPC(&args.QueryOptions,
|
||||||
&reply.QueryMeta,
|
&reply.QueryMeta,
|
||||||
state.QueryTables("Nodes"),
|
state.QueryTables("Nodes"),
|
||||||
func() error {
|
func() error {
|
||||||
|
@ -114,7 +114,7 @@ func (c *Catalog) ListServices(args *structs.DCSpecificRequest, reply *structs.I
|
||||||
|
|
||||||
// Get the current nodes
|
// Get the current nodes
|
||||||
state := c.srv.fsm.State()
|
state := c.srv.fsm.State()
|
||||||
return c.srv.blockingRPC(&args.BlockingQuery,
|
return c.srv.blockingRPC(&args.QueryOptions,
|
||||||
&reply.QueryMeta,
|
&reply.QueryMeta,
|
||||||
state.QueryTables("Services"),
|
state.QueryTables("Services"),
|
||||||
func() error {
|
func() error {
|
||||||
|
@ -136,7 +136,7 @@ func (c *Catalog) ServiceNodes(args *structs.ServiceSpecificRequest, reply *stru
|
||||||
|
|
||||||
// Get the nodes
|
// Get the nodes
|
||||||
state := c.srv.fsm.State()
|
state := c.srv.fsm.State()
|
||||||
err := c.srv.blockingRPC(&args.BlockingQuery,
|
err := c.srv.blockingRPC(&args.QueryOptions,
|
||||||
&reply.QueryMeta,
|
&reply.QueryMeta,
|
||||||
state.QueryTables("ServiceNodes"),
|
state.QueryTables("ServiceNodes"),
|
||||||
func() error {
|
func() error {
|
||||||
|
@ -174,7 +174,7 @@ func (c *Catalog) NodeServices(args *structs.NodeSpecificRequest, reply *structs
|
||||||
|
|
||||||
// Get the node services
|
// Get the node services
|
||||||
state := c.srv.fsm.State()
|
state := c.srv.fsm.State()
|
||||||
return c.srv.blockingRPC(&args.BlockingQuery,
|
return c.srv.blockingRPC(&args.QueryOptions,
|
||||||
&reply.QueryMeta,
|
&reply.QueryMeta,
|
||||||
state.QueryTables("NodeServices"),
|
state.QueryTables("NodeServices"),
|
||||||
func() error {
|
func() error {
|
||||||
|
|
|
@ -20,7 +20,7 @@ func (h *Health) ChecksInState(args *structs.ChecksInStateRequest,
|
||||||
|
|
||||||
// Get the state specific checks
|
// Get the state specific checks
|
||||||
state := h.srv.fsm.State()
|
state := h.srv.fsm.State()
|
||||||
return h.srv.blockingRPC(&args.BlockingQuery,
|
return h.srv.blockingRPC(&args.QueryOptions,
|
||||||
&reply.QueryMeta,
|
&reply.QueryMeta,
|
||||||
state.QueryTables("ChecksInState"),
|
state.QueryTables("ChecksInState"),
|
||||||
func() error {
|
func() error {
|
||||||
|
@ -38,7 +38,7 @@ func (h *Health) NodeChecks(args *structs.NodeSpecificRequest,
|
||||||
|
|
||||||
// Get the node checks
|
// Get the node checks
|
||||||
state := h.srv.fsm.State()
|
state := h.srv.fsm.State()
|
||||||
return h.srv.blockingRPC(&args.BlockingQuery,
|
return h.srv.blockingRPC(&args.QueryOptions,
|
||||||
&reply.QueryMeta,
|
&reply.QueryMeta,
|
||||||
state.QueryTables("NodeChecks"),
|
state.QueryTables("NodeChecks"),
|
||||||
func() error {
|
func() error {
|
||||||
|
@ -62,7 +62,7 @@ func (h *Health) ServiceChecks(args *structs.ServiceSpecificRequest,
|
||||||
|
|
||||||
// Get the service checks
|
// Get the service checks
|
||||||
state := h.srv.fsm.State()
|
state := h.srv.fsm.State()
|
||||||
return h.srv.blockingRPC(&args.BlockingQuery,
|
return h.srv.blockingRPC(&args.QueryOptions,
|
||||||
&reply.QueryMeta,
|
&reply.QueryMeta,
|
||||||
state.QueryTables("ServiceChecks"),
|
state.QueryTables("ServiceChecks"),
|
||||||
func() error {
|
func() error {
|
||||||
|
@ -84,7 +84,7 @@ func (h *Health) ServiceNodes(args *structs.ServiceSpecificRequest, reply *struc
|
||||||
|
|
||||||
// Get the nodes
|
// Get the nodes
|
||||||
state := h.srv.fsm.State()
|
state := h.srv.fsm.State()
|
||||||
err := h.srv.blockingRPC(&args.BlockingQuery,
|
err := h.srv.blockingRPC(&args.QueryOptions,
|
||||||
&reply.QueryMeta,
|
&reply.QueryMeta,
|
||||||
state.QueryTables("CheckServiceNodes"),
|
state.QueryTables("CheckServiceNodes"),
|
||||||
func() error {
|
func() error {
|
||||||
|
|
|
@ -50,7 +50,7 @@ func (k *KVS) Get(args *structs.KeyRequest, reply *structs.IndexedDirEntries) er
|
||||||
|
|
||||||
// Get the local state
|
// Get the local state
|
||||||
state := k.srv.fsm.State()
|
state := k.srv.fsm.State()
|
||||||
return k.srv.blockingRPC(&args.BlockingQuery,
|
return k.srv.blockingRPC(&args.QueryOptions,
|
||||||
&reply.QueryMeta,
|
&reply.QueryMeta,
|
||||||
state.QueryTables("KVSGet"),
|
state.QueryTables("KVSGet"),
|
||||||
func() error {
|
func() error {
|
||||||
|
@ -83,7 +83,7 @@ func (k *KVS) List(args *structs.KeyRequest, reply *structs.IndexedDirEntries) e
|
||||||
|
|
||||||
// Get the local state
|
// Get the local state
|
||||||
state := k.srv.fsm.State()
|
state := k.srv.fsm.State()
|
||||||
return k.srv.blockingRPC(&args.BlockingQuery,
|
return k.srv.blockingRPC(&args.QueryOptions,
|
||||||
&reply.QueryMeta,
|
&reply.QueryMeta,
|
||||||
state.QueryTables("KVSList"),
|
state.QueryTables("KVSList"),
|
||||||
func() error {
|
func() error {
|
||||||
|
|
|
@ -203,7 +203,7 @@ func (s *Server) raftApply(t structs.MessageType, msg interface{}) (interface{},
|
||||||
|
|
||||||
// blockingRPC is used for queries that need to wait for a
|
// blockingRPC is used for queries that need to wait for a
|
||||||
// minimum index. This is used to block and wait for changes.
|
// minimum index. This is used to block and wait for changes.
|
||||||
func (s *Server) blockingRPC(b *structs.BlockingQuery, m *structs.QueryMeta,
|
func (s *Server) blockingRPC(b *structs.QueryOptions, m *structs.QueryMeta,
|
||||||
tables MDBTables, run func() error) error {
|
tables MDBTables, run func() error) error {
|
||||||
var timeout <-chan time.Time
|
var timeout <-chan time.Time
|
||||||
var notifyCh chan struct{}
|
var notifyCh chan struct{}
|
||||||
|
|
|
@ -35,18 +35,15 @@ type RPCInfo interface {
|
||||||
AllowStaleRead() bool
|
AllowStaleRead() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlockingQuery is used to block on a query and wait for a change.
|
|
||||||
// Either both fields, or neither must be provided.
|
|
||||||
type BlockingQuery struct {
|
|
||||||
// If set, wait until query exceeds given index
|
|
||||||
MinQueryIndex uint64
|
|
||||||
|
|
||||||
// Provided with MinQueryIndex to wait for change
|
|
||||||
MaxQueryTime time.Duration
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryOptions is used to specify various flags for read queries
|
// QueryOptions is used to specify various flags for read queries
|
||||||
type QueryOptions struct {
|
type QueryOptions struct {
|
||||||
|
// If set, wait until query exceeds given index. Must be provided
|
||||||
|
// with MaxQueryTime.
|
||||||
|
MinQueryIndex uint64
|
||||||
|
|
||||||
|
// Provided with MinQueryIndex to wait for change.
|
||||||
|
MaxQueryTime time.Duration
|
||||||
|
|
||||||
// If set, any follower can service the request. Results
|
// If set, any follower can service the request. Results
|
||||||
// may be arbitrarily stale.
|
// may be arbitrarily stale.
|
||||||
AllowStale bool
|
AllowStale bool
|
||||||
|
@ -125,7 +122,6 @@ func (r *DeregisterRequest) RequestDatacenter() string {
|
||||||
// DCSpecificRequest is used to query about a specific DC
|
// DCSpecificRequest is used to query about a specific DC
|
||||||
type DCSpecificRequest struct {
|
type DCSpecificRequest struct {
|
||||||
Datacenter string
|
Datacenter string
|
||||||
BlockingQuery
|
|
||||||
QueryOptions
|
QueryOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +135,6 @@ type ServiceSpecificRequest struct {
|
||||||
ServiceName string
|
ServiceName string
|
||||||
ServiceTag string
|
ServiceTag string
|
||||||
TagFilter bool // Controls tag filtering
|
TagFilter bool // Controls tag filtering
|
||||||
BlockingQuery
|
|
||||||
QueryOptions
|
QueryOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +146,6 @@ func (r *ServiceSpecificRequest) RequestDatacenter() string {
|
||||||
type NodeSpecificRequest struct {
|
type NodeSpecificRequest struct {
|
||||||
Datacenter string
|
Datacenter string
|
||||||
Node string
|
Node string
|
||||||
BlockingQuery
|
|
||||||
QueryOptions
|
QueryOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,7 +157,6 @@ func (r *NodeSpecificRequest) RequestDatacenter() string {
|
||||||
type ChecksInStateRequest struct {
|
type ChecksInStateRequest struct {
|
||||||
Datacenter string
|
Datacenter string
|
||||||
State string
|
State string
|
||||||
BlockingQuery
|
|
||||||
QueryOptions
|
QueryOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,7 +285,6 @@ func (r *KVSRequest) RequestDatacenter() string {
|
||||||
type KeyRequest struct {
|
type KeyRequest struct {
|
||||||
Datacenter string
|
Datacenter string
|
||||||
Key string
|
Key string
|
||||||
BlockingQuery
|
|
||||||
QueryOptions
|
QueryOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue