wbstore

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Overview

Package wbstore implements a wrapper for a blob.CAS that caches writes of content-addressed data in a buffer and pushes them into a base store in the background.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store struct {
	blob.CAS
	// contains filtered or unexported fields
}

A Store implements the blob.CAS interface delegated to an underlying (base) store. Non-replacement writes are cached locally in a buffer store, and written behind to the base store in the background. Get and Size queries respect the buffer cache, so that the local application sees a consistent view. Other store operations delegate directly to the base store.

This wrapper is intended for use with base store implementations that are remote and expensive to write to, such as cloud storage. This approach is suitable for applications that do not require immediate consistency of the base store.

func New

func New(ctx context.Context, base blob.CAS, buf blob.Store) *Store

New constructs a store wrapper that delegates to base and uses buf as the local buffer store. New will panic if base == nil or buf == nil. The ctx value governs the operation of the background writer, which will run until the store is closed or ctx terminates.

If the buffer store is not empty, any existing blobs will be mirrored to the base store. This allows the caller to gracefully resume after failures.

func (*Store) Buffer

func (s *Store) Buffer() blob.Store

Buffer returns the buffer store used by s.

func (*Store) CASPut

func (s *Store) CASPut(ctx context.Context, opts blob.CASPutOptions) (string, error)

CASPut implements part of blob.CAS. It queries the base store for the content key, but stores the blob only in the buffer.

func (*Store) Close

func (s *Store) Close(ctx context.Context) error

Close implements the optional blob.Closer interface. It signals the background writer to terminate, and blocks until it has done so or until ctx ends.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, key string) error

Delete implements part of blob.Store. The key is deleted from both the buffer and the base store, and succeeds as long as either of those operations succeeds.

func (*Store) Get

func (s *Store) Get(ctx context.Context, key string) ([]byte, error)

Get implements part of blob.Store. If key is in the write-behind store, its value there is returned; otherwise it is fetched from the base store.

func (*Store) Len added in v0.2.0

func (s *Store) Len(ctx context.Context) (int64, error)

Len implements part of blob.Store. It merges contents from the buffer that are not listed in the underlying store, so that the reported length reflects the total number of unique keys across both the buffer and the base store.

func (*Store) List added in v0.2.0

func (s *Store) List(ctx context.Context, start string, f func(string) error) error

List implements part of blob.Store. It merges contents from the buffer that are not listed in the underlying store, so that the keys reported include those that have not yet been written back.

func (*Store) Put

func (s *Store) Put(ctx context.Context, opts blob.PutOptions) error

Put implements part of blob.Store. It delegates to the base store directly for writes that request replacement; otherwise it stores the blob into the buffer for writeback.

func (*Store) Sync

func (s *Store) Sync(ctx context.Context) error

Sync blocks until the buffer is empty or ctx ends.

Jump to

Keyboard shortcuts

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