state

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: May 9, 2017 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingNode is the error returned when trying an operation
	// which requires a node registration but none exists.
	ErrMissingNode = errors.New("Missing node registration")

	// ErrMissingService is the error we return if trying an
	// operation which requires a service but none exists.
	ErrMissingService = errors.New("Missing service registration")

	// ErrMissingSessionID is returned when a session registration
	// is attempted with an empty session ID.
	ErrMissingSessionID = errors.New("Missing session ID")

	// ErrMissingACLID is returned when an ACL set is called on
	// an ACL with an empty ID.
	ErrMissingACLID = errors.New("Missing ACL ID")

	// ErrMissingQueryID is returned when a Query set is called on
	// a Query with an empty ID.
	ErrMissingQueryID = errors.New("Missing Query ID")
)

Functions

This section is empty.

Types

type Delay

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

Delay is used to mark certain locks as unacquirable. When a lock is forcefully released (failing health check, destroyed session, etc.), it is subject to the LockDelay impossed by the session. This prevents another session from acquiring the lock for some period of time as a protection against split-brains. This is inspired by the lock-delay in Chubby. Because this relies on wall-time, we cannot assume all peers perceive time as flowing uniformly. This means KVSLock MUST ignore lockDelay, since the lockDelay may have expired on the leader, but not on the follower. Rejecting the lock could result in inconsistencies in the FSMs due to the rate time progresses. Instead, only the opinion of the leader is respected, and the Raft log is never questioned.

func NewDelay

func NewDelay() *Delay

NewDelay returns a new delay manager.

func (*Delay) GetExpiration

func (d *Delay) GetExpiration(key string) time.Time

GetExpiration returns the expiration time of a key lock delay. This must be checked on the leader node, and not in KVSLock due to the variability of clocks.

func (*Delay) SetExpiration

func (d *Delay) SetExpiration(key string, now time.Time, delay time.Duration)

SetExpiration sets the expiration time for the lock delay to the given delay from the given now time.

type Graveyard

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

Graveyard manages a set of tombstones.

func NewGraveyard

func NewGraveyard(gc *TombstoneGC) *Graveyard

NewGraveyard returns a new graveyard.

func (*Graveyard) DumpTxn

func (g *Graveyard) DumpTxn(tx *memdb.Txn) (memdb.ResultIterator, error)

DumpTxn returns all the tombstones.

func (*Graveyard) GetMaxIndexTxn

func (g *Graveyard) GetMaxIndexTxn(tx *memdb.Txn, prefix string) (uint64, error)

GetMaxIndexTxn returns the highest index tombstone whose key matches the given context, using a prefix match.

func (*Graveyard) InsertTxn

func (g *Graveyard) InsertTxn(tx *memdb.Txn, key string, idx uint64) error

InsertTxn adds a new tombstone.

func (*Graveyard) ReapTxn

func (g *Graveyard) ReapTxn(tx *memdb.Txn, idx uint64) error

ReapTxn cleans out all tombstones whose index values are less than or equal to the given idx. This prevents unbounded storage growth of the tombstones.

func (*Graveyard) RestoreTxn

func (g *Graveyard) RestoreTxn(tx *memdb.Txn, stone *Tombstone) error

RestoreTxn is used when restoring from a snapshot. For general inserts, use InsertTxn.

type IndexEntry

type IndexEntry struct {
	Key   string
	Value uint64
}

IndexEntry keeps a record of the last index per-table.

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) Clear

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

Clear removes a channel from the notify group

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 PreparedQueryIndex added in v0.6.4

type PreparedQueryIndex struct {
}

PreparedQueryIndex is a custom memdb indexer used to manage index prepared query templates. None of the built-in indexers do what we need, and our use case is pretty specific so it's better to put the logic here.

func (*PreparedQueryIndex) FromArgs added in v0.6.4

func (p *PreparedQueryIndex) FromArgs(args ...interface{}) ([]byte, error)

FromArgs is used when querying for an exact match. Since we don't add any suffix we can just call the prefix version.

func (*PreparedQueryIndex) FromObject added in v0.6.4

func (*PreparedQueryIndex) FromObject(obj interface{}) (bool, []byte, error)

FromObject is used to compute the index key when inserting or updating an object.

