consul

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2015 License: MPL-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultDC          = "dc1"
	DefaultLANSerfPort = 8301
	DefaultWANSerfPort = 8302
)
View Source
const (
	SerfCheckID           = "serfHealth"
	SerfCheckName         = "Serf Health Status"
	SerfCheckAliveOutput  = "Agent alive and reachable"
	SerfCheckFailedOutput = "Agent not live or unreachable"
	ConsulServiceID       = "consul"
	ConsulServiceName     = "consul"
)
View Source
const (
	ProtocolVersionMin uint8 = 1
	ProtocolVersionMax       = 2
)

These are the protocol versions that Consul can _understand_. These are Consul-level protocol versions, that are used to configure the Serf protocol versions.

View Source
const (
	// StatusReap is used to update the status of a node if we
	// are handling a EventMemberReap
	StatusReap = serf.MemberStatus(-1)
)

Variables

View Source
var (
	DefaultRPCAddr = &net.TCPAddr{IP: net.ParseIP("0.0.0.0"), Port: 8300}
)

Functions

func DefaultIndexFunc

func DefaultIndexFunc(idx *MDBIndex, parts []string) string

DefaultIndexFunc is used if no IdxFunc is provided. It joins the columns using '||' which is reasonably unlikely to occur. We also prefix with a byte to ensure we never have a zero length key

func DefaultIndexPrefixFunc

func DefaultIndexPrefixFunc(idx *MDBIndex, parts []string) string

DefaultIndexPrefixFunc can be used with DefaultIndexFunc to scan for index prefix values. This should only be used as part of a virtual index.

func FilterDirEnt added in v0.4.0

func FilterDirEnt(acl acl.ACL, ent structs.DirEntries) structs.DirEntries

FilterDirEnt is used to filter a list of directory entries by applying an ACL policy

func FilterEntries added in v0.4.0

func FilterEntries(f Filter) int

FilterEntries is used to do an inplace filter of a slice. This has cost proportional to the list length.

func FilterKeys added in v0.4.0

func FilterKeys(acl acl.ACL, keys []string) []string

FilterKeys is used to filter a list of keys by applying an ACL policy

func GetPrivateIP

func GetPrivateIP() (net.IP, error)

GetPrivateIP is used to return the first private IP address associated with an interface on the machine

func NewFSM

func NewFSM(gc *TombstoneGC, path string, logOutput io.Writer) (*consulFSM, error)

NewFSMPath is used to construct a new FSM with a blank state

func ToLowerList added in v0.4.0

func ToLowerList(l []string) []string

Types

type ACL added in v0.4.0

type ACL struct {
	// contains filtered or unexported fields
}

ACL endpoint is used to manipulate ACLs

func (*ACL) Apply added in v0.4.0

func (a *ACL) Apply(args *structs.ACLRequest, reply *string) error

Apply is used to apply a modifying request to the data store. This should only be used for operations that modify the data

func (*ACL) Get added in v0.4.0

func (a *ACL) Get(args *structs.ACLSpecificRequest,
	reply *structs.IndexedACLs) error

Get is used to retrieve a single ACL

func (*ACL) GetPolicy added in v0.4.0

func (a *ACL) GetPolicy(args *structs.ACLPolicyRequest, reply *structs.ACLPolicy) error

GetPolicy is used to retrieve a compiled policy object with a TTL. Does not support a blocking query.

func (*ACL) List added in v0.4.0

func (a *ACL) List(args *structs.DCSpecificRequest,
	reply *structs.IndexedACLs) error

List is used to list all the ACLs

type Catalog

type Catalog struct {
	// contains filtered or unexported fields
}

Catalog endpoint is used to manipulate the service catalog

func (*Catalog) Deregister

func (c *Catalog) Deregister(args *structs.DeregisterRequest, reply *struct{}) error

Deregister is used to remove a service registration for a given node.

func (*Catalog) ListDatacenters

func (c *Catalog) ListDatacenters(args *struct{}, reply *[]string) error

ListDatacenters is used to query for the list of known datacenters

func (*Catalog) ListNodes

func (c *Catalog) ListNodes(args *structs.DCSpecificRequest, reply *structs.IndexedNodes) error

ListNodes is used to query the nodes in a DC

func (*Catalog) ListServices

func (c *Catalog) ListServices(args *structs.DCSpecificRequest, reply *structs.IndexedServices) error

ListServices is used to query the services in a DC

func (*Catalog) NodeServices

func (c *Catalog) NodeServices(args *structs.NodeSpecificRequest, reply *structs.IndexedNodeServices) error

NodeServices returns all the services registered as part of a node

func (*Catalog) Register

func (c *Catalog) Register(args *structs.RegisterRequest, reply *struct{}) error

Register is used register that a node is providing a given service.

func (*Catalog) ServiceNodes

func (c *Catalog) ServiceNodes(args *structs.ServiceSpecificRequest, reply *structs.IndexedServiceNodes) error

ServiceNodes returns all the nodes registered as part of a service

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is Consul client which uses RPC to communicate with the services for service discovery, health checking, and DC forwarding.

func NewClient

func NewClient(config *Config) (*Client, error)

NewClient is used to construct a new Consul client from the configuration, potentially returning an error

func (*Client) Encrypted added in v0.5.0

func (c *Client) Encrypted() bool

Encrypted determines if gossip is encrypted

func (*Client) JoinLAN

