Documentation
¶
Overview ¶
Package appstore is the storage of an app's views (hl.storage.<scope>) without the rest of the apps: the areas, their limits, the versions of their keys (ifVersion) and where an area's file lives. The runtime keeps the install's area on its disk and, under a hub, every other area in the hub's store, so the data of an app is the same on every machine of a space and is there with the machines off; the hub answers a view it serves with the same code. It imports nothing of the runtime or the hub.
Index ¶
- Constants
- Variables
- func CheckKey(key string) error
- func Path(app string, scope Scope, name string) (string, error)
- func ValidApp(app string) bool
- func ValidOwner(owner string) bool
- func WriteFileAtomic(file string, data []byte) error
- type Area
- type Client
- type ConflictError
- type Files
- type Folder
- type Room
- type Scope
Constants ¶
const HostKeyPrefix = "__hl_"
HostKeyPrefix begins the keys the host keeps in an app's areas (VersionsKey, the workflow of a document): a view neither reads nor writes them as keys.
const MaxAreaBytes = 10 << 20
MaxAreaBytes is the largest area of any scope.
const MaxKeyBytes = 256
MaxKeyBytes is the longest key.
const StorePrefix = "storage/"
StorePrefix is the folder of the apps' areas in a space's apps collection of the store: storage/<Path>.
const VersionsKey = "__hl_versions"
VersionsKey is where an area's file keeps the version of each key, next to the values. A key's version is a counter that only grows: a write adds one, a delete adds one too and keeps the number, so a key made anew never repeats a version a reader holds. A key with no version (data written before versions) is at 0. The name is not a key a caller can use.
Variables ¶
var ( // ErrQuota: the write would take the area past its limit. ErrQuota = errors.New("apps: the storage area is full") // ErrArgs: a scope, owner or key that is not one. ErrArgs = errors.New("apps: bad storage arguments") // ErrConflict: a write that named the version it read (ifVersion) found the key moved on. The error is a // *ConflictError, which carries the version the key has now. ErrConflict = errors.New("apps: the key changed since it was read") // ErrMoved: an area's file is no longer at the revision a write was made on (another machine wrote it); the // write is made again on top of the new one. ErrMoved = errors.New("apps: the area changed under the write") )
var Limit = map[Scope]int{ ScopeInstall: 5 << 20, ScopeUser: 1 << 20, ScopeChat: 256 << 10, ScopeSpace: 10 << 20, ScopeDoc: 100 << 10, }
Limit is the most one area may hold, in bytes of its JSON file.
var Total = map[Scope]int64{ ScopeInstall: 5 << 20, ScopeUser: 1 << 20, ScopeChat: 20 << 20, ScopeSpace: 10 << 20, ScopeDoc: 20 << 20, }
Total is the most all the areas of one scope of one app may hold together, so many chats or documents cannot add up past what the scope is meant to cost.
Functions ¶
func Path ¶
Path is where an area's file is, relative to the storage's root: <app>/<scope>/<name>.json. name is the chat or document for a scope per owner, and "area" for the others; in the hub's store a user area is named by the person and a chat's by the person and the chat (<person>.<chat>), so the hub shows them only to that person's machines.
func ValidOwner ¶
ValidOwner says whether a text can name the chat or document an area belongs to.
func WriteFileAtomic ¶
WriteFileAtomic writes a file through a temporary one beside it, so a reader never sees half of it.
Types ¶
type Area ¶
type Area struct {
Values map[string]json.RawMessage
Versions map[string]int64
}
Area is an area as its file holds it: the values and the version of each key.
func Update ¶
func Update(ctx context.Context, f Files, scope Scope, rel string, quota bool, change func(*Area) (bool, error)) (*Area, error)
Update changes an area: change gets the area as it is and says whether it changed it (or refuses with an error); the file is written only then, and only inside the scope's limits (quota false: a delete, which never needs room). A write that finds the area moved on runs change again on the new one. It answers the area as written.
type Client ¶
type Client interface {
Current(ctx context.Context, path string) (*filestore.Entry, error)
GetBlob(ctx context.Context, sha string, w io.Writer) error
PutBlob(ctx context.Context, sha string, data []byte) error
Commit(ctx context.Context, req filestore.CommitRequest) (filestore.CommitResponse, error)
Snapshot(ctx context.Context, prefix string, at int64) (filestore.Snapshot, error)
}
Client is the store's API as a machine speaks it (filesync.Client).
type ConflictError ¶
type ConflictError struct{ Current int64 }
ConflictError is the refusal of a write whose ifVersion is not the key's version; Current is the version it has.
func (*ConflictError) Error ¶
func (e *ConflictError) Error() string
func (*ConflictError) Is ¶
func (e *ConflictError) Is(target error) bool
type Files ¶
type Files interface {
// Read is a file and the revision it is at; nil and the revision of its deletion (0 when it never was) when
// there is none.
Read(ctx context.Context, rel string) (data []byte, rev int64, err error)
// Write puts a file (nil deletes it) on top of the revision base Read gave; ErrMoved when it is no longer there.
Write(ctx context.Context, rel string, base int64, data []byte) error
// Weigh is what the files under a folder (rel, no slash at the end) weigh together.
Weigh(ctx context.Context, dir string) (int64, error)
}
Files is where areas' files are kept: a folder on the machine, or a room of the hub's store.
func ClientFiles ¶
ClientFiles is areas' files in the hub's store, as a machine reaches them; author names the writer of a revision.
type Folder ¶
type Folder string
Folder is areas' files in a folder of the machine. Its revisions are all 0: the writers of one folder are one process, which holds its own lock around a read and the write after it.
type Room ¶
type Room interface {
Current(ctx context.Context, path string) (*filestore.Entry, error)
OpenBlob(ctx context.Context, sha string) (io.ReadCloser, error)
PutBlob(ctx context.Context, sha string, r io.Reader) error
Commit(ctx context.Context, req filestore.CommitRequest, machine string) (*filestore.Entry, bool, error)
Snapshot(ctx context.Context, prefix string, at int64) (filestore.Snapshot, error)
}
Room is a room of the store as the hub reads it itself (filestore.Store).