func (*PreparedQueryIndex) PrefixFromArgs added in v0.6.4

func (*PreparedQueryIndex) PrefixFromArgs(args ...interface{}) ([]byte, error)

PrefixFromArgs is used when doing a prefix scan for an object.

type Restore added in v0.8.2

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

Restore is used to efficiently manage restoring a large amount of data to a state store.

func (*Restore) ACL added in v0.8.2

func (s *Restore) ACL(acl *structs.ACL) error

ACL is used when restoring from a snapshot. For general inserts, use ACLSet.

func (*Restore) Abort added in v0.8.2

func (s *Restore) Abort()

Abort abandons the changes made by a restore. This or Commit should always be called.

func (*Restore) Autopilot added in v0.8.2

func (s *Restore) Autopilot(config *structs.AutopilotConfig) error

Autopilot is used when restoring from a snapshot.

func (*Restore) Commit added in v0.8.2

func (s *Restore) Commit()

Commit commits the changes made by a restore. This or Abort should always be called.

func (*Restore) Coordinates added in v0.8.2

func (s *Restore) Coordinates(idx uint64, updates structs.Coordinates) error

Coordinates is used when restoring from a snapshot. For general inserts, use CoordinateBatchUpdate. We do less vetting of the updates here because they already got checked on the way in during a batch update.

func (*Restore) KVS added in v0.8.2

func (s *Restore) KVS(entry *structs.DirEntry) error

KVS is used when restoring from a snapshot. Use KVSSet for general inserts.

func (*Restore) PreparedQuery added in v0.8.2

func (s *Restore) PreparedQuery(query *structs.PreparedQuery) error

PreparedQuery is used when restoring from a snapshot. For general inserts, use PreparedQuerySet.

func (*Restore) Registration added in v0.8.2

func (s *Restore) Registration(idx uint64, req *structs.RegisterRequest) error

Registration 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 (*Restore) Session added in v0.8.2

func (s *Restore) Session(sess *structs.Session) error

Session is used when restoring from a snapshot. For general inserts, use SessionCreate.

func (*Restore) Tombstone added in v0.8.2

func (s *Restore) Tombstone(stone *Tombstone) error

Tombstone is used when restoring from a snapshot. For general inserts, use Graveyard.InsertTxn.

type Snapshot added in v0.8.2

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

Snapshot is used to provide a point-in-time snapshot. It works by starting a read transaction against the whole state store.

func (*Snapshot) ACLs added in v0.8.2

func (s *Snapshot) ACLs() (memdb.ResultIterator, error)

ACLs is used to pull all the ACLs from the snapshot.

func (*Snapshot) Autopilot added in v0.8.2

func (s *Snapshot) Autopilot() (*structs.AutopilotConfig, error)

Autopilot is used to pull the autopilot config from the snapshot.

func (*Snapshot) Checks added in v0.8.2

func (s *Snapshot) Checks(node string) (memdb.ResultIterator, error)

Checks is used to pull the full list of checks for a given node for use during snapshots.

func (*Snapshot) Close added in v0.8.2

func (s *Snapshot) Close()

Close performs cleanup of a state snapshot.

func (*Snapshot) Coordinates added in v0.8.2

func (s *Snapshot) Coordinates() (memdb.ResultIterator, error)

Coordinates is used to pull all the coordinates from the snapshot.

func (*Snapshot) KVs added in v0.8.2

func (s *Snapshot) KVs() (memdb.ResultIterator, error)

KVs is used to pull the full list of KVS entries for use during snapshots.

func (*Snapshot) LastIndex added in v0.8.2

func (s *Snapshot) LastIndex() uint64

LastIndex returns that last index that affects the snapshotted data.

func (*Snapshot) Nodes added in v0.8.2

func (s *Snapshot) Nodes() (memdb.ResultIterator, error)

Nodes is used to pull the full list of nodes for use during snapshots.

func (*Snapshot) PreparedQueries added in v0.8.2

func (s *Snapshot) PreparedQueries() (structs.PreparedQueries, error)

PreparedQueries is used to pull all the prepared queries from the snapshot.

func (*Snapshot) Services added in v0.8.2

func (s *Snapshot) Services(node string) (memdb.ResultIterator, error)