func (c *Client) JoinLAN(addrs []string) (int, error)

JoinLAN is used to have Consul client join the inner-DC pool The target address should be another node inside the DC listening on the Serf LAN address

func (*Client) KeyManagerLAN added in v0.5.0

func (c *Client) KeyManagerLAN() *serf.KeyManager

KeyManagerLAN returns the LAN Serf keyring manager

func (*Client) LANMembers

func (c *Client) LANMembers() []serf.Member

LANMembers is used to return the members of the LAN cluster

func (*Client) Leave

func (c *Client) Leave() error

Leave is used to prepare for a graceful shutdown

func (*Client) LocalMember added in v0.3.0

func (c *Client) LocalMember() serf.Member

LocalMember is used to return the local node

func (*Client) RPC

func (c *Client) RPC(method string, args interface{}, reply interface{}) error

RPC is used to forward an RPC call to a consul server, or fail if no servers

func (*Client) RemoveFailedNode

func (c *Client) RemoveFailedNode(node string) error

RemoveFailedNode is used to remove a failed node from the cluster

func (*Client) Shutdown

func (c *Client) Shutdown() error

Shutdown is used to shutdown the client

func (*Client) Stats

func (c *Client) Stats() map[string]map[string]string

Stats is used to return statistics for debugging and insight for various sub-systems

func (*Client) UserEvent added in v0.4.0

func (c *Client) UserEvent(name string, payload []byte) error

UserEvent is used to fire an event via the Serf layer

type Config

type Config struct {
	// Bootstrap mode is used to bring up the first Consul server.
	// It is required so that it can elect a leader without any
	// other nodes being present
	Bootstrap bool

	// BootstrapExpect mode is used to automatically bring up a collection of
	// Consul servers. This can be used to automatically bring up a collection
	// of nodes.
	BootstrapExpect int

	// Datacenter is the datacenter this Consul server represents
	Datacenter string

	// DataDir is the directory to store our state in
	DataDir string

	// Node name is the name we use to advertise. Defaults to hostname.
	NodeName string

	// Domain is the DNS domain for the records. Defaults to "consul."
	Domain string

	// RaftConfig is the configuration used for Raft in the local DC
	RaftConfig *raft.Config

	// RPCAddr is the RPC address used by Consul. This should be reachable
	// by the WAN and LAN
	RPCAddr *net.TCPAddr

	// RPCAdvertise is the address that is advertised to other nodes for
	// the RPC endpoint. This can differ from the RPC address, if for example
	// the RPCAddr is unspecified "0.0.0.0:8300", but this address must be
	// reachable
	RPCAdvertise *net.TCPAddr

	// SerfLANConfig is the configuration for the intra-dc serf
	SerfLANConfig *serf.Config

	// SerfWANConfig is the configuration for the cross-dc serf
	SerfWANConfig *serf.Config

	// ReconcileInterval controls how often we reconcile the strongly
	// consistent store with the Serf info. This is used to handle nodes
	// that are force removed, as well as intermittent unavailability during
	// leader election.
	ReconcileInterval time.Duration

	// LogOutput is the location to write logs to. If this is not set,
	// logs will go to stderr.
	LogOutput io.Writer

	// ProtocolVersion is the protocol version to speak. This must be between
	// ProtocolVersionMin and ProtocolVersionMax.
	ProtocolVersion uint8

	// VerifyIncoming is used to verify the authenticity of incoming connections.
	// This means that TCP requests are forbidden, only allowing for TLS. TLS connections
	// must match a provided certificate authority. This can be used to force client auth.
	VerifyIncoming bool

	// VerifyOutgoing is used to verify the authenticity of outgoing connections.
	// This means that TLS requests are used, and TCP requests are not made. TLS connections
	// must match a provided certificate authority. This is used to verify authenticity of
	// server nodes.
	VerifyOutgoing bool

	// VerifyServerHostname is used to enable hostname verification of servers. This
	// ensures that the certificate presented is valid for server.<datacenter>.<domain>.
	// This prevents a compromised client from being restarted as a server, and then
	// intercepting request traffic as well as being added as a raft peer. This should be
	// enabled by default with VerifyOutgoing, but for legacy reasons we cannot break
	// existing clients.
	VerifyServerHostname bool

	// CAFile is a path to a certificate authority file. This is used with VerifyIncoming
	// or VerifyOutgoing to verify the TLS connection.
	CAFile string

	// CertFile is used to provide a TLS certificate that is used for serving TLS connections.
	// Must be provided to serve TLS connections.
	CertFile string

	// KeyFile is used to provide a TLS key that is used for serving TLS connections.
	// Must be provided to serve TLS connections.
	KeyFile string

	// ServerName is used with the TLS certificate to ensure the name we
	// provide matches the certificate
	ServerName string

	// RejoinAfterLeave controls our interaction with Serf.
	// When set to false (default), a leave causes a Consul to not rejoin
	// the cluster until an explicit join is received. If this is set to
	// true, we ignore the leave, and rejoin the cluster on start.
	RejoinAfterLeave bool

	// Build is a string that is gossiped around, and can be used to help
	// operators track which versions are actively deployed
	Build string

	// ACLToken is the default token to use when making a request.
	// If not provided, the anonymous token is used. This enables
	// backwards compatibility as well.
	ACLToken string

	// ACLMasterToken is used to bootstrap the ACL system. It should be specified
	// on the servers in the ACLDatacenter. When the leader comes online, it ensures
	// that the Master token is available. This provides the initial token.
	ACLMasterToken string

	// ACLDatacenter provides the authoritative datacenter for ACL
	// tokens. If not provided, ACL verification is disabled.
	ACLDatacenter string

	// ACLTTL controls the time-to-live of cached ACL policies.
	// It can be set to zero to disable caching, but this adds
	// a substantial cost.
	ACLTTL time.Duration

	// ACLDefaultPolicy is used to control the ACL interaction when
	// there is no defined policy. This can be "allow" which means
	// ACLs are used to black-list, or "deny" which means ACLs are
	// white-lists.
	ACLDefaultPolicy string

	// ACLDownPolicy controls the behavior of ACLs if the ACLDatacenter
	// cannot be contacted. It can be either "deny" to deny all requests,
	// or "extend-cache" which ignores the ACLCacheInterval and uses
	// cached policies. If a policy is not in the cache, it acts like deny.
	// "allow" can be used to allow all requests. This is not recommended.
	ACLDownPolicy string

	// TombstoneTTL is used to control how long KV tombstones are retained.
	// This provides a window of time where the X-Consul-Index is monotonic.
	// Outside this window, the index may not be monotonic. This is a result
	// of a few trade offs:
	// 1) The index is defined by the data view and not globally. This is a
	// performance optimization that prevents any write from incrementing the
	// index for all data views.
	// 2) Tombstones are not kept indefinitely, since otherwise storage required
	// is also monotonic. This prevents deletes from reducing the disk space
	// used.
	// In theory, neither of these are intrinsic limitations, however for the
	// purposes of building a practical system, they are reaonable trade offs.
	//
	// It is also possible to set this to an incredibly long time, thereby
	// simulating infinite retention. This is not recommended however.
	//
	TombstoneTTL time.Duration

	// TombstoneTTLGranularity is used to control how granular the timers are
	// for the Tombstone GC. This is used to batch the GC of many keys together
	// to reduce overhead. It is unlikely a user would ever need to tune this.
	TombstoneTTLGranularity time.Duration

	// Minimum Session TTL
	SessionTTLMin time.Duration

	// ServerUp callback can be used to trigger a notification that
	// a Consul server is now up and known about.
	ServerUp func()

	// UserEventHandler callback can be used to handle incoming
	// user events. This function should not block.
	UserEventHandler func(serf.UserEvent)
}

