store

package
v0.44.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 43 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package store is the one place Corbie keeps anything: values with names, three ways of writing one, and the directory, bucket and memory stores.

Index

Constants

View Source
const ServedScheme = "corbie://"

ServedScheme begins the address of a directory that another computer serves: corbie://host:port.

View Source
const SideBySide = 16

SideBySide is how many requests one Bounded store has open at once by default: the store of one controller pass, one start or one definition made while a machine runs; and how many of the values a listing names a watcher or a follower reads at once.

View Source
const Version = 2

Version is the layout this Corbie knows.

View Source
const VersionName = "version"

VersionName is the name of the value that holds the layout's version.

Variables

View Source
var (
	// Overwrite writes, or deletes, whatever is there.
	Overwrite = How{/* contains filtered or unexported fields */}
	// OnlyIfNew writes only if nothing has the name yet.
	OnlyIfNew = How{/* contains filtered or unexported fields */}
)
View Source
var (
	// ErrUnreachable is a call the store did not answer.
	ErrUnreachable = errors.New("could not reach the store")
	// ErrRefused is a write, delete or listing the store would not allow.
	ErrRefused = errors.New("the store refused")
	// ErrUnknown is a conditional write whose answer was lost: it may or
	// may not have been written.
	ErrUnknown = errors.New("the store's answer was lost")
	// ErrName is a name no store takes.
	ErrName = errors.New("not a name a store can hold")
	// ErrNothing is a copy of a name that holds nothing.
	ErrNothing = errors.New("nothing is there to copy")
)

Functions

func Above added in v0.17.0

func Above(location string) []string

Above gives a location and each path above it, nearest first, ending with "/".

func AddressesOf added in v0.40.0

func AddressesOf(root string) ([]string, error)

AddressesOf gives the addresses of the members of the directory at root.

func Blob

func Blob(ctl, instance, name string) string

func Blobs

func Blobs(ctl, instance string) string

func Carried

func Carried(ctl, instance string) string

func Check

func Check(ctx context.Context, s Store) error

Check refuses a store whose layout this Corbie does not know.

func CheckInstance

func CheckInstance(name string) error

CheckInstance says whether name has the form of an instance's name.

func CheckLocation added in v0.17.0

func CheckLocation(location string) error

CheckLocation says whether a text can be a location: "/", or "/" then parts, each as CheckLocationPart has it and none holding "*", which makes a pattern.

func CheckLocationPart added in v0.23.0

func CheckLocationPart(part string) error

CheckLocationPart says whether a text can be one part of a location or of a pattern of locations: not empty, ".", ".." or "+", and holding no "#", which separates a key from its location, slash, backslash or control character.

func CheckPart

func CheckPart(part string) error

CheckPart says whether part can be one part of a name: not empty, not starting with a dot, and holding no slash.

func ChildInstance

func ChildInstance(parent string, at time.Time, job string) string

ChildInstance makes the name of an instance below another. It follows from what asked for it, so that asking twice names one child.

func DirectoryAt added in v0.39.0

func DirectoryAt(address string) (string, error)

DirectoryAt gives the directory an address names, where it names one.

func Each added in v0.9.0

func Each(ctx context.Context, limit, n int, do func(i int) error) error

Each does n things side by side, at most limit at a time, and gives the first error. Nothing more is begun once one has failed or the context has ended. One of them may itself do things side by side: what bounds the requests is a store from Bounded.

func Emit

func Emit(ctl, instance string, job, number int) string

Emit is the name of an emit entry of a job: under the job's number in the instance, never its name, since every client lists every record.

func EmitOf added in v0.21.0

func EmitOf(ctl, instance, name string) (job, number int, ok bool)

EmitOf reads the job's number and the entry's number out of the name of an emit entry of an instance.

func Emits

func Emits(ctl, instance string) string

func Finished

func Finished(ctl string) string

func FinishedHead

func FinishedHead(ctl, instance string) string

func HasMembers added in v0.39.0

func HasMembers(root string) bool

HasMembers says whether the directory at root has members.

func House

func House(ctl string) string

House is the name the controller's own wake is under, where an instance's name would be: the wake for its hourly housekeeping.

func Inbox

func Inbox(party string) string

func InstanceClient

func InstanceClient(instance string) string

InstanceClient is the client that owns the tree of the instance's root.

func InstanceOf

func InstanceOf(ctl, name string) string

InstanceOf reads the instance out of a head's or a record entry's name.

func InstanceTime

func InstanceTime(instance string) (time.Time, error)

