bccore

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package bccore implements handles and object lifecycles.

Index

Constants

View Source
const (
	DefaultVolumeTTL = 5 * time.Minute
	DefaultTxTTL     = 1 * time.Minute
	DefaultQueueTTL  = 2 * time.Minute
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyObject

type AnyObject interface {
	Down(ctx context.Context) error
}

type Params

type Params struct {
	// Root is the root Volume, which will be given the 0 ID
	Root Volume
	// Up is called to bring up a Volume or Queue
	Up func(ctx context.Context, oid blobcache.OID) (AnyObject, error)
	// OnLink is called before the object is linked to.
	// The object must be persisted so that it can be loaded later
	OnLink func(ctx context.Context, info blobcache.Info, ao AnyObject) error
	// OnSave, if not nil, is called on Save.
	// This is where schema checks can be performed.
	OnSave func(ctx context.Context, vol Volume, tx Tx, root []byte) error
}

type Queue

type Queue interface {
	AnyObject

	// Enqueue adds messages to the Queue.
	// It returns the number of messages accepted.
	Enqueue(ctx context.Context, msgs []blobcache.Message) (int, error)
	// Dequeue removes messages from the Queue.
	Dequeue(ctx context.Context, buf []blobcache.Message, opts blobcache.DequeueOpts) (int, error)
	// Down is called when the queue has no remaining handles
	Down(ctx context.Context) error
	// Config returns the QueueConfig for this queue.
	Config() blobcache.QueueConfig
	// Backend returns the QueueSpec for this queue.
	Backend() blobcache.QueueBackend[blobcache.OID]
}

type System

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

System manages objects and handles to those objects

func New

func New(p Params) System

func (*System) Abort

func (sys *System) Abort(ctx context.Context, txh blobcache.Handle) error

func (*System) AbortAll

func (s *System) AbortAll(ctx context.Context) error

func (*System) BeginTx

func (sys *System) BeginTx(ctx context.Context, volh blobcache.Handle, txspec blobcache.TxParams) (*blobcache.Handle, error)

func (*System) Cleanup

func (s *System) Cleanup(ctx context.Context, now time.Time, onDown func(blobcache.OID)) error

Cleanup should be called periodically, so that unused handles can be expired.

func (*System) Commit

func (sys *System) Commit(ctx context.Context, txh blobcache.Handle) error

func (*System) Copy

func (sys *System) Copy(ctx context.Context, txh blobcache.Handle, srcTxns []blobcache.Handle, cids []blobcache.CID, out *blobcache.BitMap) error

func (*System) Create

func (sys *System) Create(ctx context.Context, oid blobcache.OID, x AnyObject, rights blobcache.ActionSet, createdAt time.Time, ttl time.Duration) (blobcache.Handle, error)

func (*System) Delete

func (sys *System) Delete(ctx context.Context, txh blobcache.Handle, cids []blobcache.CID) error

func (*System) Dequeue

func (sys *System) Dequeue(ctx context.Context, qh blobcache.Handle, buf []blobcache.Message, opts blobcache.DequeueOpts) (int, error)

Dequeue implements blobcache.QueueAPI.Dequeue

func (*System) Drop

func (sys *System) Drop(_ context.Context, h blobcache.Handle) error

Drop implements blobcache.HandleAPI.Drop

func (*System) Enqueue

func (sys *System) Enqueue(ctx context.Context, qh blobcache.Handle, msgs []blobcache.Message) (*blobcache.InsertResp, error)

Enqueue implements blobcache.QueueAPI.Enqueue

func (*System) Exists

func (sys *System) Exists(ctx context.Context, txh blobcache.Handle, cids []blobcache.CID, dst *blobcache.BitMap) error

func (*System) Fiat

func (sys *System) Fiat(ctx context.Context, oid blobcache.OID, rights blobcache.ActionSet, createdAt time.Time, ttl time.Duration) (blobcache.Handle, error)

Fiat brings up the object if necessary and creates a new handle

func (*System) Get

func (sys *System) Get(ctx context.Context, txh blobcache.Handle, cid blobcache.CID, buf []byte, opts blobcache.GetOpts) (int, error)

func (*System) Inspect

func (sys *System) Inspect(ctx context.Context, h blobcache.Handle) (blobcache.Info, error)

func (*System) InspectHandle

func (sys *System) InspectHandle(_ context.Context, h blobcache.Handle) (*blobcache.HandleInfo, error)

InspectHandle implements blobcache.HandleAPI.InspectHandle

func (*System) InspectQueue

func (sys *System) InspectQueue(ctx context.Context, qh blobcache.Handle) (blobcache.QueueInfo, error)

InspectQueue implements blobcache.QueueAPI.InspectQueue

func (*System) InspectTx

func (sys *System) InspectTx(ctx context.Context, txh blobcache.Handle) (*blobcache.TxInfo, error)

func (*System) InspectVolume

func (sys *System) InspectVolume(ctx context.Context, h blobcache.Handle) (*blobcache.VolumeInfo, error)

func (*System) IsUp

func (sys *System) IsUp(x blobcache.OID) bool

IsUp returns true if x has at least one active handle pointing at it, and it's state is loaded in memory.

func (*System) IsVisited

func (sys *System) IsVisited(ctx context.Context, txh blobcache.Handle, cids []blobcache.CID, dst *blobcache.BitMap) error

func (*System) KeepAlive

func (sys *System) KeepAlive(_ context.Context, hs []blobcache.Handle) error

KeepAlive implements blobcache.HandleAPI.KeepAlive

func (*System) Load

func (sys *System) Load(ctx context.Context, txh blobcache.Handle, dst *[]byte) error

func (*System) Mint

func (sys *System) Mint(x blobcache.OID, rights blobcache.ActionSet, createdAt time.Time, ttl time.Duration) blobcache.Handle

func (*System) OpenFrom

func (sys *System) OpenFrom(ctx context.Context, base blobcache.Handle, ltok blobcache.LinkToken, mask blobcache.ActionSet) (*blobcache.Handle, error)

func (*System) Post

func (sys *System) Post(ctx context.Context, txh blobcache.Handle, data []byte, opts blobcache.PostOpts) (blobcache.CID, error)

func (*System) ResolveQueue

func (sys *System) ResolveQueue(qh blobcache.Handle) (Queue, error)

func (*System) ResolveVol

func (sys *System) ResolveVol(qh blobcache.Handle) (Volume, error)

func (*System) Save

func (sys *System) Save(ctx context.Context, txh blobcache.Handle, root []byte) error

func (*System) Share

Share creates a new handle from x and applies mask.

func (*System) SubToVolume

func (sys *System) SubToVolume(ctx context.Context, qh blobcache.Handle, volh blobcache.Handle, spec blobcache.VolSubSpec) error

SubToVolume subscribes vol to q. This allows aribtrary volumes to be subscribed to arbitrary queues, but this is not the correct thing for a Node to do in the general case, Nodes should forward subscriptions to remote Volumes and Queues when both are on the same Node.

func (sys *System) Unlink(ctx context.Context, txh blobcache.Handle, targets []blobcache.LinkID) error

func (*System) Visit

func (sys *System) Visit(ctx context.Context, txh blobcache.Handle, cids []blobcache.CID) error
func (sys *System) VisitLinks(ctx context.Context, txh blobcache.Handle, targets []blobcache.LinkID) error

type Tx

type Tx interface {
	Params() blobcache.TxParams
	Commit(ctx context.Context) error
	Abort(ctx context.Context) error

	Save(ctx context.Context, src []byte) error
	Load(ctx context.Context, dst *[]byte) error

	Post(ctx context.Context, data []byte, opts blobcache.PostOpts) (blobcache.CID, error)
	Get(ctx context.Context, cid blobcache.CID, buf []byte, opts blobcache.GetOpts) (int, error)
	Delete(ctx context.Context, cids []blobcache.CID) error
	Exists(ctx context.Context, cids []blobcache.CID, dst *blobcache.BitMap) error

	IsVisited(ctx context.Context, cids []blobcache.CID, dst *blobcache.BitMap) error
	Visit(ctx context.Context, cids []blobcache.CID) error

	MaxSize() int
	HashAlgo() blobcache.HashAlgo

	// Link creates adds a handle to prove access to a volume.
	Link(ctx context.Context, svoid blobcache.OID, rights blobcache.ActionSet, subvol AnyObject) (*blobcache.LinkToken, error)
	// Unlink removes a link from the volume.
	Unlink(ctx context.Context, targets []blobcache.LinkID) error
	// VisitLinks visits a link to another volume.
	// This is only usable in a GC transaction.
	VisitLinks(ctx context.Context, targets []blobcache.LinkID) error
}

Tx is a consistent view of a volume, during a transaction.

type Volume

type Volume interface {
	AnyObject

	// GetParams returns the effective parameters of the volume.
	GetParams() blobcache.VolumeConfig
	// GetBackend returns the backend of the volume.
	GetBackend() blobcache.VolumeBackend[blobcache.OID]

	BeginTx(ctx context.Context, spec blobcache.TxParams) (Tx, error)

	// AccessSubVolume returns the rights granted to access a subvolume.
	// Returns 0 if there is no link to the target.
	AccessSubVolume(ctx context.Context, target blobcache.LinkToken) (blobcache.ActionSet, error)
}

Jump to

Keyboard shortcuts

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