Config is used to configure the server

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig is used to return a sane default configuration

func (*Config) CheckACL added in v0.4.0

func (c *Config) CheckACL() error

CheckACL is used to sanity check the ACL configuration

func (*Config) CheckVersion

func (c *Config) CheckVersion() error

CheckVersion is used to check if the ProtocolVersion is valid

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn is a pooled connection to a Consul server

func (*Conn) Close

func (c *Conn) Close() error

type ConnPool

type ConnPool struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ConnPool is used to maintain a connection pool to other Consul servers. This is used to reduce the latency of RPC requests between servers. It is only used to pool connections in the rpcConsul mode. Raft connections are pooled separately.

func NewPool

func NewPool(logOutput io.Writer, maxTime time.Duration, maxStreams int, tlsWrap tlsutil.DCWrapper) *ConnPool

NewPool is used to make a new connection pool Maintain at most one connection per host, for up to maxTime. Set maxTime to 0 to disable reaping. maxStreams is used to control the number of idle streams allowed. If TLS settings are provided outgoing connections use TLS.

func (*ConnPool) RPC

func (p *ConnPool) RPC(dc string, addr net.Addr, version int, method string, args interface{}, reply interface{}) error

RPC is used to make an RPC call to a remote host

func (*ConnPool) Shutdown

func (p *ConnPool) Shutdown() error

Shutdown is used to close the connection pool

type Filter added in v0.4.0

type Filter interface {
	Len() int
	Filter(int) bool
	Move(dst, src, span int)
}

Filter interfae is used with FilterEntries to do an in-place filter of a slice.

type Health

type Health struct {
	// contains filtered or unexported fields
}

Health endpoint is used to query the health information

func (*Health) ChecksInState

func (h *Health) ChecksInState(args *structs.ChecksInStateRequest,
	reply *structs.IndexedHealthChecks) error

ChecksInState is used to get all the checks in a given state

func (*Health) NodeChecks

func (h *Health) NodeChecks(args *structs.NodeSpecificRequest,
	reply *structs.IndexedHealthChecks) error

NodeChecks is used to get all the checks for a node

func (*Health) ServiceChecks

func (h *Health) ServiceChecks(args *structs.ServiceSpecificRequest,
	reply *structs.IndexedHealthChecks) error

ServiceChecks is used to get all the checks for a service

func (*Health) ServiceNodes

ServiceNodes returns all the nodes registered as part of a service including health info

type IndexFunc

type IndexFunc func(*MDBIndex, []string) string

type Interface

type Interface interface {
	RPC(method string, args interface{}, reply interface{}) error
	LANMembers() []serf.Member
	LocalMember() serf.Member
}

Interface is used to provide either a Client or Server, both of which can be used to perform certain common Consul methods

type Internal added in v0.2.0

type Internal struct {
	// contains filtered or unexported fields
}

Internal endpoint is used to query the miscellaneous info that does not necessarily fit into the other systems. It is also used to hold undocumented APIs that users should not rely on.

func (*Internal) EventFire added in v0.4.0