InstanceTime is the time the instance was named.

func IsDirectory

func IsDirectory(address string) bool

IsDirectory says whether an address names a directory, which keeps no party out of anything.

func IsServed

func IsServed(address string) bool

IsServed says whether an address names a directory another computer serves.

func JobMessage

func JobMessage(instance, job string) string

JobMessage is the name a job has in its runner's inbox and among its marks: fixed by its instance and its name.

func Key added in v0.12.0

func Key(ctl, location, key string) string

Key is the name of a key's file among a location's. A key is any text, so the name holds its hash and never the key itself. A singleton's is the empty key.

func Keys added in v0.17.0

func Keys(ctl, location string) string

func Leader added in v0.40.0

func Leader(ctx context.Context, member, party string, proof tls.Certificate, keeper ed25519.PublicKey) (leads bool, leader string, err error)

Leader asks the member at an address, host:port, who leads the store, as a party. It says whether that member leads, or else the address of the member it names, which is nothing where it knows of none. An error is a member that did not answer.

func LeaveMembers added in v0.39.0

func LeaveMembers(root string) error

LeaveMembers makes the copy at root the whole store, with one member: the log goes, and what of it was not applied goes with it.

func LinkMessage

func LinkMessage(from string, step, index int, what string) string

LinkMessage is the name of a message the controller sends itself for one instance on behalf of another: fixed by the step that asked for it, and sorting in the order that instance's steps asked.

func LocationBlob added in v0.17.0

func LocationBlob(ctl, location, name string) string

func LocationBlobs added in v0.17.0

func LocationBlobs(ctl, location string) string

func LocationDir added in v0.17.0

func LocationDir(ctl, location string) string

LocationDir is where the entries of one location are: under "+" after its path, and "+" is never a part of a location, so no location's entries are a path above another's. The entries of "/" are under locations/+.

func LocationFile added in v0.17.0

func LocationFile(ctl, location string) string

func Locations added in v0.17.0

func Locations(ctl string) string

Locations is where everything set at a location is kept.

func MemberID added in v0.40.0

func MemberID(key ed25519.PublicKey) uint64

MemberID is the number a member is known to the others by, made of the key of the member's own card. A computer that takes a member's place has another card, and so another number under the same name.

func Message

func Message(party, sender, message string) string

func Names added in v0.9.0

func Names(listed []Listed, err error) ([]string, error)

Names gives the names of a listing, in its order, for a caller that needs no marks: names, err := Names(s.List(ctx, under)).

func NewInstance

func NewInstance(client string, now time.Time) string

NewInstance makes the name of a new root instance for a client.

func Number

func Number(name string) int

Number reads the number at the end of a step's or an emit's name.

func ParseLocation added in v0.17.0

func ParseLocation(ctl, name string) (location, entry string, ok bool)

ParseLocation reads the location out of the name of one of its entries, and what follows the location's "+".

func ParseWake

func ParseWake(ctl, name string) (at time.Time, instance, what string, ok bool)

ParseWake reads a wake's name.

func Policy

func Policy(p Party, bucket, prefix string, also ...string) (string, error)

Policy prints the policy that limits a party's key for a bucket to its row of the table. bucket is the bucket's name and prefix the path the store's address gives after it. The policy is written to be attached to the party's key; set on the bucket itself, each statement needs that key as its principal as well.

Every write a limited party may make is allowed only when the request carries If-None-Match, which is what makes it only-if-new. The steps of a large upload that put nothing under a name are allowed without it, as is giving such an upload up. Listing is allowed only under the paths the party may list. Each name in also is an object in a bucket of its own that the party reads beside its row.

Amazon S3 enforces all of this. A service that takes the same requests but does not know the condition key s3:if-none-match cannot hold a party to only-if-new, and so cannot enforce the table whatever else it does.

A policy cannot say "any one part of a name", so where the table has any one part the policy has any path. A limited party can therefore add names deeper than the layout draws; it still can never replace or remove one.

func PolicyFor

func PolicyFor(address string, p Party, kept, name string) (string, error)

PolicyFor prints the policy for a party of the bucket an address names. Where kept is the address of another bucket, the policy lets the party read the object of that name there as well.

func Proof

func Proof(key ed25519.PrivateKey) (tls.Certificate, error)

Proof is what an end of a served directory's wire shows of itself as a connection is made: its identity key and nothing else. Whoever shows it is known to hold the key's other half.

func Receipt

func Receipt(ctl, sender, message string) string

Receipt is the name of the controller's answer to a client's message: in a directory of the message's own name.

