gotcore

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const MaxNameLen = 1024

Variables

View Source
var (
	ErrNotExist = errors.New("mark does not exist")
	ErrExists   = errors.New("a mark already exists by that name")
)

Functions

func CheckName

func CheckName(name string) error

func CloneMark

func CloneMark(ctx context.Context, st SpaceTx, from, to string) error

func ForEach

func ForEach(ctx context.Context, stx SpaceTx, span Span, fn func(string) error) (retErr error)

ForEach is a convenience function which uses Space.List to call fn with all the mark names contained in span.

func GotFS

func GotFS(cfg DSConfig) *gotfs.Machine

func GotVC

func GotVC(cfg DSConfig) *gotvc.Machine[Payload]

func History

func History(ctx context.Context, vcmach *VCMach, s stores.Reading, snapRef gdat.Ref, fn func(ref gdat.Ref, snap Snap) error) error

func IsExists

func IsExists(err error) bool

func IsNotExist

func IsNotExist(err error) bool

func SortAnnotations

func SortAnnotations(s []Annotation)

func Sync

func Sync(ctx context.Context, src, dst *MarkTx, force bool) error

SyncVolumes syncs the contents of src to dst.

func SyncSpaces

func SyncSpaces(ctx context.Context, task SyncSpacesTask) error

func TestSpace

func TestSpace(t *testing.T, newSpace func(t testing.TB) Space)

func TestSync

func TestSync(t *testing.T, setup func(testing.TB) Space)

func ViewSnapshot

func ViewSnapshot(ctx context.Context, stx SpaceTx, se SnapExpr, fn func(vctx *ViewCtx) error) error

ViewSnapshot calls fn with everything needed to read a Snapshot, its filesystem, and its ancestry.

Types

type Annotation

type Annotation struct {
	Key   string `json:"k"`
	Value string `json:"v"`
}

Annotation annotates a mark

func GetAnnotation

func GetAnnotation(as []Annotation, key string) (ret []Annotation)

type ChunkingConfig

type ChunkingConfig struct {
	CD  *Chunking_CDConfig `json:"cd,omitempty"`
	Max *Chunking_Fixed    `json:"fixed,omitempty"`
}

type Chunking_CDConfig

type Chunking_CDConfig struct {
	MeanSize int `json:"mean_size"`
	MaxSize  int `json:"max_size"`
}

type Chunking_Fixed

type Chunking_Fixed struct {
	Max uint32 `json:"max"`
	Min uint32 `json:"min"`
}

type DSConfig

type DSConfig struct {
	// Salt is a 32-byte salt used to derive the cryptographic keys for the mark.
	Salt Salt `json:"salt"`
	// GotFS contains all configuration for GotFS
	GotFS FSConfig `json:"fs"`
}

DSConfig holds all data structure parameters

func DefaultConfig

func DefaultConfig(public bool) DSConfig

func (DSConfig) Hash

func (cfg DSConfig) Hash() [32]byte

func (DSConfig) Marshal

func (cfg DSConfig) Marshal(out []byte) []byte

type ErrInvalidName

type ErrInvalidName struct {
	Name   string
	Reason string
}

func (ErrInvalidName) Error

func (e ErrInvalidName) Error() string

type ErrRefIntegrity

type ErrRefIntegrity struct {
	Ref   gdat.Ref
	Store string
}

func (ErrRefIntegrity) Error

func (e ErrRefIntegrity) Error() string

type FSConfig

type FSConfig struct {
	Data     ChunkingConfig    `json:"data_chunking"`
	Metadata Chunking_CDConfig `json:"metadata_chunking"`
}

Config contains all parameters.

type FSMach

type FSMach = gotfs.Machine

type Info

type Info struct {
	// Config holds the all the datastructure parameters
	Config DSConfig `json:"config"`
	// Annotations are arbitrary metadata associated with the mark.
	Annotations []Annotation `json:"annotations"`

	// CreatedAt is the time the mark was created.
	CreatedAt tai64.TAI64 `json:"created_at"`
}

Info is the metadata associated with a Mark.

func CreateIfNotExists

func CreateIfNotExists(ctx context.Context, stx SpaceTx, k string, cfg Metadata) (*Info, error)

func (Info) AsMetadata

func (i Info) AsMetadata() Metadata