func (m *Internal) EventFire(args *structs.EventFireRequest,
	reply *structs.EventFireResponse) error

EventFire is a bit of an odd endpoint, but it allows for a cross-DC RPC call to fire an event. The primary use case is to enable user events being triggered in a remote DC.

func (*Internal) KeyringOperation added in v0.5.0

func (m *Internal) KeyringOperation(
	args *structs.KeyringRequest,
	reply *structs.KeyringResponses) error

KeyringOperation will query the WAN and LAN gossip keyrings of all nodes.

func (*Internal) NodeDump added in v0.2.0

func (m *Internal) NodeDump(args *structs.DCSpecificRequest,
	reply *structs.IndexedNodeDump) error

ChecksInState is used to get all the checks in a given state

func (*Internal) NodeInfo added in v0.2.0

func (m *Internal) NodeInfo(args *structs.NodeSpecificRequest,
	reply *structs.IndexedNodeDump) error

ChecksInState is used to get all the checks in a given state

type KVS

type KVS struct {
	// contains filtered or unexported fields
}

KVS endpoint is used to manipulate the Key-Value store

func (*KVS) Apply

func (k *KVS) Apply(args *structs.KVSRequest, reply *bool) error

Apply is used to apply a KVS request to the data store. This should only be used for operations that modify the data

func (*KVS) Get

func (k *KVS) Get(args *structs.KeyRequest, reply *structs.IndexedDirEntries) error

Get is used to lookup a single key

func (*KVS) List

func (k *KVS) List(args *structs.KeyRequest, reply *structs.IndexedDirEntries) error

List is used to list all keys with a given prefix

func (*KVS) ListKeys added in v0.2.0

func (k *KVS) ListKeys(args *structs.KeyListRequest, reply *structs.IndexedKeyList) error

ListKeys is used to list all keys with a given prefix to a seperator

type MDBIndex

type MDBIndex struct {
	AllowBlank      bool      // Can fields be blank
	Unique          bool      // Controls if values are unique
	Fields          []string  // Fields are used to build the index
	IdxFunc         IndexFunc // Can be used to provide custom indexing
	Virtual         bool      // Virtual index does not exist, but can be used for queries
	RealIndex       string    // Virtual indexes use a RealIndex for iteration
	CaseInsensitive bool      // Controls if values are case-insensitive
	// contains filtered or unexported fields
}

An Index is named, and uses a series of column values to map to the row-id containing the table

type MDBTable

type MDBTable struct {
	Env     *mdb.Env
	Name    string // This is the name of the table, must be unique
	Indexes map[string]*MDBIndex
	Encoder func(interface{}) []byte
	Decoder func([]byte) interface{}
	// contains filtered or unexported fields
}

An MDB table is a logical representation of a table, which is a generic row store. It provides a simple mechanism to store rows using a row id, while maintaining any number of secondary indexes.

func (*MDBTable) Delete

func (t *MDBTable) Delete(index string, parts ...string) (num int, err error)

Delete is used to delete one or more rows. An index an appropriate fields are specified. The fields can be a prefix of the index. Returns the rows deleted or an error.

func (*MDBTable) DeleteTxn

func (t *MDBTable) DeleteTxn(tx *MDBTxn, index string, parts ...string) (int, error)

DeleteTxn is like Delete, but occurs in a specific transaction that can span multiple tables.

func (*MDBTable) Get

func (t *MDBTable) Get(index string, parts ...string) (uint64, []interface{}, error)

Get is used to lookup one or more rows. An index an appropriate fields are specified. The fields can be a prefix of the index.

func (*MDBTable) GetTxn

func (t *MDBTable) GetTxn(tx *MDBTxn, index string, parts ...string) ([]interface{}, error)

GetTxn is like Get but it operates within a specific transaction. This can be used for read that span multiple tables

func (*MDBTable) GetTxnLimit added in v0.5.0

func (t *MDBTable) GetTxnLimit(tx *MDBTxn, limit int, index string, parts ...string) ([]interface{}, error)

GetTxnLimit is like GetTxn limits the maximum number of rows it will return

func (*MDBTable) Init

func (t *MDBTable) Init() error

Init is used to initialize the MDBTable and ensure it's ready

func (*MDBTable) Insert

func (t *MDBTable) Insert(obj interface{}) error

Insert is used to insert or update an object

func (*MDBTable) InsertTxn

func (t *MDBTable) InsertTxn(tx *MDBTxn, obj interface{}) error

Insert is used to insert or update an object within a given transaction

func (*MDBTable) LastIndex

func (t *MDBTable) LastIndex() (uint64, error)

LastIndex is get the last index that updated the table

func (*MDBTable) LastIndexTxn

func (t *MDBTable) LastIndexTxn(tx *MDBTxn) (uint64, error)

LastIndexTxn is like LastIndex but it operates within a specific transaction.

func (*MDBTable) SetLastIndex

func (t *MDBTable) SetLastIndex(index uint64) error

SetLastIndex is used to set the last index that updated the table

func (*MDBTable) SetLastIndexTxn

func (t *MDBTable) SetLastIndexTxn(tx *MDBTxn, index uint64) error

SetLastIndexTxn is used to set the last index within a transaction

func (*MDBTable) SetMaxLastIndexTxn added in v0.3.0

func (t *MDBTable) SetMaxLastIndexTxn(tx *MDBTxn, index uint64) error

