Documentation ¶
Overview ¶
Package nodestore implements a datastore-backed persistent store of qscheduler state, that shards state over as many entities as necessary to stay under datastore's single-entity size limit, and uses an in-memory cache to avoid unnecessary datastore reads.
Index ¶
- func List(ctx context.Context) ([]string, error)
- type NodeStore
- func (n *NodeStore) Clean(ctx context.Context) (int, error)
- func (n *NodeStore) Create(ctx context.Context, timestamp time.Time) error
- func (n *NodeStore) Delete(ctx context.Context) error
- func (n *NodeStore) Get(ctx context.Context) (*types.QScheduler, error)
- func (n *NodeStore) Run(ctx context.Context, o Operator) error
- type Operator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type NodeStore ¶
type NodeStore struct {
// contains filtered or unexported fields
}
NodeStore is a persistent store for an individual quotascheduler state.
All methods are concurrency-safe.
func For ¶
For returns a NodeStore for the given pool from a collection of per-pool singletons, or creates a new store if necessary.
Production callers should prefer this over New.
func New ¶
New returns a new NodeStore.
Most callers should use For instead, to fetch a singleton for the given pool. Using the singlton in production reduces the probability of bad contention concurrent operations.
Tests that explicitly want to test interaction between two separate NodeStores should use New.
func (*NodeStore) Clean ¶
Clean deletes stale entities. It should be called periodically by a cronjob.
It returns the number of stale entities deleted.
type Operator ¶
type Operator interface { // Modify is called to modify a quotascheduler state; it may be called // more than once, therefore it should not have side effects besides: // - modifying the supplied *types.QScheduler, // - side effects that are stored internally to the Operator (e.g. metrics // to be used in the Commit or Finish calls). // // If there are any side effects stored internally to the Operator, they // should be reset on each call to Modify. Modify(ctx context.Context, state *types.QScheduler) error // Commit will be called within a datastore transaction, after a successful // call to Modify. Commit should be used to persist any transactional // side effects of Modify (such as emitting tasks to a task queue). Commit(context.Context) error // Finish will be called at most once, after a successful call to Commit. // This will be called outside of any transactions, and should be used // for non-transactional at-most-once side effects, such as incrementing // ts_mon counters. Finish(context.Context) }
Operator describes an interface that NodeStore will use for for mutating a quotascheduler's state, and persisting any side-effects.
NodeStore will not call any methods of an Operator concurrently.
func NewModOnlyOperator ¶
NewModOnlyOperator returns an Operator that simply applies the given state-modification function. This is a convenience method for callers that don't need to handle the Commit or Finish phases of an Operator.