func (Info) Clone

func (i Info) Clone() Info

type MarkTx

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

MarkTx scopes down a SpaceTx to a single Mark.

func NewMarkTx

func NewMarkTx(ctx context.Context, stx SpaceTx, name string) (*MarkTx, error)

func (*MarkTx) Apply

func (m *MarkTx) Apply(ctx context.Context, fn func([3]stores.RW, gdat.Ref) (gdat.Ref, error)) error

Apply calls fn with the Marks target Ref If the mark does not yet have a target, then the ref will be 0.

func (*MarkTx) Config

func (m *MarkTx) Config() DSConfig

func (*MarkTx) FSRO

func (mtx *MarkTx) FSRO() [2]stores.Reading

func (*MarkTx) FSRW

func (mtx *MarkTx) FSRW() [2]stores.RW

func (*MarkTx) GotFS

func (b *MarkTx) GotFS() *gotfs.Machine

func (*MarkTx) GotVC

func (b *MarkTx) GotVC() *VCMach

func (*MarkTx) History

func (b *MarkTx) History(ctx context.Context, fn func(ref gdat.Ref, snap Snap) error) error

func (*MarkTx) Info

func (b *MarkTx) Info() Info

func (*MarkTx) Load

func (b *MarkTx) Load(ctx context.Context, dst *gdat.Ref) (bool, error)

Load loads a snapshot from the Mark

func (*MarkTx) LoadFS

func (b *MarkTx) LoadFS(ctx context.Context, dst *gotfs.Root) (bool, error)

func (*MarkTx) LoadSnap

func (mt *MarkTx) LoadSnap(ctx context.Context, dst *Snap) (bool, error)

func (*MarkTx) Modify

func (m *MarkTx) Modify(ctx context.Context, fn func(mctx ModifyCtx) (*Snap, error)) error

func (*MarkTx) RO

func (mtx *MarkTx) RO() [3]stores.Reading

func (*MarkTx) Save

func (m *MarkTx) Save(ctx context.Context, ref gdat.Ref) error

Save saves the snapshot to the Mark

func (*MarkTx) VCRO

func (mtx *MarkTx) VCRO() stores.Reading

func (*MarkTx) VCRW

func (mtx *MarkTx) VCRW() stores.RW

func (*MarkTx) WO

func (mtx *MarkTx) WO() [3]stores.Writing

type Metadata

type Metadata struct {
	Config      DSConfig     `json:"config"`
	Annotations []Annotation `json:"annotations"`
}

Metadata is non-volume, user-modifiable information associated with a mark.

func (Metadata) AsInfo

func (c Metadata) AsInfo() Info

func (Metadata) Clone

func (c Metadata) Clone() Metadata

Clone returns a deep copy of md

type ModifyCtx

type ModifyCtx struct {
	VC     *VCMach
	FS     *FSMach
	Stores [3]stores.RW
	Root   *Snap
}

ModifyCtx is the context passed to the modify function.

func (*ModifyCtx) Sync

func (mctx *ModifyCtx) Sync(ctx context.Context, srcs [3]stores.Reading, root Snap) error

Sync syncs a snapshot into the store

type Payload

type Payload struct {
	Root gotfs.Root
	Aux  []byte
}

Payload is the thing being snapshotted.

func ParsePayload

func ParsePayload(data []byte) (Payload, error)

func (Payload) Marshal

func (p Payload) Marshal(out []byte) []byte

func (*Payload) Unmarshal

func (p *Payload) Unmarshal(data []byte) error

type Salt

type Salt [32]byte

Salt is a 32-byte salt

func (Salt) MarshalText

func (s Salt) MarshalText() ([]byte, error)

func (*Salt) String

func (s *Salt) String() string

func (*Salt) UnmarshalText

func (s *Salt) UnmarshalText(data []byte) error

type Snap

type Snap = gotvc.Vertex[Payload]

func GetSnapshot

func GetSnapshot(ctx context.Context, s stores.Reading, ref gdat.Ref) (*Snap, error)

GetSnapshot reads a snapshot from the store.

type SnapExpr

type SnapExpr interface {
	GetSpace() string
	// Resolve returns a valid Ref, which points to a Snapshot.
	Resolve(ctx context.Context, stx SpaceTx) (*gdat.Ref, error)
	// contains filtered or unexported methods
}