SetMaxLastIndexTxn is used to set the last index within a transaction if it exceeds the current maximum

func (*MDBTable) StartTxn

func (t *MDBTable) StartTxn(readonly bool, mdbTxn *MDBTxn) (*MDBTxn, error)

startTxn is used to start a transaction

func (*MDBTable) StreamTxn

func (t *MDBTable) StreamTxn(stream chan<- interface{}, tx *MDBTxn, index string, parts ...string) error

StreamTxn is like GetTxn but it streams the results over a channel. This can be used if the expected data set is very large. The stream is always closed on return.

type MDBTables

type MDBTables []*MDBTable

MDBTables is used for when we have a collection of tables

func (MDBTables) LastIndexTxn

func (t MDBTables) LastIndexTxn(tx *MDBTxn) (uint64, error)

LastIndexTxn is used to get the last transaction from all of the tables

func (MDBTables) StartTxn

func (t MDBTables) StartTxn(readonly bool) (*MDBTxn, error)

StartTxn is used to create a transaction that spans a list of tables

type MDBTxn

type MDBTxn struct {
	// contains filtered or unexported fields
}

MDBTxn is used to wrap an underlying transaction

func (*MDBTxn) Abort

func (t *MDBTxn) Abort()

Abort is used to close the transaction

func (*MDBTxn) Commit

func (t *MDBTxn) Commit() error

Commit is used to commit a transaction

func (*MDBTxn) Defer added in v0.3.0

func (t *MDBTxn) Defer(f func())

Defer is used to defer a function call until a successful commit

type NotifyGroup

type NotifyGroup struct {
	// contains filtered or unexported fields
}

NotifyGroup is used to allow a simple notification mechanism. Channels can be marked as waiting, and when notify is invoked, all the waiting channels get a message and are cleared from the notify list.

func (*NotifyGroup) Notify

func (n *NotifyGroup) Notify()

Notify will do a non-blocking send to all waiting channels, and clear the notify list

func (*NotifyGroup) Wait

func (n *NotifyGroup) Wait(ch chan struct{})

Wait adds a channel to the notify group

func (*NotifyGroup) WaitCh

func (n *NotifyGroup) WaitCh() chan struct{}

WaitCh allocates a channel that is subscribed to notifications

type RPCType

type RPCType byte

type RaftLayer

type RaftLayer struct {
	// contains filtered or unexported fields
}

RaftLayer implements the raft.StreamLayer interface, so that we can use a single RPC layer for Raft and Consul

func NewRaftLayer

func NewRaftLayer(addr net.Addr, tlsWrap tlsutil.Wrapper) *RaftLayer

NewRaftLayer is used to initialize a new RaftLayer which can be used as a StreamLayer for Raft. If a tlsConfig is provided, then the connection will use TLS.

func (*RaftLayer) Accept

func (l *RaftLayer) Accept() (net.Conn, error)

Accept is used to return connection which are dialed to be used with the Raft layer

func (*RaftLayer) Addr

func (l *RaftLayer) Addr() net.Addr

Addr is used to return the address of the listener

func (*RaftLayer) Close

func (l *RaftLayer) Close() error

Close is used to stop listening for Raft connections

func (*RaftLayer) Dial

func (l *RaftLayer) Dial(address string, timeout time.Duration) (net.Conn, error)

Dial is used to create a new outgoing connection

func (*RaftLayer) Handoff

func (l *RaftLayer) Handoff(c net.Conn) error

Handoff is used to hand off a connection to the RaftLayer. This allows it to be Accept()'ed

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is Consul server which manages the service discovery, health checking, DC forwarding, Raft, and multiple Serf pools.

func NewServer

func NewServer(config *Config) (*Server, error)

NewServer is used to construct a new Consul server from the configuration, potentially returning an error

func (*Server) Encrypted added in v0.5.0

func (s *Server) Encrypted() bool

Encrypted determines if gossip is encrypted

func (*Server) IsLeader

func (s *Server) IsLeader() bool

IsLeader checks if this server is the cluster leader

func (*Server) JoinLAN

func (s *Server) JoinLAN(addrs []string) (int, error)

JoinLAN is used to have Consul join the inner-DC pool The target address should be another node inside the DC listening on the Serf LAN address

func (*Server) JoinWAN

func (s *Server) JoinWAN(addrs []string) (int, error)

JoinWAN is used to have Consul join the cross-WAN Consul ring The target address should be another node listening on the Serf WAN address

func (*Server) KeyManagerLAN added in v0.5.0

func (s *Server) KeyManagerLAN() *serf.KeyManager

KeyManagerLAN returns the LAN Serf keyring manager

func (*Server) KeyManagerWAN added in v0.5.0

func (s *Server) KeyManagerWAN() *serf.KeyManager

KeyManagerWAN returns the WAN Serf keyring manager

func (*Server) LANMembers

func (s *Server) LANMembers() []serf.Member

LANMembers is used to return the members of the LAN cluster

func (*Server) Leave

func (s *Server) Leave() error

Leave is used to prepare for a graceful shutdown of the server

func (*Server) LocalMember added in v0.3.0

func (c *Server) LocalMember() serf.Member

LocalMember is used to return the local node

func (*Server) RPC

func (s *Server) RPC(method string, args interface{}, reply interface{}) error

RPC is used to make a local RPC call

func (*Server) RemoveFailedNode

func (s *Server) RemoveFailedNode(node string) error