func ReceiptBlob added in v0.17.0

func ReceiptBlob(ctl, sender, message, name string) string

ReceiptBlob is the name of a blob a call's result names.

func ReceiptBlobs added in v0.17.0

func ReceiptBlobs(ctl, sender, message string) string

ReceiptBlobs is where the blobs a call's result names are.

func ReceiptMessage added in v0.17.0

func ReceiptMessage(ctl, name string) (message string, ok bool)

ReceiptMessage reads the message out of the name of a receipt or of one of its blobs.

func Receipts

func Receipts(ctl, sender string) string

func Record

func Record(ctl, instance string) string

func Records

func Records(ctl string) string

func Result added in v0.17.0

func Result(ctl, sender, message string) string

Result is the name of what became of the run a client called in a tree it does not own, beside the call's receipt.

func RootInstance added in v0.17.0

func RootInstance(client string, at time.Time, from string) string

RootInstance makes the name of a root instance that the controller starts for a client, as a submit starts a singleton. It follows from what asked for it, so that asking twice names one instance.

func Running

func Running(ctl string) string

func RunningHead

func RunningHead(ctl, instance string) string

func Secret

func Secret(ctl, at, name string) string

func Secrets

func Secrets(ctl, at string) string

func ServedAddress added in v0.42.0

func ServedAddress(s Store) string

ServedAddress gives the address of a served directory as the store has it now, with the members a member last named, or nothing for any other store.

func ServedHosts added in v0.39.0

func ServedHosts(address string) ([]string, error)

ServedHosts gives the members a served directory's address names, each as host:port: corbie://host:port, or with several members corbie://host:port,host:port,host:port.

func ServedListener

func ServedListener(l net.Listener, keeper tls.Certificate) net.Listener

ServedListener takes the connections to a served directory: the keeper proves its key to each, and each has to prove a key of its own. Whose key that is the server asks at every request. No connection is taken up again from an earlier one, so nothing of a connection outlives it.

func SetJoining added in v0.40.0

func SetJoining(root, name, address string, ask []string) error

SetJoining sets the directory at root up to join a store's members: the computer itself, by the name and address it is to have, and the addresses of the members it is to ask.

func SetMembers added in v0.39.0

func SetMembers(root string, members []MemberAt) error

SetMembers writes the members file: a line for each member, with its name, its address and, where it is joining, the word joining.

func SetUp

func SetUp(ctx context.Context, s Store) error

SetUp writes the layout's version into a store that has none.

func Stamp

func Stamp(t time.Time) string

Stamp writes a time as it appears in names.

func Step

func Step(ctl, instance string, number int) string

Step is the name of a step entry. Numbers are written so that names sort in number order.

func Steps

func Steps(ctl, instance string) string

func Taken

func Taken(runner string, due time.Time, job string) string

Taken is the name of the mark a runner leaves for a job it has taken. The name carries the job's due time, so the marks whose time has passed are found by listing alone.

func TakenList

func TakenList(runner string) string

func TakenOf

func TakenOf(name string) (job string, due time.Time, ok bool)

TakenOf gives the job a mark is for, and the job's due time.

func Tree added in v0.17.0

func Tree(ctl, prefix string) string

Tree is the name of the entry of a tree submitted at a prefix.

func Tried added in v0.12.0

func Tried(ctl, instance string) string

func Trust

func Trust(ctl, party string) string

func TrustList

func TrustList(ctl string) string

func Unreported added in v0.37.0

func Unreported(s Store) error

Unreported says why the operating system does not report to this process what other processes write into a directory store, where a wait on the store asked it to and it refused. Any other store gives nil.

func Upload added in v0.17.0

func Upload(ctl, client, message, name string) string

Upload is the name of a file a client sends with a message.

func Uploaded added in v0.17.0

func Uploaded(ctl, client, message string) string

Uploaded is where the files a client sends with one message are.

func Uploads added in v0.17.0

func Uploads(ctl, client string) string

func Value added in v0.17.0

func Value(ctl, at, name string) string

func Values added in v0.17.0

func Values(ctl, at string) string

func Wake

func Wake(ctl string, at time.Time, instance, what string) string

Wake is the name of a wake: wakes list soonest first.

func Wakes

func Wakes(ctl string) string

Types

type Act

type Act int

Act is one thing a party does to a name.

const (
	ActRead Act = 1 << iota
	ActList
	ActAdd     // write only-if-new
	ActRewrite // overwrite or write only-if-unchanged
	ActDelete
)

func (Act) String

func (a Act) String() string

