wbstore

package
v0.0.0-...-4a8f785 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: Apache-2.0 Imports: 6 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. Content-addressed 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, data []byte) (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) 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) Size

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

Size implements part of blob.Store. If an unflushed write for the key exists in the buffer, its size is reported; otherwise the size of the base key.

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