RemoveFailedNode is used to remove a failed node from the cluster

func (*Server) Shutdown

func (s *Server) Shutdown() error

Shutdown is used to shutdown the server

func (*Server) Stats

func (s *Server) Stats() map[string]map[string]string

Stats is used to return statistics for debugging and insight for various sub-systems

func (*Server) UserEvent added in v0.4.0

func (s *Server) UserEvent(name string, payload []byte) error

UserEvent is used to fire an event via the Serf layer on the LAN

func (*Server) WANMembers

func (s *Server) WANMembers() []serf.Member

WANMembers is used to return the members of the LAN cluster

type Session added in v0.3.0

type Session struct {
	// contains filtered or unexported fields
}

Session endpoint is used to manipulate sessions for KV

func (*Session) Apply added in v0.3.0

func (s *Session) Apply(args *structs.SessionRequest, reply *string) error

Apply is used to apply a modifying request to the data store. This should only be used for operations that modify the data

func (*Session) Get added in v0.3.0

Get is used to retrieve a single session

func (*Session) List added in v0.3.0

List is used to list all the active sessions

func (*Session) NodeSessions added in v0.3.0

func (s *Session) NodeSessions(args *structs.NodeSpecificRequest,
	reply *structs.IndexedSessions) error

NodeSessions is used to get all the sessions for a particular node

func (*Session) Renew added in v0.5.0

Renew is used to renew the TTL on a single session

type StateSnapshot

type StateSnapshot struct {
	// contains filtered or unexported fields
}

StateSnapshot is used to provide a point-in-time snapshot It works by starting a readonly transaction against all tables.

func (*StateSnapshot) ACLList added in v0.4.0

func (s *StateSnapshot) ACLList() ([]*structs.ACL, error)

ACLList is used to list all of the ACLs

func (*StateSnapshot) Close

func (s *StateSnapshot) Close() error

Close is used to abort the transaction and allow for cleanup

func (*StateSnapshot) KVSDump

func (s *StateSnapshot) KVSDump(stream chan<- interface{}) error

KVSDump is used to list all KV entries. It takes a channel and streams back *struct.DirEntry objects. This will block and should be invoked in a goroutine.

func (*StateSnapshot) LastIndex

func (s *StateSnapshot) LastIndex() uint64

LastIndex returns the last index that affects the snapshotted data

func (*StateSnapshot) NodeChecks

func (s *StateSnapshot) NodeChecks(node string) structs.HealthChecks

NodeChecks is used to return all the checks of a given node

func (*StateSnapshot) NodeServices

func (s *StateSnapshot) NodeServices(name string) *structs.NodeServices

NodeServices is used to return all the services of a given node

func (*StateSnapshot) Nodes

func (s *StateSnapshot) Nodes() structs.Nodes

Nodes returns all the known nodes, the slice alternates between the node name and address

func (*StateSnapshot) SessionList added in v0.3.0

func (s *StateSnapshot) SessionList() ([]*structs.Session, error)

SessionList is used to list all the open sessions

func (*StateSnapshot) TombstoneDump added in v0.5.0

func (s *StateSnapshot) TombstoneDump(stream chan<- interface{}) error

TombstoneDump is used to dump all tombstone entries. It takes a channel and streams back *struct.DirEntry objects. This will block and should be invoked in a goroutine.

type StateStore

type StateStore struct {
	// contains filtered or unexported fields
}

The StateStore is responsible for maintaining all the Consul state. It is manipulated by the FSM which maintains consistency through the use of Raft. The goals of the StateStore are to provide high concurrency for read operations without blocking writes, and to provide write availability in the face of reads. The current implementation uses the Lightning Memory-Mapped Database (MDB). This gives us Multi-Version Concurrency Control for "free"

func NewStateStore

func NewStateStore(gc *TombstoneGC, logOutput io.Writer) (*StateStore, error)

NewStateStore is used to create a new state store

func NewStateStorePath added in v0.4.1

func NewStateStorePath(gc *TombstoneGC, path string, logOutput io.Writer) (*StateStore, error)

NewStateStorePath is used to create a new state store at a given path The path is cleared on closing.

func (*StateStore) ACLDelete added in v0.4.0

func (s *StateStore) ACLDelete(index uint64, id string) error

ACLDelete is used to remove an ACL

func (*StateStore) ACLGet added in v0.4.0

func (s *StateStore) ACLGet(id string) (uint64, *structs.ACL, error)

ACLGet is used to get an ACL by ID

func (*StateStore) ACLList added in v0.4.0

func (s *StateStore) ACLList() (uint64, []*structs.ACL, error)

ACLList is used to list all the acls

func (*StateStore) ACLRestore added in v0.4.0

func (s *StateStore) ACLRestore(acl *structs.ACL) error

ACLRestore is used to restore an ACL. It should only be used when doing a restore, otherwise ACLSet should be used.

func (*StateStore) ACLSet added in v0.4.0

func (s *StateStore) ACLSet(index uint64, acl *structs.ACL) error

ACLSet is used to create or update an ACL entry

func (*StateStore) CheckServiceNodes

func (s *StateStore) CheckServiceNodes(service string) (uint64, structs.CheckServiceNodes)

CheckServiceNodes returns the nodes associated with a given service, along with any associated check

func (*StateStore) CheckServiceTagNodes

func (s *StateStore) CheckServiceTagNodes(service, tag string) (uint64, structs.CheckServiceNodes)