Services is used to pull the full list of services for a given node for use during snapshots.

func (*Snapshot) Sessions added in v0.8.2

func (s *Snapshot) Sessions() (memdb.ResultIterator, error)

Sessions is used to pull the full list of sessions for use during snapshots.

func (*Snapshot) Tombstones added in v0.8.2

func (s *Snapshot) Tombstones() (memdb.ResultIterator, error)

Tombstones is used to pull all the tombstones from the graveyard.

type Store added in v0.8.2

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

Store is where we store all of Consul's state, including records of node registrations, services, checks, key/value pairs and more. The DB is entirely in-memory and is constructed from the Raft log through the FSM.

func NewStateStore

func NewStateStore(gc *TombstoneGC) (*Store, error)

NewStateStore creates a new in-memory state storage layer.

func (*Store) ACLDelete added in v0.8.2

func (s *Store) ACLDelete(idx uint64, aclID string) error

ACLDelete is used to remove an existing ACL from the state store. If the ACL does not exist this is a no-op and no error is returned.

func (*Store) ACLGet added in v0.8.2

func (s *Store) ACLGet(ws memdb.WatchSet, aclID string) (uint64, *structs.ACL, error)

ACLGet is used to look up an existing ACL by ID.

func (*Store) ACLList added in v0.8.2

func (s *Store) ACLList(ws memdb.WatchSet) (uint64, structs.ACLs, error)

ACLList is used to list out all of the ACLs in the state store.

func (*Store) ACLSet added in v0.8.2

func (s *Store) ACLSet(idx uint64, acl *structs.ACL) error

ACLSet is used to insert an ACL rule into the state store.

func (*Store) Abandon added in v0.8.2

func (s *Store) Abandon()

Abandon is used to signal that the given state store has been abandoned. Calling this more than one time will panic.

func (*Store) AbandonCh added in v0.8.2

func (s *Store) AbandonCh() <-chan struct{}

AbandonCh returns a channel you can wait on to know if the state store was abandoned.

func (*Store) AutopilotCASConfig added in v0.8.2

func (s *Store) AutopilotCASConfig(idx, cidx uint64, config *structs.AutopilotConfig) (bool, error)

AutopilotCASConfig is used to try updating the Autopilot configuration with a given Raft index. If the CAS index specified is not equal to the last observed index for the config, then the call is a noop,

func (*Store) AutopilotConfig added in v0.8.2

func (s *Store) AutopilotConfig() (uint64, *structs.AutopilotConfig, error)

AutopilotConfig is used to get the current Autopilot configuration.

func (*Store) AutopilotSetConfig added in v0.8.2

func (s *Store) AutopilotSetConfig(idx uint64, config *structs.AutopilotConfig) error

AutopilotSetConfig is used to set the current Autopilot configuration.

func (*Store) CheckServiceNodes added in v0.8.2

func (s *Store) CheckServiceNodes(ws memdb.WatchSet, serviceName string) (uint64, structs.CheckServiceNodes, error)

CheckServiceNodes is used to query all nodes and checks for a given service.

func (*Store) CheckServiceTagNodes added in v0.8.2

func (s *Store) CheckServiceTagNodes(ws memdb.WatchSet, serviceName, tag string) (uint64, structs.CheckServiceNodes, error)

CheckServiceTagNodes is used to query all nodes and checks for a given service, filtering out services that don't contain the given tag.

func (*Store) ChecksInState added in v0.8.2

func (s *Store) ChecksInState(ws memdb.WatchSet, state string) (uint64, structs.HealthChecks, error)

ChecksInState is used to query the state store for all checks which are in the provided state.

func (*Store) ChecksInStateByNodeMeta added in v0.8.2

func (s *Store) ChecksInStateByNodeMeta(ws memdb.WatchSet, state string, filters map[string]string) (uint64, structs.HealthChecks, error)

ChecksInStateByNodeMeta is used to query the state store for all checks which are in the provided state, filtered by the given node metadata values.

func (*Store) CoordinateBatchUpdate added in v0.8.2

func (s *Store) CoordinateBatchUpdate(idx uint64, updates structs.Coordinates) error

CoordinateBatchUpdate processes a batch of coordinate updates and applies them in a single transaction.

