Documentation
¶
Overview ¶
Package gitstore is the index behind the chassis `git` personality and the txco://repo/* ops: which repositories a tenant has, which objects each holds (an object id → the content-addressed store's key, with the object's type and size), and where its refs point. The bytes are not here: a git object's content lives in the chassis's content-addressed store (chassis/filecas) under the sha256 of that content, so a blob's key is the file's own hash and the store deduplicates across everything else the chassis keeps. This index is the tenant fence over that shared store: an object is served only when the repository's row names it, never by probing the store on a client's behalf.
Refs move by compare-and-swap, all of a push's refs or none, in one write transaction; every move leaves a log row saying who moved what from where to where (the audit the design asks for: the principal and credential of a push, the stack of an op). There is no garbage collection: objects a ref no longer reaches stay indexed, as the blob plane's do (docs/advanced/blobs.md).
Storage is dialect-aware (registry.Dialect, the seam the drive, calendar and contacts indexes use); the bundled backend is a SQLite file of its own, never the runtime DB (a runtime-DB write reloads the whole dbcache mirror). A fleet overlay registers a shared Postgres backend the same way so the head on any node serves what an op on any node wrote.
Index ¶
- Constants
- Variables
- func Register(name string, c Constructor)
- type Actor
- type Config
- type Constructor
- type ErrRefMoved
- type Object
- type Quotas
- type Ref
- type RefLogEntry
- type RefUpdate
- type Repo
- type Store
- func (s *Store) Close() error
- func (s *Store) CompareAndSetRefs(ctx context.Context, repoID string, updates []RefUpdate, by Actor) error
- func (s *Store) CreateRepo(ctx context.Context, r Repo) (Repo, bool, error)
- func (s *Store) DB() *sql.DB
- func (s *Store) EnsureSchema(ctx context.Context) error
- func (s *Store) GetObject(ctx context.Context, repoID, oid string) (Object, bool, error)
- func (s *Store) GetRef(ctx context.Context, repoID, name string) (Ref, bool, error)
- func (s *Store) GetRepo(ctx context.Context, tenant, name string) (Repo, bool, error)
- func (s *Store) GetRepoByID(ctx context.Context, id string) (Repo, bool, error)
- func (s *Store) ListObjects(ctx context.Context, repoID, typ string) ([]Object, error)
- func (s *Store) ListRefs(ctx context.Context, repoID string) ([]Ref, error)
- func (s *Store) ListRepos(ctx context.Context, tenant string) ([]Repo, error)
- func (s *Store) ObjectStats(ctx context.Context, repoID string) (count, bytes int64, err error)
- func (s *Store) PutObjects(ctx context.Context, repoID string, objs []Object) error
- func (s *Store) RefLog(ctx context.Context, repoID string, limit int) ([]RefLogEntry, error)
- func (s *Store) RemoveRepo(ctx context.Context, id string) error
- func (s *Store) SetClock(now func() time.Time)
Constants ¶
const ZeroOID = "0000000000000000000000000000000000000000"
ZeroOID is git's "no object": the Old of a ref being created, the New of one being deleted.
Variables ¶
var ( // ErrNotFound is a missing repository. ErrNotFound = errors.New("gitstore: not found") )
Functions ¶
func Register ¶
func Register(name string, c Constructor)
Register adds a backend constructor. Called from a backend package's init(): the bundled sqlite one here, an overlay's Postgres one in the service binary.
Types ¶
type Actor ¶
type Actor struct {
Principal string
Credential string
// Source is "push" or "op".
Source string
// Stack is the stack whose op moved the ref ("" for a push).
Stack string
}
Actor is who moved refs, for the log.
type Config ¶
type Config struct {
// DBPath is the bundled SQLite backend's file path (--git-db-path).
DBPath string
}
Config carries the backend-selecting options resolved from chassis config. The bundled "sqlite" backend uses DBPath; a shared backend (the fleet's Postgres overlay) reads its DSN from the environment.
type Constructor ¶
Constructor builds a Store from resolved config. It opens its backing DB and calls Store.EnsureSchema before returning.
type ErrRefMoved ¶
ErrRefMoved is the compare-and-swap failure: the ref is not at the Old the writer named. Current is ZeroOID for a ref that does not exist.
func (*ErrRefMoved) Error ¶
func (e *ErrRefMoved) Error() string
type Object ¶
type Object struct {
OID string
Type string // blob | tree | commit | tag
Size int64
SHA256 string
// Inline holds the content itself for a small object, when a backend
// chooses to keep it in the row (nil: the content is in the store).
Inline []byte
}
Object is one indexed git object: the id, what it is, how big, and where its content is.
type RefLogEntry ¶
type RefLogEntry struct {
ID string
Name string
Old string
New string
Principal string
Credential string
Source string
Stack string
At time.Time
}
RefLogEntry is one row of the audit log.
type RefUpdate ¶
RefUpdate is one move: Old must be the current value (ZeroOID when the ref must not exist), New the value to set (ZeroOID to delete).
type Repo ¶
type Repo struct {
// ID is `rp_<hxid>`, minted at create.
ID string
// Tenant is the tenant slug (the one the hostname resolves to and the
// ops run as).
Tenant string
// Name is the repository's name: the path segment a client clones
// (`/git/<name>.git`) and the instance of its `git:<name>:*` scopes.
Name string
// Principal owns the repository: the identity whose credentials the
// application issues for it. Recorded for the administrative ops; a
// push is authorized by its credential's scopes, not by this.
Principal string
// CreatedBy is the stack that made the repository: the one that may
// remove it.
CreatedBy string
// PolicyPush is "stack" (a push is accepted only when the tenant's
// `_git` stack answers ok) or "open" (no lane).
PolicyPush string
// Head is the ref HEAD names (refs/heads/main).
Head string
Quotas Quotas
CreatedAt time.Time
}
Repo is one repository's row.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the façade over the index tables.
func NewStore ¶
NewStore builds a Store over the opened DB and its dialect. A nil dialect defaults to SQLite.
func Open ¶
Open constructs the named backend. An unknown name is a startup error listing what is available (so a misconfigured --git-store fails loudly).
func OpenSQLiteFile ¶
OpenSQLiteFile opens the bundled backend at path (tests and tools).
func (*Store) CompareAndSetRefs ¶
func (s *Store) CompareAndSetRefs(ctx context.Context, repoID string, updates []RefUpdate, by Actor) error
CompareAndSetRefs moves refs, all or none: every update's Old must equal the ref's current value (ZeroOID for one that does not exist), or the first mismatch is returned as *ErrRefMoved and nothing changes. A ZeroOID New deletes the ref. Each move leaves a log row naming the actor.
func (*Store) CreateRepo ¶
CreateRepo makes the repository, or returns the existing one of that tenant and name (created = false): the create is idempotent so an application may "ensure" a repository. The id is minted here; Head defaults to refs/heads/main, PolicyPush to "stack".
func (*Store) EnsureSchema ¶
EnsureSchema creates the tables and indexes if absent. Portable DDL: TEXT ids, TEXT RFC3339 timestamps, BIGINT counters, BYTEA for the one binary column — one DDL serves SQLite and Postgres. Additive-only.
func (*Store) GetRepoByID ¶
GetRepoByID finds a repository by id.
func (*Store) ListObjects ¶
ListObjects lists the repository's objects, of one type or all (""). Metadata only (no inline content).
func (*Store) ObjectStats ¶
ObjectStats reports how many objects the repository indexes and their total size (the repository's size for the quota).
func (*Store) PutObjects ¶
PutObjects indexes objects; one already indexed is left alone (the same id is the same content).
func (*Store) RemoveRepo ¶
RemoveRepo deletes a repository and its index rows (refs, objects, log). The objects' content stays in the content-addressed store. ErrNotFound when there is no such repository.