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.



This section is empty.


This section is empty.


func List

func List(ctx context.Context) ([]string, error)

List returns the full list of scheduler ids.


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

func For(qsPoolID string) *NodeStore

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

func New(qsPoolID string) *NodeStore

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

func (n *NodeStore) Clean(ctx context.Context) (int, error)

Clean deletes stale entities. It should be called periodically by a cronjob.

It returns the number of stale entities deleted.

func (*NodeStore) Create

func (n *NodeStore) Create(ctx context.Context, timestamp time.Time) error

Create creates a new persistent scheduler entity if one doesn't exist.

func (*NodeStore) Delete

func (n *NodeStore) Delete(ctx context.Context) error

Delete deletes all entities associated with a given pool.

func (*NodeStore) Get

func (n *NodeStore) Get(ctx context.Context) (*types.QScheduler, error)

Get returns the current qscheduler state.

func (*NodeStore) Run

func (n *NodeStore) Run(ctx context.Context, o Operator) error

Run runs the given operator.

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.

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

func NewModOnlyOperator(f func(ctx context.Context, state *types.QScheduler) error) Operator

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.

Source Files


Path Synopsis
Package blob defines the proto format used by nodestore.
Package blob defines the proto format used by nodestore.