store

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 21 Imported by: 0 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 keeps the git objects of a repository in packs and the operation objects of a workspace, in one object store. HTTP, grants and the SQL index are in other packages.

Index

Constants

View Source
const (
	MaxOpBytes   = 8 << 20
	MaxPackBytes = 64 << 20
	MaxIdxBytes  = 8 << 20
	// MaxBlobBatchBytes bounds the blobs that one batch read returns.
	MaxBlobBatchBytes = 16 << 20
	// MaxBatch bounds the objects of one put.
	MaxBatch = 100000

	// SlotRead is the weight of a request that holds one object in memory.
	// SlotWrite is the weight of a request that holds a large body.
	SlotRead  = 1
	SlotWrite = slotCapacity
)

Variables

View Source
var (
	ErrNotConfigured = errors.New("store: no object store")
	ErrNotFound      = errors.New("store: object not found")
	ErrInvalid       = errors.New("store: invalid object name or content")
	ErrTooLarge      = errors.New("store: object too large")
)

Functions

func ValidWorkspaceID

func ValidWorkspaceID(id string) bool

ValidWorkspaceID reports whether id can name a workspace.

Types

type Entry

type Entry struct {
	Name string
	Mode uint32
	SHA  gitpack.SHA
	Size int64
}

type OpKind

type OpKind string
const (
	OpOperation OpKind = "operations"
	OpView      OpKind = "views"
)

type PackIndex

type PackIndex interface {
	AddPack(ctx context.Context, repo Repo, packID string, bytes int64) error
	Packs(ctx context.Context, repo Repo) ([]PackRef, error)
}

PackIndex lists the packs of a repo, oldest first.

type PackRef

type PackRef struct {
	ID    string
	Bytes int64
}

type Repo

type Repo struct{ Prefix, Path string }

Repo names a repository as <prefix>:<path>.

func ParseRepo

func ParseRepo(s string) (Repo, error)

ParseRepo reads the text form. It rejects a prefix or a path that the object keys cannot carry.

func (Repo) String

func (r Repo) String() string

type Service

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

Service stores the objects of every repo and workspace in one object store.

func New

func New(st objstore.Store, index PackIndex) *Service

func (*Service) Blobs

func (s *Service) Blobs(ctx context.Context, repo Repo, shas []gitpack.SHA) ([][]byte, error)

func (*Service) Commit

func (s *Service) Commit(ctx context.Context, repo Repo, sha gitpack.SHA) (gitpack.SHA, time.Time, error)

Commit returns the tree of a commit and its committer time.

func (*Service) Get

func (s *Service) Get(ctx context.Context, repo Repo, sha gitpack.SHA) (gitpack.Type, []byte, error)

func (*Service) GetOp

func (s *Service) GetOp(ctx context.Context, ws string, kind OpKind, id string) ([]byte, error)

func (*Service) Has

func (s *Service) Has(ctx context.Context, repo Repo, shas []gitpack.SHA) ([]bool, error)

Has reports for each sha whether a pack of the repo holds it. It reads the pack indexes only.

func (*Service) ImportPack

func (s *Service) ImportPack(ctx context.Context, repo Repo, id string, idx, pack []byte) error

ImportPack stores a pack and its v2 index under the SHA-256 of the pack.

func (*Service) PutObjects

func (s *Service) PutObjects(ctx context.Context, repo Repo, objs []gitpack.Object) ([]gitpack.SHA, error)

PutObjects stores objects as one pack and returns their names in order.

func (*Service) PutOp

func (s *Service) PutOp(ctx context.Context, ws string, kind OpKind, id string, data []byte) error

func (*Service) Slot

func (s *Service) Slot(ctx context.Context, weight int64) (release func(), err error)

Slot reserves weight units of the memory that large requests may hold. The caller releases it.

func (*Service) TreeBulk

func (s *Service) TreeBulk(ctx context.Context, repo Repo, sha gitpack.SHA, maxEntries int) ([]Tree, error)

TreeBulk returns a tree and its subtrees breadth first, until the entries returned reach maxEntries. Blob entries carry their size.

type Stats

type Stats struct {
	Objects, Bytes, Packs, RangeReads, RangeBytes, MaxDepth, SlotWaitNanos atomic.Int64
}

Stats counts what one request read from the store. A handler puts one in the context with WithStats and reads it when the request ends. A nil *Stats counts nothing.

func StatsFrom

func StatsFrom(ctx context.Context) *Stats

StatsFrom returns the Stats of a request, or nil.

func WithStats

func WithStats(ctx context.Context) (context.Context, *Stats)

WithStats returns ctx with a Stats that the reads of the request fill.

func (*Stats) AddSlotWait

func (s *Stats) AddSlotWait(d time.Duration)

AddSlotWait adds the time a request waited for a weighted slot.

type Tree

type Tree struct {
	SHA     gitpack.SHA
	Entries []Entry
}

Jump to

Keyboard shortcuts

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