mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
nomad: adding basic RPC interfaces
This commit is contained in:
@@ -2,10 +2,17 @@ package structs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-msgpack/codec"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNoLeader = fmt.Errorf("No cluster leader")
|
||||
ErrNoRegionPath = fmt.Errorf("No path to region")
|
||||
)
|
||||
|
||||
type MessageType uint8
|
||||
|
||||
const (
|
||||
@@ -21,6 +28,69 @@ const (
|
||||
IgnoreUnknownTypeFlag MessageType = 128
|
||||
)
|
||||
|
||||
// RPCInfo is used to describe common information about query
|
||||
type RPCInfo interface {
|
||||
RequestRegion() string
|
||||
IsRead() bool
|
||||
AllowStaleRead() bool
|
||||
}
|
||||
|
||||
// QueryOptions is used to specify various flags for read queries
|
||||
type QueryOptions struct {
|
||||
// The target region for this query
|
||||
Region string
|
||||
|
||||
// If set, any follower can service the request. Results
|
||||
// may be arbitrarily stale.
|
||||
AllowStale bool
|
||||
}
|
||||
|
||||
func (q QueryOptions) RequestRegion() string {
|
||||
return q.Region
|
||||
}
|
||||
|
||||
// QueryOption only applies to reads, so always true
|
||||
func (q QueryOptions) IsRead() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (q QueryOptions) AllowStaleRead() bool {
|
||||
return q.AllowStale
|
||||
}
|
||||
|
||||
type WriteRequest struct {
|
||||
Region string
|
||||
}
|
||||
|
||||
func (w WriteRequest) RequestRegion() string {
|
||||
// The target region for this request
|
||||
return w.Region
|
||||
}
|
||||
|
||||
// WriteRequest only applies to writes, always false
|
||||
func (w WriteRequest) IsRead() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (w WriteRequest) AllowStaleRead() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// QueryMeta allows a query response to include potentially
|
||||
// useful metadata about a query
|
||||
type QueryMeta struct {
|
||||
// This is the index associated with the read
|
||||
Index uint64
|
||||
|
||||
// If AllowStale is used, this is time elapsed since
|
||||
// last contact between the follower and leader. This
|
||||
// can be used to gauge staleness.
|
||||
LastContact time.Duration
|
||||
|
||||
// Used to indicate if there is a known leader node
|
||||
KnownLeader bool
|
||||
}
|
||||
|
||||
// msgpackHandle is a shared handle for encoding/decoding of structs
|
||||
var msgpackHandle = &codec.MsgpackHandle{}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user