CheckServiceNodes returns the nodes associated with a given service, along with any associated checks

func (*StateStore) ChecksInState

func (s *StateStore) ChecksInState(state string) (uint64, structs.HealthChecks)

CheckInState is used to get all the checks for a service in a given state

func (*StateStore) Close

func (s *StateStore) Close() error

Close is used to safely shutdown the state store

func (*StateStore) DeleteNode

func (s *StateStore) DeleteNode(index uint64, node string) error

DeleteNode is used to delete a node and all it's services

func (*StateStore) DeleteNodeCheck

func (s *StateStore) DeleteNodeCheck(index uint64, node, id string) error

DeleteNodeCheck is used to delete a node health check

func (*StateStore) DeleteNodeService

func (s *StateStore) DeleteNodeService(index uint64, node, id string) error

DeleteNodeService is used to delete a node service

func (*StateStore) EnsureCheck

func (s *StateStore) EnsureCheck(index uint64, check *structs.HealthCheck) error

EnsureCheck is used to create a check or updates it's state

func (*StateStore) EnsureNode

func (s *StateStore) EnsureNode(index uint64, node structs.Node) error

EnsureNode is used to ensure a given node exists, with the provided address

func (*StateStore) EnsureRegistration added in v0.4.0

func (s *StateStore) EnsureRegistration(index uint64, req *structs.RegisterRequest) error

EnsureRegistration is used to make sure a node, service, and check registration is performed within a single transaction to avoid race conditions on state updates.

func (*StateStore) EnsureService

func (s *StateStore) EnsureService(index uint64, node string, ns *structs.NodeService) error

EnsureService is used to ensure a given node exposes a service

func (*StateStore) GetNode

func (s *StateStore) GetNode(name string) (uint64, bool, string)

GetNode returns all the address of the known and if it was found

func (*StateStore) KVSCheckAndSet

func (s *StateStore) KVSCheckAndSet(index uint64, d *structs.DirEntry) (bool, error)

KVSCheckAndSet is used to perform an atomic check-and-set

func (*StateStore) KVSDelete

func (s *StateStore) KVSDelete(index uint64, key string) error

KVSDelete is used to delete a KVS entry

func (*StateStore) KVSDeleteCheckAndSet added in v0.5.0

func (s *StateStore) KVSDeleteCheckAndSet(index uint64, key string, casIndex uint64) (bool, error)

KVSDeleteCheckAndSet is used to perform an atomic delete check-and-set

func (*StateStore) KVSDeleteTree

func (s *StateStore) KVSDeleteTree(index uint64, prefix string) error

KVSDeleteTree is used to delete all keys with a given prefix

func (*StateStore) KVSGet

func (s *StateStore) KVSGet(key string) (uint64, *structs.DirEntry, error)

KVSGet is used to get a KV entry

func (*StateStore) KVSList

func (s *StateStore) KVSList(prefix string) (uint64, uint64, structs.DirEntries, error)

KVSList is used to list all KV entries with a prefix

func (*StateStore) KVSListKeys added in v0.2.0

func (s *StateStore) KVSListKeys(prefix, seperator string) (uint64, []string, error)

KVSListKeys is used to list keys with a prefix, and up to a given seperator

func (*StateStore) KVSLock added in v0.3.0

func (s *StateStore) KVSLock(index uint64, d *structs.DirEntry) (bool, error)

KVSLock works like KVSSet but only writes if the lock can be acquired

func (*StateStore) KVSLockDelay added in v0.3.0

func (s *StateStore) KVSLockDelay(key string) time.Time

KVSLockDelay returns the expiration time of a key lock delay. A key may have a lock delay if it was unlocked due to a session invalidation instead of a graceful unlock. This must be checked on the leader node, and not in KVSLock due to the variability of clocks.

func (*StateStore) KVSRestore

func (s *StateStore) KVSRestore(d *structs.DirEntry) error

KVSRestore is used to restore a DirEntry. It should only be used when doing a restore, otherwise KVSSet should be used.

func (*StateStore) KVSSet

func (s *StateStore) KVSSet(index uint64, d *structs.DirEntry) error

KVSSet is used to create or update a KV entry

func (*StateStore) KVSUnlock added in v0.3.0

func (s *StateStore) KVSUnlock(index uint64, d *structs.DirEntry) (bool, error)

KVSUnlock works like KVSSet but only writes if the lock can be unlocked

func (*StateStore) NodeChecks

func (s *StateStore) NodeChecks(node string) (uint64, structs.HealthChecks)

NodeChecks is used to get all the checks for a node

func (*StateStore) NodeDump added in v0.2.0

func (s *StateStore) NodeDump() (uint64, structs.NodeDump)

NodeDump is used to generate the NodeInfo for all nodes. This is very expensive, and should generally be avoided for programatic access.

func (*StateStore) NodeInfo added in v0.2.0

func (s *StateStore) NodeInfo(node string) (uint64, structs.NodeDump)

NodeInfo is used to generate the full info about a node.

func (*StateStore) NodeServices

func (s *StateStore) NodeServices(name string) (uint64, *structs.NodeServices)

NodeServices is used to return all the services of a given node

func (*StateStore) NodeSessions added in v0.3.0

func (s *StateStore) NodeSessions(node string) (uint64, []*structs.Session, error)

NodeSessions is used to list all the open sessions for a node

func (*StateStore) Nodes