func (*Store) CoordinateGetRaw added in v0.8.2

func (s *Store) CoordinateGetRaw(node string) (*coordinate.Coordinate, error)

CoordinateGetRaw queries for the coordinate of the given node. This is an unusual state store method because it just returns the raw coordinate or nil, none of the Raft or node information is returned. This hits the 90% internal-to-Consul use case for this data, and this isn't exposed via an endpoint, so it doesn't matter that the Raft info isn't available.

func (*Store) Coordinates added in v0.8.2

func (s *Store) Coordinates(ws memdb.WatchSet) (uint64, structs.Coordinates, error)

Coordinates queries for all nodes with coordinates.

func (*Store) DeleteCheck added in v0.8.2

func (s *Store) DeleteCheck(idx uint64, node string, checkID types.CheckID) error

DeleteCheck is used to delete a health check registration.

func (*Store) DeleteNode added in v0.8.2

func (s *Store) DeleteNode(idx uint64, nodeName string) error

DeleteNode is used to delete a given node by its ID.

func (*Store) DeleteService added in v0.8.2

func (s *Store) DeleteService(idx uint64, nodeName, serviceID string) error

DeleteService is used to delete a given service associated with a node.

func (*Store) EnsureCheck added in v0.8.2

func (s *Store) EnsureCheck(idx uint64, hc *structs.HealthCheck) error

EnsureCheck is used to store a check registration in the db.

func (*Store) EnsureNode added in v0.8.2

func (s *Store) EnsureNode(idx uint64, node *structs.Node) error

EnsureNode is used to upsert node registration or modification.

func (*Store) EnsureRegistration added in v0.8.2