SnapExpr is a sum type representing the different ways to refer to a Snapshot in Got So far, there are 2 primitive ways - Exactly by Ref - By Mark And 1 higher-order way - By an offset from the result of a previous expression

func ParseSnapExpr

func ParseSnapExpr(x string) (SnapExpr, error)

type SnapExpr_Exact

type SnapExpr_Exact struct {
	Space string
	Ref   gdat.Ref
}

func ParseSnap_Exact

func ParseSnap_Exact(x string) (*SnapExpr_Exact, error)

func (*SnapExpr_Exact) GetSpace

func (se *SnapExpr_Exact) GetSpace() string

func (*SnapExpr_Exact) Resolve

func (se *SnapExpr_Exact) Resolve(ctx context.Context, tx SpaceTx) (*gdat.Ref, error)

type SnapExpr_Mark

type SnapExpr_Mark struct {
	Space string
	Name  string
}

func ParseSnap_Mark

func ParseSnap_Mark(x string) (*SnapExpr_Mark, error)

func (SnapExpr_Mark) GetSpace

func (se SnapExpr_Mark) GetSpace() string

func (SnapExpr_Mark) Resolve

func (se SnapExpr_Mark) Resolve(ctx context.Context, tx SpaceTx) (*gdat.Ref, error)

func (SnapExpr_Mark) String

func (se SnapExpr_Mark) String() string

type SnapExpr_Offset

type SnapExpr_Offset struct {
	X      SnapExpr
	Offset uint
}

type SnapInfo

type SnapInfo struct {
	AuthoredAt tai64.TAI64  `json:"authored_at"`
	Authors    []inet256.ID `json:"authors"`

	Message string `json:"message"`
}

SnapInfo holds additional information about a snapshot. This is stored as json in the snapshot.

type Space

type Space interface {
	// Do calls fn to perform a transaction.
	Do(ctx context.Context, modify bool, fn func(SpaceTx) error) error
}

A Space holds named gotcore.

type SpaceTx

type SpaceTx interface {
	// Create creates a new Mark at name in the Space.
	// The mark will have md for initial metadata.
	// An error is returned if the name already exists.
	Create(ctx context.Context, name string, md Metadata) (*Info, error)
	// Inspect returns all the info for a Mark
	Inspect(ctx context.Context, name string) (*Info, error)
	// SetMetadata sets the metadata for the Mark at name to md
	SetMetadata(ctx context.Context, name string, md Metadata) error
	// Delete deletes a Mark and all of it's metadata, the Snapshot is not removed.
	Delete(ctx context.Context, name string) error
	// All iterates over all the mark names.
	All(context.Context) iter.Seq2[string, error]

	// Store returns the space's underlying stores
	// These can all be the same store, but each will be passed to different systems.
	// 0: GotFS data stream
	// 1: GotFS metadata
	// 2: GotVC
	Stores() [3]stores.RW
	// SetTarget changes the mark so it points to a different snapshot
	SetTarget(ctx context.Context, name string, ref gdat.Ref) error
	// GetTarget retrieves the Snapshot referenced by gdat.Ref
	GetTarget(ctx context.Context, name string, dst *gdat.Ref) (bool, error)
}

SpaceTx is a transaction on a Space

type Span

type Span struct {
	Begin string
	End   string
}

func TotalSpan

func TotalSpan() Span

func (Span) Contains

func (s Span) Contains(x string) bool

type SyncSpacesTask

type SyncSpacesTask struct {
	// Src is the space to read from.
	Src Space
	// Dst is the name ofthe space to write to.
	Dst Space

	// Filter is applied to src to determine what to copy.
	// If nil, then all marks are copied.
	Filter func(string) bool
	// MapName is applied to go from names in the Src space, to name in the Dst space.
	MapName func(string) string
}

SyncSpacesTask contains parameters needed to copy marks from one space to another.

type VCMach

type VCMach = gotvc.Machine[Payload]

type ViewCtx

type ViewCtx struct {
	VC     *VCMach
	FS     *FSMach
	Stores [3]stores.Reading
	Target gdat.Ref
	Root   *Snap
}

func (*ViewCtx) FSRO

func (vc *ViewCtx) FSRO() [2]stores.Reading

Jump to

Keyboard shortcuts

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