consul: Merging BlockingQuery into QueryOptions

This commit is contained in:
Armon Dadgar 2014-04-21 11:31:15 -07:00
parent 180cc33030
commit e706c988b8
5 changed files with 18 additions and 26 deletions

View File

@ -97,7 +97,7 @@ func (c *Catalog) ListNodes(args *structs.DCSpecificRequest, reply *structs.Inde
// Get the local state
state := c.srv.fsm.State()
return c.srv.blockingRPC(&args.BlockingQuery,
return c.srv.blockingRPC(&args.QueryOptions,
&reply.QueryMeta,
state.QueryTables("Nodes"),
func() error {
@ -114,7 +114,7 @@ func (c *Catalog) ListServices(args *structs.DCSpecificRequest, reply *structs.I
// Get the current nodes
state := c.srv.fsm.State()
return c.srv.blockingRPC(&args.BlockingQuery,
return c.srv.blockingRPC(&args.QueryOptions,
&reply.QueryMeta,
state.QueryTables("Services"),
func() error {
@ -136,7 +136,7 @@ func (c *Catalog) ServiceNodes(args *structs.ServiceSpecificRequest, reply *stru
// Get the nodes
state := c.srv.fsm.State()
err := c.srv.blockingRPC(&args.BlockingQuery,
err := c.srv.blockingRPC(&args.QueryOptions,
&reply.QueryMeta,
state.QueryTables("ServiceNodes"),
func() error {
@ -174,7 +174,7 @@ func (c *Catalog) NodeServices(args *structs.NodeSpecificRequest, reply *structs
// Get the node services
state := c.srv.fsm.State()
return c.srv.blockingRPC(&args.BlockingQuery,
return c.srv.blockingRPC(&args.QueryOptions,
&reply.QueryMeta,
state.QueryTables("NodeServices"),
func() error {

View File

@ -20,7 +20,7 @@ func (h *Health) ChecksInState(args *structs.ChecksInStateRequest,
// Get the state specific checks
state := h.srv.fsm.State()
return h.srv.blockingRPC(&args.BlockingQuery,
return h.srv.blockingRPC(&args.QueryOptions,
&reply.QueryMeta,
state.QueryTables("ChecksInState"),
func() error {
@ -38,7 +38,7 @@ func (h *Health) NodeChecks(args *structs.NodeSpecificRequest,
// Get the node checks
state := h.srv.fsm.State()
return h.srv.blockingRPC(&args.BlockingQuery,
return h.srv.blockingRPC(&args.QueryOptions,
&reply.QueryMeta,
state.QueryTables("NodeChecks"),
func() error {
@ -62,7 +62,7 @@ func (h *Health) ServiceChecks(args *structs.ServiceSpecificRequest,
// Get the service checks
state := h.srv.fsm.State()
return h.srv.blockingRPC(&args.BlockingQuery,
return h.srv.blockingRPC(&args.QueryOptions,
&reply.QueryMeta,
state.QueryTables("ServiceChecks"),
func() error {
@ -84,7 +84,7 @@ func (h *Health) ServiceNodes(args *structs.ServiceSpecificRequest, reply *struc
// Get the nodes
state := h.srv.fsm.State()
err := h.srv.blockingRPC(&args.BlockingQuery,
err := h.srv.blockingRPC(&args.QueryOptions,
&reply.QueryMeta,
state.QueryTables("CheckServiceNodes"),
func() error {

View File

@ -50,7 +50,7 @@ func (k *KVS) Get(args *structs.KeyRequest, reply *structs.IndexedDirEntries) er
// Get the local state
state := k.srv.fsm.State()
return k.srv.blockingRPC(&args.BlockingQuery,
return k.srv.blockingRPC(&args.QueryOptions,
&reply.QueryMeta,
state.QueryTables("KVSGet"),
func() error {
@ -83,7 +83,7 @@ func (k *KVS) List(args *structs.KeyRequest, reply *structs.IndexedDirEntries) e
// Get the local state
state := k.srv.fsm.State()
return k.srv.blockingRPC(&args.BlockingQuery,
return k.srv.blockingRPC(&args.QueryOptions,
&reply.QueryMeta,
state.QueryTables("KVSList"),
func() error {

View File

@ -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
// 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 {
var timeout <-chan time.Time
var notifyCh chan struct{}

View File

@ -35,18 +35,15 @@ type RPCInfo interface {
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
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
// may be arbitrarily stale.
AllowStale bool
@ -125,7 +122,6 @@ func (r *DeregisterRequest) RequestDatacenter() string {
// DCSpecificRequest is used to query about a specific DC
type DCSpecificRequest struct {
Datacenter string
BlockingQuery
QueryOptions
}
@ -139,7 +135,6 @@ type ServiceSpecificRequest struct {
ServiceName string
ServiceTag string
TagFilter bool // Controls tag filtering
BlockingQuery
QueryOptions
}
@ -151,7 +146,6 @@ func (r *ServiceSpecificRequest) RequestDatacenter() string {
type NodeSpecificRequest struct {
Datacenter string
Node string
BlockingQuery
QueryOptions
}
@ -163,7 +157,6 @@ func (r *NodeSpecificRequest) RequestDatacenter() string {
type ChecksInStateRequest struct {
Datacenter string
State string
BlockingQuery
QueryOptions
}
@ -292,7 +285,6 @@ func (r *KVSRequest) RequestDatacenter() string {
type KeyRequest struct {
Datacenter string
Key string
BlockingQuery
QueryOptions
}