func (s *Store) EnsureRegistration(idx 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 (*Store) EnsureService added in v0.8.2

func (s *Store) EnsureService(idx uint64, node string, svc *structs.NodeService) error

EnsureService is called to upsert creation of a given NodeService.

func (*Store) GetNode added in v0.8.2

func (s *Store) GetNode(id string) (uint64, *structs.Node, error)

GetNode is used to retrieve a node registration by node name ID.

func (*Store) GetNodeID added in v0.8.2

func (s *Store) GetNodeID(id types.NodeID) (uint64, *structs.Node, error)

GetNodeID is used to retrieve a node registration by node ID.

func (*Store) KVSDelete added in v0.8.2

func (s *Store) KVSDelete(idx uint64, key string) error

KVSDelete is used to perform a shallow delete on a single key in the the state store.

func (*Store) KVSDeleteCAS added in v0.8.2

func (s *Store) KVSDeleteCAS(idx, cidx uint64, key string) (bool, error)

KVSDeleteCAS is used to try doing a KV delete operation with a given raft index. If the CAS index specified is not equal to the last observed index for the given key, then the call is a noop, otherwise a normal KV delete is invoked.

func (*Store) KVSDeleteTree added in v0.8.2

func (s *Store) KVSDeleteTree(idx uint64, prefix string) error

KVSDeleteTree is used to do a recursive delete on a key prefix in the state store. If any keys are modified, the last index is set, otherwise this is a no-op.

func (*Store) KVSGet added in v0.8.2

func (s *Store) KVSGet(ws memdb.WatchSet, key string) (uint64, *structs.DirEntry, error)

KVSGet is used to retrieve a key/value pair from the state store.

func (*Store) KVSList added in v0.8.2

func (s *Store) KVSList(ws memdb.WatchSet, prefix string) (uint64, structs.DirEntries, error)

KVSList is used to list out all keys under a given prefix. If the prefix is left empty, all keys in the KVS will be returned. The returned is the max index of the returned kvs entries or applicable tombstones, or else it's the full table indexes for kvs and tombstones.

func (*Store) KVSListKeys added in v0.8.2

func (s *Store) KVSListKeys(ws memdb.WatchSet, prefix, sep string) (uint64, []string, error)

KVSListKeys is used to query the KV store for keys matching the given prefix. An optional separator may be specified, which can be used to slice off a part of the response so that only a subset of the prefix is returned. In this mode, the keys which are omitted are still counted in the returned index.

func (*Store) KVSLock added in v0.8.2

func (s *Store) KVSLock(idx uint64, entry *structs.DirEntry) (bool, error)

KVSLock is similar to KVSSet but only performs the set if the lock can be acquired.

func (*Store) KVSLockDelay added in v0.8.2

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

KVSLockDelay returns the expiration time for any lock delay associated with the given key.

func (*Store) KVSSet added in v0.8.2

func (s *Store) KVSSet(idx uint64, entry *structs.DirEntry) error

KVSSet is used to store a key/value pair.

func (*Store) KVSSetCAS added in v0.8.2

func (s *Store) KVSSetCAS(idx uint64, entry *structs.DirEntry) (bool, error)

KVSSetCAS is used to do a check-and-set operation on a KV entry. The ModifyIndex in the provided entry is used to determine if we should write the entry to the state store or bail. Returns a bool indicating if a write happened and any error.

func (*Store) KVSUnlock added in v0.8.2

func (s *Store) KVSUnlock(idx uint64, entry *structs.DirEntry) (bool, error)

KVSUnlock is similar to KVSSet but only performs the set if the lock can be unlocked (the key must already exist and be locked).

func (*Store) NodeCheck added in v0.8.2

func (s *Store) NodeCheck(nodeName string, checkID types.CheckID) (uint64, *structs.HealthCheck, error)

NodeCheck is used to retrieve a specific check associated with the given node.

func (*Store) NodeChecks added in v0.8.2

func (s *Store) NodeChecks(ws memdb.WatchSet, nodeName string) (uint64, structs.HealthChecks, error)

NodeChecks is used to retrieve checks associated with the given node from the state store.

func (*Store) NodeDump added in v0.8.2

func (s *Store) NodeDump(ws memdb.WatchSet) (uint64, structs.NodeDump, error)

NodeDump is used to generate a dump of all nodes. This call is expensive as it has to query every node, service, and check. The response can also be quite large since there is currently no filtering applied.

func (*Store) NodeInfo added in v0.8.2

func (s *Store) NodeInfo(ws memdb.WatchSet, node string) (uint64, structs.NodeDump, error)

NodeInfo is used to generate a dump of a single node. The dump includes all services and checks which are registered against the node.

func (*Store) NodeService added in v0.8.2

func (s *Store) NodeService(nodeName string, serviceID string) (uint64, *structs.NodeService, error)

NodeService is used to retrieve a specific service associated with the given node.

func (*Store) NodeServices added in v0.8.2

func (s *Store) NodeServices(ws memdb.WatchSet, nodeNameOrID string) (uint64, *structs.NodeServices, error)

NodeServices is used to query service registrations by node name or UUID.

func (*Store) NodeSessions added in v0.8.2

func (s *Store) NodeSessions(ws memdb.WatchSet, nodeID string) (uint64, structs.Sessions, error)

NodeSessions returns a set of active sessions associated with the given node ID. The returned index is the highest index seen from the result set.

func (*Store) Nodes added in v0.8.2

func (s *Store) Nodes(ws memdb.WatchSet) (uint64, structs.Nodes, error)

Nodes is used to return all of the known nodes.

func (*Store) NodesByMeta added in v0.8.2

func (s *Store) NodesByMeta(ws memdb.WatchSet, filters map[string]string) (uint64, structs.Nodes, error)

NodesByMeta is used to return all nodes with the given metadata key/value pairs.

func (*Store) PreparedQueryDelete added in v0.8.2

func (s *Store) PreparedQueryDelete(idx uint64, queryID string) error

PreparedQueryDelete deletes the given query by ID.

func (*Store) PreparedQueryGet added in v0.8.2

func (s *Store) PreparedQueryGet(ws memdb.WatchSet, queryID string) (uint64, *structs.PreparedQuery, error)

PreparedQueryGet returns the given prepared query by ID.

func (*Store) PreparedQueryList added in v0.8.2

func (s *Store) PreparedQueryList(ws memdb.WatchSet) (uint64, structs.PreparedQueries, error)

PreparedQueryList returns all the prepared queries.

func (*Store) PreparedQueryResolve added in v0.8.2

func (s *Store) PreparedQueryResolve(queryIDOrName string) (uint64, *structs.PreparedQuery, error)

PreparedQueryResolve returns the given prepared query by looking up an ID or Name. If the query was looked up by name and it's a template, then the template will be rendered before it is returned.

func (*Store) PreparedQuerySet added in v0.8.2

func (s *Store) PreparedQuerySet(idx uint64, query *structs.PreparedQuery) error

PreparedQuerySet is used to create or update a prepared query.

func (*Store) ReapTombstones added in v0.8.2

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

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

func (*Store) Restore added in v0.8.2

func (s *Store) Restore() *Restore

Restore is used to efficiently manage restoring a large amount of data into the state store. It works by doing all the restores inside of a single transaction.

func (*Store) ServiceChecks added in v0.8.2

func (s *Store) ServiceChecks(ws memdb.WatchSet, serviceName string) (uint64, structs.HealthChecks, error)

ServiceChecks is used to get all checks associated with a given service ID. The query is performed against a service _name_ instead of a service ID.

func (*Store) ServiceChecksByNodeMeta added in v0.8.2

func (s *Store) ServiceChecksByNodeMeta(ws memdb.WatchSet, serviceName string,
	filters map[string]string) (uint64, structs.HealthChecks, error)

ServiceChecksByNodeMeta is used to get all checks associated with a given service ID, filtered by the given node metadata values. The query is performed against a service _name_ instead of a service ID.

func (*Store) ServiceNodes added in v0.8.2

func (s *Store) ServiceNodes(ws memdb.WatchSet, serviceName string) (uint64, structs.ServiceNodes, error)

ServiceNodes returns the nodes associated with a given service name.

func (*Store) ServiceTagNodes added in v0.8.2

func (s *Store) ServiceTagNodes(ws memdb.WatchSet, service string, tag string) (uint64, structs.ServiceNodes, error)

ServiceTagNodes returns the nodes associated with a given service, filtering out services that don't contain the given tag.

func (*Store) Services added in v0.8.2

func (s *Store) Services(ws memdb.WatchSet) (uint64, structs.Services, error)

Services returns all services along with a list of associated tags.

func (*Store) ServicesByNodeMeta added in v0.8.2

func (s *Store) ServicesByNodeMeta(ws memdb.WatchSet, filters map[string]string) (uint64, structs.Services, error)

ServicesByNodeMeta returns all services, filtered by the given node metadata.

func (*Store) SessionCreate added in v0.8.2

func (s *Store) SessionCreate(idx uint64, sess *structs.Session) error

SessionCreate is used to register a new session in the state store.

func (*Store) SessionDestroy added in v0.8.2

func (s *Store) SessionDestroy(idx uint64, sessionID string) error

SessionDestroy is used to remove an active session. This will implicitly invalidate the session and invoke the specified session destroy behavior.

func (*Store) SessionGet added in v0.8.2

func (s *Store) SessionGet(ws memdb.WatchSet, sessionID string) (uint64, *structs.Session, error)

SessionGet is used to retrieve an active session from the state store.

func (*Store) SessionList added in v0.8.2

func (s *Store) SessionList(ws memdb.WatchSet) (uint64, structs.Sessions, error)

SessionList returns a slice containing all of the active sessions.

func (*Store) Snapshot added in v0.8.2

func (s *Store) Snapshot() *Snapshot

Snapshot is used to create a point-in-time snapshot of the entire db.

func (*Store) TxnRO added in v0.8.2

TxnRO runs the given operations inside a single read transaction in the state store. You must verify outside this function that no write operations are present, otherwise you'll get an error from the state store.

func (*Store) TxnRW added in v0.8.2

func (s *Store) TxnRW(idx uint64, ops structs.TxnOps) (structs.TxnResults, structs.TxnErrors)

TxnRW tries to run the given operations all inside a single transaction. If any of the operations fail, the entire transaction will be rolled back. This is done in a full write transaction on the state store, so reads and writes are possible

type Tombstone

type Tombstone struct {
	Key   string
	Index uint64
}

Tombstone is the internal type used to track tombstones.

type TombstoneGC

type TombstoneGC struct {
	sync.Mutex
	// 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

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

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

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

func (t *TombstoneGC) PendingExpiration() bool

PendingExpiration is used to check if any expirations are pending.

func (*TombstoneGC) SetEnabled

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.

Jump to

Keyboard shortcuts

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