Documentation ¶
Index ¶
- Constants
- Variables
- func Apply(store *MemoryStore, item events.Event) (err error)
- func CreateCluster(tx Tx, c *api.Cluster) error
- func CreateNetwork(tx Tx, n *api.Network) error
- func CreateNode(tx Tx, n *api.Node) error
- func CreateService(tx Tx, s *api.Service) error
- func CreateTask(tx Tx, t *api.Task) error
- func DeleteCluster(tx Tx, id string) error
- func DeleteNetwork(tx Tx, id string) error
- func DeleteNode(tx Tx, id string) error
- func DeleteService(tx Tx, id string) error
- func DeleteTask(tx Tx, id string) error
- func FindClusters(tx ReadTx, by By) ([]*api.Cluster, error)
- func FindNetworks(tx ReadTx, by By) ([]*api.Network, error)
- func FindNodes(tx ReadTx, by By) ([]*api.Node, error)
- func FindServices(tx ReadTx, by By) ([]*api.Service, error)
- func FindTasks(tx ReadTx, by By) ([]*api.Task, error)
- func GetCluster(tx ReadTx, id string) *api.Cluster
- func GetNetwork(tx ReadTx, id string) *api.Network
- func GetNode(tx ReadTx, id string) *api.Node
- func GetService(tx ReadTx, id string) *api.Service
- func GetTask(tx ReadTx, id string) *api.Task
- func UpdateCluster(tx Tx, c *api.Cluster) error
- func UpdateNetwork(tx Tx, n *api.Network) error
- func UpdateNode(tx Tx, n *api.Node) error
- func UpdateService(tx Tx, s *api.Service) error
- func UpdateTask(tx Tx, t *api.Task) error
- func ViewAndWatch(store *MemoryStore, cb func(ReadTx) error, specifiers ...state.Event) (watch chan events.Event, cancel func(), err error)
- type Batch
- type By
- func ByCN(name string) By
- func ByDesiredState(state api.TaskState) By
- func ByIDPrefix(idPrefix string) By
- func ByMembership(membership api.NodeSpec_Membership) By
- func ByName(name string) By
- func ByNamePrefix(namePrefix string) By
- func ByNodeID(nodeID string) By
- func ByRole(role api.NodeRole) By
- func ByServiceID(serviceID string) By
- func BySlot(serviceID string, slot uint64) By
- func Or(bys ...By) By
- type MemoryStore
- func (s *MemoryStore) ApplyStoreActions(actions []*api.StoreAction) error
- func (s *MemoryStore) Batch(cb func(*Batch) error) (int, error)
- func (s *MemoryStore) Restore(snapshot *pb.StoreSnapshot) error
- func (s *MemoryStore) Save(tx ReadTx) (*pb.StoreSnapshot, error)
- func (s *MemoryStore) Update(cb func(Tx) error) error
- func (s *MemoryStore) View(cb func(ReadTx))
- func (s *MemoryStore) WatchQueue() *watch.Queue
- type Object
- type ObjectStoreConfig
- type ReadTx
- type Tx
Constants ¶
const ( // MaxChangesPerTransaction is the number of changes after which a new // transaction should be started within Batch. MaxChangesPerTransaction = 200 // MaxTransactionBytes is the maximum serialized transaction size. MaxTransactionBytes = 1.5 * 1024 * 1024 )
const ( // DefaultClusterName is the default name to use for the cluster // object. DefaultClusterName = "default" )
Variables ¶
var ( // ErrExist is returned by create operations if the provided ID is already // taken. ErrExist = errors.New("object already exists") // ErrNotExist is returned by altering operations (update, delete) if the // provided ID is not found. ErrNotExist = errors.New("object does not exist") // ErrNameConflict is returned by create/update if the object name is // already in use by another object. ErrNameConflict = errors.New("name conflicts with an existing object") // ErrInvalidFindBy is returned if an unrecognized type is passed to Find. ErrInvalidFindBy = errors.New("invalid find argument type") // ErrSequenceConflict is returned when trying to update an object // whose sequence information does not match the object in the store's. ErrSequenceConflict = errors.New("update out of sequence") )
var All byAll
All is an argument that can be passed to find to list all items in the set.
Functions ¶
func Apply ¶
func Apply(store *MemoryStore, item events.Event) (err error)
Apply takes an item from the event stream of one Store and applies it to a second Store.
func CreateCluster ¶
CreateCluster adds a new cluster to the store. Returns ErrExist if the ID is already taken.
func CreateNetwork ¶
CreateNetwork adds a new network to the store. Returns ErrExist if the ID is already taken.
func CreateNode ¶
CreateNode adds a new node to the store. Returns ErrExist if the ID is already taken.
func CreateService ¶
CreateService adds a new service to the store. Returns ErrExist if the ID is already taken.
func CreateTask ¶
CreateTask adds a new task to the store. Returns ErrExist if the ID is already taken.
func DeleteCluster ¶
DeleteCluster removes a cluster from the store. Returns ErrNotExist if the cluster doesn't exist.
func DeleteNetwork ¶
DeleteNetwork removes a network from the store. Returns ErrNotExist if the network doesn't exist.
func DeleteNode ¶
DeleteNode removes a node from the store. Returns ErrNotExist if the node doesn't exist.
func DeleteService ¶
DeleteService removes a service from the store. Returns ErrNotExist if the service doesn't exist.
func DeleteTask ¶
DeleteTask removes a task from the store. Returns ErrNotExist if the task doesn't exist.
func FindClusters ¶
FindClusters selects a set of clusters and returns them.
func FindNetworks ¶
FindNetworks selects a set of networks and returns them.
func FindServices ¶
FindServices selects a set of services and returns them.
func GetCluster ¶
GetCluster looks up a cluster by ID. Returns nil if the cluster doesn't exist.
func GetNetwork ¶
GetNetwork looks up a network by ID. Returns nil if the network doesn't exist.
func GetService ¶
GetService looks up a service by ID. Returns nil if the service doesn't exist.
func UpdateCluster ¶
UpdateCluster updates an existing cluster in the store. Returns ErrNotExist if the cluster doesn't exist.
func UpdateNetwork ¶
UpdateNetwork updates an existing network in the store. Returns ErrNotExist if the network doesn't exist.
func UpdateNode ¶
UpdateNode updates an existing node in the store. Returns ErrNotExist if the node doesn't exist.
func UpdateService ¶
UpdateService updates an existing service in the store. Returns ErrNotExist if the service doesn't exist.
func UpdateTask ¶
UpdateTask updates an existing task in the store. Returns ErrNotExist if the node doesn't exist.
func ViewAndWatch ¶
func ViewAndWatch(store *MemoryStore, cb func(ReadTx) error, specifiers ...state.Event) (watch chan events.Event, cancel func(), err error)
ViewAndWatch calls a callback which can observe the state of this MemoryStore. It also returns a channel that will return further events from this point so the snapshot can be kept up to date. The watch channel must be released with watch.StopWatch when it is no longer needed. The channel is guaranteed to get all events after the moment of the snapshot, and only those events.
Types ¶
type Batch ¶
type Batch struct {
// contains filtered or unexported fields
}
Batch provides a mechanism to batch updates to a store.
type By ¶
type By interface {
// contains filtered or unexported methods
}
By is an interface type passed to Find methods. Implementations must be defined in this package.
func ByDesiredState ¶
ByDesiredState creates an object to pass to Find to select by desired state.
func ByIDPrefix ¶
ByIDPrefix creates an object to pass to Find to select by query.
func ByMembership ¶
func ByMembership(membership api.NodeSpec_Membership) By
ByMembership creates an object to pass to Find to select by Membership.
func ByNamePrefix ¶
ByNamePrefix creates an object to pass to Find to select by query.
func ByServiceID ¶
ByServiceID creates an object to pass to Find to select by service.
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore is a concurrency-safe, in-memory implementation of the Store interface.
func NewMemoryStore ¶
func NewMemoryStore(proposer state.Proposer) *MemoryStore
NewMemoryStore returns an in-memory store. The argument is an optional Proposer which will be used to propagate changes to other members in a cluster.
func (*MemoryStore) ApplyStoreActions ¶
func (s *MemoryStore) ApplyStoreActions(actions []*api.StoreAction) error
ApplyStoreActions updates a store based on StoreAction messages.
func (*MemoryStore) Batch ¶
func (s *MemoryStore) Batch(cb func(*Batch) error) (int, error)
Batch performs one or more transactions that allow reads and writes It invokes a callback that is passed a Batch object. The callback may call batch.Update for each change it wants to make as part of the batch. The changes in the batch may be split over multiple transactions if necessary to keep transactions below the size limit. Batch holds a lock over the state, but will yield this lock every it creates a new transaction to allow other writers to proceed. Thus, unrelated changes to the state may occur between calls to batch.Update.
This method allows the caller to iterate over a data set and apply changes in sequence without holding the store write lock for an excessive time, or producing a transaction that exceeds the maximum size.
Batch returns the number of calls to batch.Update whose changes were successfully committed to the store.
func (*MemoryStore) Restore ¶
func (s *MemoryStore) Restore(snapshot *pb.StoreSnapshot) error
Restore sets the contents of the store to the serialized data in the argument.
func (*MemoryStore) Save ¶
func (s *MemoryStore) Save(tx ReadTx) (*pb.StoreSnapshot, error)
Save serializes the data in the store.
func (*MemoryStore) Update ¶
func (s *MemoryStore) Update(cb func(Tx) error) error
Update executes a read/write transaction.
func (*MemoryStore) View ¶
func (s *MemoryStore) View(cb func(ReadTx))
View executes a read transaction.
func (*MemoryStore) WatchQueue ¶
func (s *MemoryStore) WatchQueue() *watch.Queue
WatchQueue returns the publish/subscribe queue.
type Object ¶
type Object interface { ID() string // Get ID Meta() api.Meta // Retrieve metadata SetMeta(api.Meta) // Set metadata Copy() Object // Return a copy of this object EventCreate() state.Event // Return a creation event EventUpdate() state.Event // Return an update event EventDelete() state.Event // Return a deletion event }
Object is a generic object that can be handled by the store.
type ObjectStoreConfig ¶
type ObjectStoreConfig struct { Name string Table *memdb.TableSchema Save func(ReadTx, *api.StoreSnapshot) error Restore func(Tx, *api.StoreSnapshot) error ApplyStoreAction func(Tx, *api.StoreAction) error NewStoreAction func(state.Event) (api.StoreAction, error) }
ObjectStoreConfig provides the necessary methods to store a particular object type inside MemoryStore.
type ReadTx ¶
type ReadTx interface {
// contains filtered or unexported methods
}
ReadTx is a read transaction. Note that transaction does not imply any internal batching. It only means that the transaction presents a consistent view of the data that cannot be affected by other transactions.
type Tx ¶
type Tx interface { ReadTx // contains filtered or unexported methods }
Tx is a read/write transaction. Note that transaction does not imply any internal batching. The purpose of this transaction is to give the user a guarantee that its changes won't be visible to other transactions until the transaction is over.