inmem

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2023 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	// contains filtered or unexported fields
}

Backend is a purely in-memory storage backend implementation.

func NewBackend

func NewBackend() (*Backend, error)

NewBackend returns a purely in-memory storage backend. It's suitable for testing and development mode, but should NOT be used in production as it has no support for durable persistence, so all of your data will be lost when the process restarts or crashes.

You must call Run before using the backend.

func (*Backend) DeleteCAS

func (b *Backend) DeleteCAS(_ context.Context, id *pbresource.ID, version string) error

DeleteCAS implements the storage.Backend interface.

func (*Backend) List

List implements the storage.Backend interface.

func (*Backend) ListByOwner

func (b *Backend) ListByOwner(_ context.Context, id *pbresource.ID) ([]*pbresource.Resource, error)

ListByOwner implements the storage.Backend interface.

func (*Backend) Read

Read implements the storage.Backend interface.

func (*Backend) Run

func (b *Backend) Run(ctx context.Context)

Run until the given context is canceled. This method blocks, so should be called in a goroutine.

func (*Backend) WatchList

func (b *Backend) WatchList(_ context.Context, resType storage.UnversionedType, tenancy *pbresource.Tenancy, namePrefix string) (storage.Watch, error)

WatchList implements the storage.Backend interface.

func (*Backend) WriteCAS

WriteCAS implements the storage.Backend interface.

type Restoration

type Restoration struct {
	// contains filtered or unexported fields
}

Restoration is a handle that can be used to restore a snapshot.

func (*Restoration) Abort

func (r *Restoration) Abort()

Abort the restoration. It's safe to always call this in a defer statement because aborting a committed restoration is a no-op.

func (*Restoration) Apply

func (r *Restoration) Apply(res *pbresource.Resource) error

Apply the given resource to the store.

func (*Restoration) Commit

func (r *Restoration) Commit()

Commit the restoration. Replaces the in-memory database wholesale and closes any watches.

type Snapshot

type Snapshot struct {
	// contains filtered or unexported fields
}

Snapshot is a point-in-time snapshot of a store.

func (*Snapshot) Next

func (s *Snapshot) Next() *pbresource.Resource

Next returns the next resource in the snapshot. nil will be returned when the end of the snapshot has been reached.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store implements an in-memory resource database using go-memdb.

It can be used as a storage backend directly via the Backend type in this package, but also handles reads in our Raft backend, and can be used as a local cache when storing data in external systems (e.g. RDBMS, K/V stores).

func NewStore

func NewStore() (*Store, error)

NewStore creates a Store.

You must call Run before using the store.

func (*Store) DeleteCAS

func (s *Store) DeleteCAS(id *pbresource.ID, vsn string) error

DeleteCAS performs an atomic Compare-And-Swap (CAS) deletion of a resource.

For more information, see the storage.Backend documentation.

func (*Store) List

func (s *Store) List(typ storage.UnversionedType, ten *pbresource.Tenancy, namePrefix string) ([]*pbresource.Resource, error)

List resources of the given type, tenancy, and optionally matching the given name prefix.

For more information, see the storage.Backend documentation.

func (*Store) ListByOwner

func (s *Store) ListByOwner(id *pbresource.ID) ([]*pbresource.Resource, error)

ListByOwner returns resources owned by the resource with the given ID.

For more information, see the storage.Backend documentation.

func (*Store) Read

func (s *Store) Read(id *pbresource.ID) (*pbresource.Resource, error)

Read a resource using its ID.

For more information, see the storage.Backend documentation.

func (*Store) Restore

func (s *Store) Restore() (*Restoration, error)

Restore starts the process of restoring a snapshot.

Callers *must* call Abort or Commit when done, to free resources.

func (*Store) Run

func (s *Store) Run(ctx context.Context)

Run until the given context is canceled. This method blocks, so should be called in a goroutine.

func (*Store) Snapshot

func (s *Store) Snapshot() (*Snapshot, error)

Snapshot obtains a point-in-time snapshot of the store that can later be persisted and restored later.

func (*Store) WatchList

func (s *Store) WatchList(typ storage.UnversionedType, ten *pbresource.Tenancy, namePrefix string) (*Watch, error)

WatchList watches resources of the given type, tenancy, and optionally matching the given name prefix.

For more information, see the storage.Backend documentation.

func (*Store) WriteCAS

func (s *Store) WriteCAS(res *pbresource.Resource, vsn string) error

WriteCAS performs an atomic Compare-And-Swap (CAS) write of a resource.

For more information, see the storage.Backend documentation.

type Watch

type Watch struct {
	// contains filtered or unexported fields
}

Watch implements the storage.Watch interface using a stream.Subscription.

func (*Watch) Close

func (w *Watch) Close()

Close the watch and free its associated resources.

func (*Watch) Next

func (w *Watch) Next(ctx context.Context) (*pbresource.WatchEvent, error)

Next returns the next WatchEvent, blocking until one is available.

Jump to

Keyboard shortcuts

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