type How

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

How is one of the three ways of writing.

func OnlyIfUnchanged

func OnlyIfUnchanged(mark Mark) How

OnlyIfUnchanged writes, or deletes, only if the value is still the one that was read with mark.

func (How) String

func (h How) String() string

type Kind

type Kind int

Kind is what a party is to the store.

const (
	// Nobody may read the layout's version and nothing else.
	Nobody Kind = iota
	Controller
	Runner
	Client
	// Viewer is a party given heads only.
	Viewer
	// Owner is whoever runs the store: no rule holds them.
	Owner
)

type Listed added in v0.9.0

type Listed struct {
	Name string
	Mark Mark
}

A Listed is one name a listing gives, with the mark a read of it gives: a value that has not changed since it was read is listed with the mark it was read with.

type Mark

type Mark string

A Mark is what a read saw of a value, for a later only-if-unchanged.

const None Mark = ""

None is the mark of a name that holds nothing.

type Member added in v0.39.0

type Member struct {
	// Failed is told of what stops the member.
	Failed func(error)
	// Held is told of what goes wrong between this member and another and
	// does not stop it: a member that does not give it the directory.
	Held func(error)
	// contains filtered or unexported fields
}

A Member is one computer's part in a served directory: its copy, and with more than one member its place among them.

func OpenMember added in v0.39.0

func OpenMember(dir, name string, id uint64, self string, proof tls.Certificate) (*Member, error)

OpenMember opens this computer's copy of a served directory, as the member of a name and a number, which other computers reach at self, host:port. proof is the key of the store's controller, which every member holds.

func (*Member) Address added in v0.39.0

func (m *Member) Address() string

Address is where other computers reach the member, as host:port.

func (*Member) Directory added in v0.39.0

func (m *Member) Directory() Store

Directory is the member's copy, as its server reads and writes it.

func (*Member) Err added in v0.39.0

func (m *Member) Err() error

Err gives what stopped the member, where something did.

func (*Member) Led added in v0.39.0

func (m *Member) Led() bool

Led says whether the member knows of a leader, itself or another: a majority of the members can then reach each other.

func (*Member) Members added in v0.39.0

func (m *Member) Members() (voters, joining []string, leader string, many bool)

Members gives the members' names as this member has them, voters first, the leader's address where it knows one, and whether the directory has more than one member at all.

func (*Member) Remove added in v0.39.0

func (m *Member) Remove(ctx context.Context, name string) error

Remove takes the member of a name out of the store's members. It is asked of whichever member leads.

func (*Member) Start added in v0.39.0

func (m *Member) Start() error

Start has the member take its place: among the members its copy records, or, on a computer set up to join, by asking them to take it. With one member it starts nothing.

func (*Member) Stop added in v0.39.0

func (m *Member) Stop()

Stop ends the member's part. Its copy stays as it is.

type MemberAt added in v0.40.0

type MemberAt struct {
	Name    string
	Address string
	Joining bool
}

A MemberAt is a member as the members file lists it: its name, the address the others reach it at, as host:port, and whether it is joining: it copies the directory, and does not yet count.

func MembersOf added in v0.39.0

func MembersOf(root string) ([]MemberAt, error)

MembersOf gives the members of the directory at root, by name, or none where the directory has one member.

type Memory

type Memory struct {

	// Note, when set, is told of everything done to the store. What a party
	// was refused was not done, and is not told.
	Note func(Op)
	// contains filtered or unexported fields
}

Memory is a store held in memory, for `corbie test` and Corbie's own tests. Each party opens it with As and is held to its row of the table, as a bucket would hold it.

func NewMemory

func NewMemory() *Memory

NewMemory makes an empty memory store.

func (*Memory) As

func (m *Memory) As(p Party) Store

As opens the store as a party, held to its row of the table.

type Op

type Op struct {
	Party Party
	Act   Act
	Name  string
	How   How
	Value []byte // what was written, or read
	Done  bool   // false for "not there", "already there" or "changed"
}

An Op is one thing a party did to a memory store.

type Party

type Party struct {
	Kind       Kind
	Name       string
	Controller string
}

A Party is one row of the table of who may touch what. Controller is the controller whose area a runner, a client or a viewer works in.

func (Party) Allows

func (p Party) Allows(act Act, name string) bool

Allows says whether the party may do act to name. For ActList, name is the path listed.

type Sender

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

A Sender names one sender's messages so that they sort in the order they were sent, also when two are sent in the same instant or the clock steps back.

func (*Sender) Next