func (s *StateStore) Nodes() (uint64, structs.Nodes)

GetNodes returns all the known nodes, the slice alternates between the node name and address

func (*StateStore) QueryTables

func (s *StateStore) QueryTables(q string) MDBTables

QueryTables returns the Tables that are queried for a given query

func (*StateStore) ReapTombstones added in v0.5.0

func (s *StateStore) ReapTombstones(index uint64) error

ReapTombstones is used to delete all the tombstones with a ModifyTime less than or equal to the given index. This is used to prevent unbounded storage growth of the tombstones.

func (*StateStore) ServiceChecks

func (s *StateStore) ServiceChecks(service string) (uint64, structs.HealthChecks)

ServiceChecks is used to get all the checks for a service

func (*StateStore) ServiceNodes

func (s *StateStore) ServiceNodes(service string) (uint64, structs.ServiceNodes)

ServiceNodes returns the nodes associated with a given service

func (*StateStore) ServiceTagNodes

func (s *StateStore) ServiceTagNodes(service, tag string) (uint64, structs.ServiceNodes)

ServiceTagNodes returns the nodes associated with a given service matching a tag

func (*StateStore) Services

func (s *StateStore) Services() (uint64, map[string][]string)

Services is used to return all the services with a list of associated tags

func (*StateStore) SessionCreate added in v0.3.0

func (s *StateStore) SessionCreate(index uint64, session *structs.Session) error

SessionCreate is used to create a new session. The ID will be populated on a successful return

func (*StateStore) SessionDestroy added in v0.3.0

func (s *StateStore) SessionDestroy(index uint64, id string) error

SessionDestroy is used to destroy a session.

func (*StateStore) SessionGet added in v0.3.0

func (s *StateStore) SessionGet(id string) (uint64, *structs.Session, error)

SessionGet is used to get a session entry

func (*StateStore) SessionList added in v0.3.0

func (s *StateStore) SessionList() (uint64, []*structs.Session, error)

SessionList is used to list all the open sessions

func (*StateStore) SessionRestore added in v0.3.0

func (s *StateStore) SessionRestore(session *structs.Session) error

SessionRestore is used to restore a session. It should only be used when doing a restore, otherwise SessionCreate should be used.

func (*StateStore) Snapshot

func (s *StateStore) Snapshot() (*StateSnapshot, error)

Snapshot is used to create a point in time snapshot

func (*StateStore) TombstoneRestore added in v0.5.0

func (s *StateStore) TombstoneRestore(d *structs.DirEntry) error

TombstoneRestore is used to restore a tombstone. It should only be used when doing a restore.

func (*StateStore) Watch

func (s *StateStore) Watch(tables MDBTables, notify chan struct{})

Watch is used to subscribe a channel to a set of MDBTables

func (*StateStore) WatchKV added in v0.5.0

func (s *StateStore) WatchKV(prefix string, notify chan struct{})

WatchKV is used to subscribe a channel to changes in KV data

type Status

type Status struct {
	// contains filtered or unexported fields
}

Status endpoint is used to check on server status

func (*Status) Leader

func (s *Status) Leader(args struct{}, reply *string) error

Leader is used to get the address of the leader

func (*Status) Peers

func (s *Status) Peers(args struct{}, reply *[]string) error

Peers is used to get all the Raft peers

func (*Status) Ping

func (s *Status) Ping(args struct{}, reply *struct{}) error

Ping is used to just check for connectivity

type StreamClient added in v0.3.0

type StreamClient struct {
	// contains filtered or unexported fields
}

streamClient is used to wrap a stream with an RPC client

func (*StreamClient) Close added in v0.5.1

func (sc *StreamClient) Close()

type TombstoneGC added in v0.5.0

type TombstoneGC struct {
	// contains filtered or unexported fields
}

TombstoneGC is used to track creation of tombstones so that they can be garbage collected after their TTL expires. The tombstones allow queries to provide monotonic index values within the TTL window. The GC is used to prevent monotonic growth in storage usage. This is a trade off between the length of the TTL and the storage overhead.

In practice, this is required to fix the issue of delete visibility. When data is deleted from the KV store, the "latest" row can go backwards if the newest row is removed. The tombstones provide a way to ensure time doesn't move backwards within some interval.

func NewTombstoneGC added in v0.5.0

func NewTombstoneGC(ttl, granularity time.Duration) (*TombstoneGC, error)

NewTombstoneGC is used to construct a new TombstoneGC given a TTL for tombstones and a tracking granularity. Longer TTLs ensure correct behavior for more time, but use more storage. A shorter granularity increases the number of Raft transactions and reduce how far past the TTL we perform GC.

func (*TombstoneGC) ExpireCh added in v0.5.0

func (t *TombstoneGC) ExpireCh() <-chan uint64

ExpireCh is used to return a channel that streams the next index that should be expired

func (*TombstoneGC) Hint added in v0.5.0

func (t *TombstoneGC) Hint(index uint64)

Hint is used to indicate that keys at the given index have been deleted, and that their GC should be scheduled.

func (*TombstoneGC) PendingExpiration added in v0.5.0

func (t *TombstoneGC) PendingExpiration() bool

PendingExpiration is used to check if any expirations are pending

func (*TombstoneGC) SetEnabled added in v0.5.0

func (t *TombstoneGC) SetEnabled(enabled bool)

SetEnabled is used to control if the tombstone GC is enabled. Should only be enabled by the leader node.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL