Documentation ¶
Overview ¶
Package storage contains storage classes for etcd-based quotas.
Index ¶
- func IsNameValid(name string) bool
- type QuotaStorage
- func (qs *QuotaStorage) Configs(ctx context.Context) (*storagepb.Configs, error)
- func (qs *QuotaStorage) Get(ctx context.Context, names []string, tokens int64) error
- func (qs *QuotaStorage) Peek(ctx context.Context, names []string) (map[string]int64, error)
- func (qs *QuotaStorage) Put(ctx context.Context, names []string, tokens int64) error
- func (qs *QuotaStorage) Reset(ctx context.Context, names []string) error
- func (qs *QuotaStorage) UpdateConfigs(ctx context.Context, reset bool, update func(*storagepb.Configs)) (*storagepb.Configs, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsNameValid ¶
IsNameValid returns true if name is a valid quota name.
Types ¶
type QuotaStorage ¶
QuotaStorage is the interface between the etcd-based quota implementations (quota.Manager and RPCs) and etcd itself.
func (*QuotaStorage) Configs ¶
Configs returns the currently known quota configs. If no config was explicitly created, then an empty storage.Configs proto is returned.
func (*QuotaStorage) Get ¶
Get acquires "tokens" tokens from the named quotas. If one of the specified quotas doesn't have enough tokens, the entire operation fails. Unknown or disabled quotas are considered infinite, therefore get requests will always succeed for them.
func (*QuotaStorage) Peek ¶
Peek returns a map of quota name to tokens for the named quotas. Unknown or disabled quotas are considered infinite and returned as having quota.MaxTokens tokens, therefore all requested names are guaranteed to be in the resulting map
func (*QuotaStorage) Put ¶
Put adds "tokens" tokens to the named quotas. Time-based quotas cannot be replenished this way, therefore put requests for them are ignored. Unknown or disabled quotas are considered infinite and also ignored.
func (*QuotaStorage) Reset ¶
func (qs *QuotaStorage) Reset(ctx context.Context, names []string) error
Reset resets the named quotas to their maximum number of tokens. Unknown or disabled quotas are considered infinite and ignored.
func (*QuotaStorage) UpdateConfigs ¶
func (qs *QuotaStorage) UpdateConfigs(ctx context.Context, reset bool, update func(*storagepb.Configs)) (*storagepb.Configs, error)
UpdateConfigs creates or updates the supplied configs in etcd. If no config exists, the current config is assumed to be an empty storagepb.Configs proto. The update function allows for mask-based updates and ensures a single-transaction read-modify-write operation. If reset is true, all specified configs will be set to their max number of tokens. If false, existing quotas won't be modified, unless the max number of tokens is lowered, in which case the new ceiling is enforced. Newly created quotas are always set to max tokens, regardless of the reset parameter.