types

package
v0.0.0-...-560d035 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2017 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const TOKEN_BYTES = 8
View Source
const TOKEN_LENGTH = 2 * TOKEN_BYTES

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store struct {
	Id           uint16 `json:"id"`
	Token        string `json:"token"`
	OwnerId      uint64 `json:"ownerId" binding:"required"`
	SubmissionId uint64 `json:"submissionId"`
	// contains filtered or unexported fields
}

func NewStore

func NewStore(id uint16, token string, db *bolt.DB) *Store

func (*Store) Delete

func (store *Store) Delete(key string) error

func (*Store) Get

func (store *Store) Get(key string) ([]byte, error)

func (*Store) Metrics

func (store *Store) Metrics() *metrics.StoreSnapshot

func (*Store) Put

func (store *Store) Put(key string, value []byte) error

@todo Keep monitoring metrics and batch writes via a WAL if need be. BoltDB is slow on random writes which "should" not matter in our case, but "should" is not a confident assumption.

type StoreRepository

type StoreRepository struct {
	// Token -> Store (nearly all access is going to be reads identified by an access token, not an ID
	// even though we primarily use the ID internally instead, to avoid coupling persisted data to a token
	// which may change (as opposed to an ID which will not).
	Items map[string]*Store `json:"items"`
	// contains filtered or unexported fields
}

StoreRepository is *not* thread-safe. In our use case mutations only ever happen via administrative actions, at most a few times *daily* and realistically never concurrently. In the edge case a store gets deleted during a read, even if the read call came in before the delete call, the deletion *may* happen before, causing the read request to fail to find the store and return with an error. If the read happens before the deletion, the read call stack will continue to hold a pointer to the Store even if it meanwhile gets removed from the Repository (which is fine). The maps are allocated on the heap and will be touched by the GC. Realistically we expect at most a few dozen up to a max of a few hundred stores to be present, so as long as this assumption holds true GC pauses should not be impacted in a meaningful manner.

func LoadStoreRepository

func LoadStoreRepository(db *bolt.DB, bucketKey []byte) (*StoreRepository, error)

LoadStoreRepository creates a StoreRepository and populates it from the given bucket identified by its key in the backing storage.

func (*StoreRepository) Create

func (repository *StoreRepository) Create(id uint16, token string) (*Store, error)

func (*StoreRepository) Delete

func (repository *StoreRepository) Delete(store *Store) error

func (*StoreRepository) GetById

func (repository *StoreRepository) GetById(id uint16) *Store

func (*StoreRepository) RegisterMetricsTicks

func (repository *StoreRepository) RegisterMetricsTicks(tickManager server.TickManager)

func (*StoreRepository) RotateToken

func (repository *StoreRepository) RotateToken(store *Store) error

func (*StoreRepository) Save

func (repository *StoreRepository) Save(store *Store) error

Jump to

Keyboard shortcuts

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