func (s *Sender) Next(now time.Time) string

Next gives the name of the next message.

type Server

type Server struct {
	// Directory is the directory served.
	Directory Store
	// Member is this computer's part in a directory with members. With it,
	// the server answers a party only while this member leads the others,
	// and otherwise says who does.
	Member *Member
	// Who says which party a name is and which key is its own. A name that
	// is no party of the controller's has no key.
	Who func(ctx context.Context, name string) (Party, ed25519.PublicKey, error)
	// Failed is told of what went wrong at this end. A party is told only
	// that something did: the error itself can name this computer's paths.
	Failed func(err error)
	// Timeout is how long a party may send nothing of a value it is sending.
	// None is no limit.
	Timeout time.Duration
	// contains filtered or unexported fields
}

A Server serves a directory to the parties of one controller.

func (*Server) HTTP added in v0.25.0

func (s *Server) HTTP() *http.Server

HTTP gives the server that takes the requests. A connection that sends nothing for the timeout, between two requests, is closed.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server) Stop

func (s *Server) Stop()

Stop has every party that is waiting answered at once, so that a server being stopped is not kept up by those it has nothing to tell.

type Store

type Store interface {
	// Read gives the value under name and the mark to write it back
	// only-if-unchanged. A name that holds nothing, or that this party may
	// not read, gives the mark None.
	Read(ctx context.Context, name string) ([]byte, Mark, error)

	// ReadPart gives up to length bytes of the value under name starting at
	// from: fewer where the value ends first, none where it is not there.
	ReadPart(ctx context.Context, name string, from, length int64) ([]byte, error)

	// Write writes the value in the way how says, and says whether it did.
	Write(ctx context.Context, name string, value []byte, how How) (bool, error)

	// WriteFrom writes a value of any size only-if-new, reading it from r.
	// The value is under its name only once all of it is in.
	WriteFrom(ctx context.Context, name string, r io.Reader) (bool, error)

	// Copy puts the value under from under to as well, only-if-new, without
	// its bytes passing through the caller.
	Copy(ctx context.Context, from, to string) (bool, error)

	// Delete removes the value under name: whatever is there (Overwrite) or
	// only-if-unchanged. Deleting a name that holds nothing is done.
	Delete(ctx context.Context, name string, how How) (bool, error)

	// List gives every name under the path, in the order names sort, each
	// with the mark a read of it gives.
	List(ctx context.Context, under string) ([]Listed, error)

	// First gives the first names under the path, in the order names sort,
	// and no more than n of them (at most a thousand), each with the mark a
	// read of it gives. It costs one look, however many names there are:
	// what is owed to time is read this way, soonest first.
	First(ctx context.Context, under string, n int) ([]Listed, error)

	// Notice gives a channel that is sent to when this process writes or
	// deletes a name under the path, and a func that ends it. A directory
	// sends to it as well when another process on the computer writes or
	// deletes a message in an inbox or a running head under the path.
	Notice(under string) (<-chan struct{}, func())
}

A Store holds named values. Every call concerns one name and nothing is held between calls.

"Not there", "already there" and "changed" are answers, never errors: a read gives the mark None, and a write or delete gives false. An error means the store could not be reached or refused the call.

func Bounded added in v0.9.0

func Bounded(s Store, n int) Store

Bounded gives a store that has at most n requests open at once, wherever they come from. A request waits for a place, and one whose context has ended is not made.

func Open

func Open(address string) (Store, error)

Open opens the store an address names. The address alone says which kind it is: "memory:" is a new memory store, "s3://…" a bucket, "corbie://…" a directory another computer serves, which OpenServed opens, and anything else a directory.

func OpenDirectory

func OpenDirectory(dir string) (Store, error)

OpenDirectory opens the directory store at dir. Nothing is made until something is written.

func OpenLocal added in v0.39.0

func OpenLocal(dir, self, party string, proof tls.Certificate, keeper ed25519.PublicKey) (Store, error)

OpenLocal opens the directory at dir as a party on the computer that holds it. self is the address of this computer's member, as host:port, which the party asks first: it is the nearest, and names the leader. proof is the party's own, and keeper the key of the store's controller, which every member proves.

func OpenServed

func OpenServed(address, party string, proof tls.Certificate, keeper ed25519.PublicKey, moved func(address string)) (Store, error)

OpenServed opens the directory served at an address as a party: proof is the party's own, and keeper is the key of the controller whose machine serves the directory. moved, where given, is told the store's address each time a member names other members than the party has.

Jump to

Keyboard shortcuts

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