storage

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package storage contains storage classes for etcd-based quotas.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNameValid

func IsNameValid(name string) bool

IsNameValid returns true if name is a valid quota name.

Types

type QuotaStorage

type QuotaStorage struct {
	Client *clientv3.Client
}

QuotaStorage is the interface between the etcd-based quota implementations (quota.Manager and RPCs) and etcd itself.

func (*QuotaStorage) Configs

func (qs *QuotaStorage) Configs(ctx context.Context) (*storagepb.Configs, error)

Configs returns the currently known quota configs. If no config was explicitly created, then an empty storage.Configs proto is returned.

func (*QuotaStorage) Get

func (qs *QuotaStorage) Get(ctx context.Context, names []string, tokens int64) error

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

func (qs *QuotaStorage) Peek(ctx context.Context, names []string) (map[string]int64, error)

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

func (qs *QuotaStorage) Put(ctx context.Context, names []string, tokens int64) error

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.

Jump to

Keyboard shortcuts

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