webstorage

package
v0.0.0-...-9057857 Latest Latest
Warning

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

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

Documentation

Rendered for js/wasm

Overview

Package webstorage provides a simple log storage implementation based on webstorage. It only really makes sense for wasm targets in browsers where the sessionStorage WebStorage API is available. See https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API for more information about the browser WebStorage API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadCheckpoint

func ReadCheckpoint(root string) ([]byte, error)

ReadCheckpoint reads and returns the contents of the log checkpoint file.

Types

type Storage

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

Storage is a serverless storage implementation which uses webstorage entries to store tree state. The storage key format is:

<root>/leaves/aa/bb/cc/ddeeff...
<root>/leaves/pending/aabbccddeeff...
<root>/seq/aa/bb/cc/ddeeff...
<root>/tile/<level>/aa/bb/ccddee...
<root>/checkpoint

The functions on this struct are not thread-safe.

func Create

func Create(root string) (*Storage, error)

Create creates a new filesystem hierarchy and returns a Storage representation for it.

func Load

func Load(root string, cpSize uint64) (*Storage, error)

Load returns a Storage instance initialised from webstorage prefixed at root. cpSize should be the Size of the checkpoint produced from the last `log.Integrate` call.

func (*Storage) DeletePending

func (fs *Storage) DeletePending(f string) error

DeletePending removes a pending leaf stored under PendingKey.

func (*Storage) GetTile

func (fs *Storage) GetTile(_ context.Context, level, index, logSize uint64) (*api.Tile, error)

GetTile returns the tile at the given tile-level and tile-index. If no complete tile exists at that location, it will attempt to find a partial tile for the given tree size at that location.

func (*Storage) Pending

func (fs *Storage) Pending(f string) ([]byte, error)

Pending returns a pending leaf stored under PendingKey.

func (*Storage) PendingKeys

func (fs *Storage) PendingKeys() ([]string, error)

PendingKeys returns the storage keys associated with pending leaves.

func (*Storage) Queue

func (fs *Storage) Queue(leaf []byte) error

Queue adds a leaf to the pending queue for integration.

func (*Storage) ScanSequenced

func (fs *Storage) ScanSequenced(_ context.Context, begin uint64, f func(seq uint64, entry []byte) error) (uint64, error)

ScanSequenced calls the provided function once for each contiguous entry in storage starting at begin. The scan will abort if the function returns an error, otherwise it will return the number of sequenced entries.

func (*Storage) Sequence

func (fs *Storage) Sequence(_ context.Context, leafhash []byte, leaf []byte) (uint64, error)

Sequence assigns the given leaf entry to the next available sequence number. This method will attempt to silently squash duplicate leaves, but it cannot be guaranteed that no duplicate entries will exist. Returns the sequence number assigned to this leaf (if the leaf has already been sequenced it will return the original sequence number and ErrDupeLeaf).

func (*Storage) StoreTile

func (fs *Storage) StoreTile(_ context.Context, level, index uint64, tile *api.Tile) error

StoreTile writes a tile out to disk. Fully populated tiles are stored at the path corresponding to the level & index parameters, partially populated (i.e. right-hand edge) tiles are stored with a .xx suffix where xx is the number of "tile leaves" in hex.

func (Storage) WriteCheckpoint

func (fs Storage) WriteCheckpoint(_ context.Context, newCPRaw []byte) error

WriteCheckpoint stores a raw log checkpoint on disk.

Jump to

Keyboard shortcuts

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