Documentation
¶
Index ¶
- Constants
- Variables
- func CopyBlob(ctx context.Context, st Store, s gitpack.SHA, size int64, w io.Writer) error
- func EncodeTree(es []Entry) []byte
- func EvictTo(max int64, dir string)
- func HoldNodeCache(dir string) (release func(), err error)
- func Maintain(ctx context.Context, o MaintainOptions)
- func RemoveStrayTemps(dir string)
- func SeedCacheSize(dir string)
- func SeedTier2Bytes(n int64)
- func Tier2Bytes() int64
- func Tier2Evictions() int64
- type BlobFile
- type BlobPrefetch
- type BlobPutter
- type BlobStreamBatcher
- type BlobStreamer
- type Cache
- func (c *Cache) AddTree(t *Tree)
- func (c *Cache) Adopt(tmp *os.File, s gitpack.SHA, size int64) error
- func (c *Cache) Blob(ctx context.Context, e Entry, next func(yield func(Entry) bool)) (string, error)
- func (c *Cache) BlobPath(s gitpack.SHA) string
- func (c *Cache) CachedTree(sha gitpack.SHA) *Tree
- func (c *Cache) Close() error
- func (c *Cache) File(ctx context.Context, s gitpack.SHA) (*os.File, error)
- func (c *Cache) HasBlob(s gitpack.SHA) bool
- func (c *Cache) Open(ctx context.Context, e Entry, next func(yield func(Entry) bool)) (BlobFile, error)
- func (c *Cache) OpenHeld(s gitpack.SHA) (BlobFile, bool)
- func (c *Cache) PrefetchBlobs(ctx context.Context, root gitpack.SHA, maxEntries int, maxBytes int64) (BlobPrefetch, error)
- func (c *Cache) PrefetchTrees(ctx context.Context, root gitpack.SHA, maxEntries int) (TreePrefetch, error)
- func (c *Cache) ReadBlob(ctx context.Context, e Entry) ([]byte, error)
- func (c *Cache) Spool() (*os.File, error)
- func (c *Cache) Tree(ctx context.Context, sha gitpack.SHA) (*Tree, error)
- func (c *Cache) TreeLimit(ctx context.Context, sha gitpack.SHA, bulk int) (*Tree, error)
- func (c *Cache) UseSegments() error
- type Entry
- type HTTPStore
- func (s *HTTPStore) Blobs(ctx context.Context, shas []gitpack.SHA) ([][]byte, error)
- func (s *HTTPStore) Calls() int64
- func (s *HTTPStore) Commit(ctx context.Context, sha gitpack.SHA) (gitpack.SHA, time.Time, error)
- func (s *HTTPStore) DeleteRef(ctx context.Context, name string, expect int64) error
- func (s *HTTPStore) GetOp(ctx context.Context, kind, id string) ([]byte, error)
- func (s *HTTPStore) Has(ctx context.Context, shas []gitpack.SHA) ([]bool, error)
- func (s *HTTPStore) ImportPack(ctx context.Context, idx, pack []byte) error
- func (s *HTTPStore) Layer(ctx context.Context, key string) (layerrow.Row, error)
- func (s *HTTPStore) LayersByBase(ctx context.Context, base string) ([]layerrow.Row, error)
- func (s *HTTPStore) Object(ctx context.Context, sha gitpack.SHA) (gitpack.Type, []byte, error)
- func (s *HTTPStore) OpHeads(ctx context.Context) (api.OpHeads, error)
- func (s *HTTPStore) OpenBlob(ctx context.Context, sha gitpack.SHA) (int64, io.ReadCloser, error)
- func (s *HTTPStore) PutBlob(ctx context.Context, sha gitpack.SHA, size int64, r io.Reader) error
- func (s *HTTPStore) PutLayer(ctx context.Context, key, base, tree string, files, bytes int64) (layerrow.Row, error)
- func (s *HTTPStore) PutObjects(ctx context.Context, objs []gitpack.Object) error
- func (s *HTTPStore) PutOp(ctx context.Context, kind, id string, data []byte) error
- func (s *HTTPStore) PutWorkspace(ctx context.Context, op, commit string, generation int64) error
- func (s *HTTPStore) Ref(ctx context.Context, name string) (api.Ref, error)
- func (s *HTTPStore) Refs(ctx context.Context) ([]api.Ref, error)
- func (s *HTTPStore) StreamBlobs(ctx context.Context, shas []gitpack.SHA, ...) error
- func (s *HTTPStore) SwapOpHeads(ctx context.Context, expect int64, heads []string) (api.OpHeads, error)
- func (s *HTTPStore) SwapRef(ctx context.Context, name string, expect int64, commit string) (api.Ref, error)
- func (s *HTTPStore) TreeBulk(ctx context.Context, sha gitpack.SHA, maxEntries int) ([]*Tree, error)
- type HasStore
- type MaintainOptions
- type OpHeadsStore
- type OpObjectStore
- type RefStore
- type SegHandle
- type Store
- type Tree
- type TreeCache
- type TreePrefetch
- type WorkspaceStore
Constants ¶
const ( DefaultPrefetchTreeEntries = DefaultTreeEntries / 4 DefaultPrefetchBlobBytes int64 = 1 << 30 PrefetchBlobMax = 64 << 10 PrefetchRuns = 2 TreePrefetchRuns = 1 PrefetchWorkers = 4 )
const ( // SegmentBytes is the size after which a segment is sealed. SegmentBytes = 64 << 20 // SegmentBlobMax is the largest blob that a segment holds. SegmentBlobMax = 256 << 10 )
const DefaultTreeEntries = 2 << 20
DefaultTreeEntries is the entries that a tree cache holds: about 200 MiB.
const OpHeadsBudget = 2 * time.Second
OpHeadsBudget bounds one store call, because the shim waits on it while jj holds its op-heads lock.
Variables ¶
var ErrGrantRefused = errors.New(volattr.GrantRefused)
ErrGrantRefused is the store answer 403 to a grant: the store holds no read of the repo for the grant, and no retry of the call passes.
var ErrNoBlobStream = errors.New("vfs: the store has no blob stream")
ErrNoBlobStream is the answer of a store that has no blob stream route, as an older service.
var ErrPackTooLarge = errors.New("vfs: the store refuses the pack as too large")
ErrPackTooLarge is the store refusing a pack for its size, or for the work that verifying it takes.
SharedTrees is the tree cache of a daemon. A tree and a commit are named by their hash, so every workspace of the node, whatever its repository, can use the same decoded tree.
Functions ¶
func CopyBlob ¶ added in v0.29.0
CopyBlob streams the blob s of size bytes, or of the size that the store gives when size is negative, from st to w through the buffers of one copy and the hash that checks it, and holds nothing of the blob in memory. It fails unless the stream has the size and the hash of the name, and w has then received bytes that the caller must discard on an error.
func EvictTo ¶ added in v0.40.0
EvictTo removes the least recently used sealed segments of the process until Tier2Bytes is at most max, and then the oldest files of blobs. A segment or a file that an open blob uses stays readable until the blob is closed, because the open file keeps it.
func HoldNodeCache ¶ added in v0.40.0
HoldNodeCache makes the process the owner of the node cache directory dir for as long as it runs, and fails when another process owns it. The caches of the process on dir share the hold.
func Maintain ¶ added in v0.40.0
func Maintain(ctx context.Context, o MaintainOptions)
func RemoveStrayTemps ¶ added in v0.22.0
func RemoveStrayTemps(dir string)
RemoveStrayTemps removes the temporary files in dir that are older than this process: a dead writer left them.
func SeedCacheSize ¶ added in v0.22.0
func SeedCacheSize(dir string)
SeedCacheSize adds the size of the files that an earlier process left in dir to Tier2Bytes. A file that this process wrote is already in the figure.
func SeedTier2Bytes ¶
func SeedTier2Bytes(n int64)
SeedTier2Bytes adds the size of the cache directory at startup to Tier2Bytes.
func Tier2Bytes ¶
func Tier2Bytes() int64
Tier2Bytes is the number of blob bytes that this process wrote to the node cache, plus the size of the cache that SeedTier2Bytes found at startup.
func Tier2Evictions ¶ added in v0.40.0
func Tier2Evictions() int64
Tier2Evictions is the number of segments and files that this process evicted from the node cache.
Types ¶
type BlobFile ¶ added in v0.40.0
BlobFile is an open blob of the node cache: N bytes at Off of F. The caller reads F and calls Close when it is done, and never closes F itself.
type BlobPrefetch ¶ added in v0.42.0
type BlobPutter ¶ added in v0.30.0
type BlobPutter interface {
PutBlob(ctx context.Context, sha gitpack.SHA, size int64, r io.Reader) error
}
BlobPutter is an optional method of Store: it stores a blob over gitpack.MaxObjectBytes from a stream.
type BlobStreamBatcher ¶ added in v0.40.0
type BlobStreamBatcher interface {
StreamBlobs(ctx context.Context, shas []gitpack.SHA, fn func(sha gitpack.SHA, data []byte) error) error
}
BlobStreamBatcher is an optional method of Store: it reads the blobs of a batch as a stream and calls fn with each blob as it arrives, which holds one blob and sends no base64. A store that has no stream answers ErrNoBlobStream.
type BlobStreamer ¶ added in v0.29.0
type BlobStreamer interface {
OpenBlob(ctx context.Context, sha gitpack.SHA) (int64, io.ReadCloser, error)
}
BlobStreamer is an optional method of Store: it reads a blob of any size as a stream, which the cache needs for a blob over gitpack.MaxObjectBytes, as Blobs refuses one.
type Cache ¶
type Cache struct {
Store Store
Dir string
BulkEntries int
PrefetchN int
PrefetchB int64
// WriteWorkers is the number of files that a batch writes at the same time.
WriteWorkers int
// Pipeline is the number of batches that a miss reads in the background after its own, in the order of the read-ahead.
Pipeline int
// Trees holds the decoded trees. A cache has its own, and the caches of one daemon share SharedTrees.
Trees *TreeCache
BlobHits, BlobMisses, TreeMisses, TreeHits atomic.Int64
// Tel carries the correlation attributes of the spans of this cache.
Tel tel.Telemetry
// contains filtered or unexported fields
}
Cache is tier 1 (decoded trees in memory) and tier 2 (blobs on node-local disk).
func (*Cache) Adopt ¶ added in v0.30.0
Adopt moves the spool file tmp, which holds the blob s, to its place in the node cache.
func (*Cache) Blob ¶
func (c *Cache) Blob(ctx context.Context, e Entry, next func(yield func(Entry) bool)) (string, error)
Blob returns the path of the blob of e in the node cache, fetching it (plus read-ahead) if absent or if its file does not have the size of its tree entry. next yields read-ahead candidates after e; it may be nil.
func (*Cache) BlobPath ¶
BlobPath is the path of the blob in the node cache, whether or not it exists.
func (*Cache) CachedTree ¶
CachedTree returns a tree only when it is already in memory.
func (*Cache) Close ¶ added in v0.40.0
Close gives up the segments of the cache. The last cache of the process on a directory seals its segment and closes the files when their last open blob is closed.
func (*Cache) File ¶ added in v0.30.0
File returns the file of the blob s in the node cache, fetching it first when the cache lacks it, by a stream when the store has one. A caller that needs the bytes of a blob by name, and has no tree entry, uses it.
func (*Cache) Open ¶ added in v0.40.0
func (c *Cache) Open(ctx context.Context, e Entry, next func(yield func(Entry) bool)) (BlobFile, error)
Open is Blob that returns the open blob. A blob that a segment holds is served from the segment file, and every other blob from its own file.
func (*Cache) OpenHeld ¶ added in v0.40.0
OpenHeld opens the blob that the cache holds, and reports false for a blob that it lacks. It fetches nothing.
func (*Cache) PrefetchBlobs ¶ added in v0.42.0
func (*Cache) PrefetchTrees ¶ added in v0.42.0
func (*Cache) ReadBlob ¶
ReadBlob returns blob bytes from the node cache. It is the one reader that holds a blob in memory whole, so it refuses an entry over gitpack.MaxObjectBytes before it asks the cache, which another workspace may have filled with such a blob by its name.
func (*Cache) Spool ¶ added in v0.30.0
Spool creates the locked temporary file of an upload that the caller then streams into and hands to Adopt.
func (*Cache) UseSegments ¶ added in v0.40.0
UseSegments makes the cache keep the blobs of at most SegmentBlobMax bytes in append-only segment files in the directory seg of the cache, and not one file each. A caller that wants a file for such a blob gets one that the cache makes from the segment.
type HTTPStore ¶
type HTTPStore struct {
BaseURL string
// Grant returns the bearer grant of each call. A caller whose mount outlives one grant returns a fresh one.
// A grant that fails fails the call.
Grant client.GrantFunc
Client *http.Client
// Tel carries the correlation attributes and the logger of the spans and records the client writes.
Tel tel.Telemetry
// contains filtered or unexported fields
}
HTTPStore reads and writes the version control store through client.Client and adds the spans of the daemon.
func (*HTTPStore) ImportPack ¶
ImportPack uploads one pack and its v2 index. The pack ID is the SHA-256 of the pack.
func (*HTTPStore) LayersByBase ¶ added in v0.44.0
LayersByBase returns the rows with the base key, most recently used first.
func (*HTTPStore) OpHeads ¶
OpHeads reads the op heads. A workspace that has none yet is generation 0 and no heads.
func (*HTTPStore) OpenBlob ¶ added in v0.29.0
OpenBlob returns the size and a reader of the blob sha, of any size. The span ends when the body starts.
func (*HTTPStore) PutBlob ¶ added in v0.29.0
PutBlob stores one blob over the in-memory limit of the store, of size bytes that it streams from r.
func (*HTTPStore) PutObjects ¶
PutObjects uploads objs in requests of at most maxPutBytes and maxPutObjects. One snapshot is one request unless it is larger.
func (*HTTPStore) PutWorkspace ¶
func (*HTTPStore) StreamBlobs ¶ added in v0.40.0
func (s *HTTPStore) StreamBlobs(ctx context.Context, shas []gitpack.SHA, fn func(sha gitpack.SHA, data []byte) error) error
StreamBlobs reads the blobs of shas through the blob stream and calls fn with each blob as it arrives. A store that does not have the route answers ErrNoBlobStream: an older service answers 405 to a POST on this path, which its route of a blob matches with other methods, and an unknown path 404 with the text of the status, while every other not found has its own text.
func (*HTTPStore) SwapOpHeads ¶
type MaintainOptions ¶ added in v0.40.0
type MaintainOptions struct {
Every time.Duration
MaxBytes int64
// Dir is the node cache directory that eviction measures.
Dir string
// EvictAfter, when set, holds the eviction back until it is closed: the size of the cache is known only after the
// scan of the start.
EvictAfter <-chan struct{}
}
MaintainOptions: a MaxBytes of 0 evicts nothing.
type OpHeadsStore ¶
type OpHeadsStore interface {
OpHeads(ctx context.Context) (api.OpHeads, error)
SwapOpHeads(ctx context.Context, expect int64, heads []string) (api.OpHeads, error)
}
OpHeadsStore reads and swaps the op heads of the workspace that the grant names.
type OpObjectStore ¶
type OpObjectStore interface {
PutOp(ctx context.Context, kind, id string, data []byte) error
GetOp(ctx context.Context, kind, id string) ([]byte, error)
}
OpObjectStore keeps the operations and views of the op log of the workspace that the grant names.
type RefStore ¶
type RefStore interface {
Refs(ctx context.Context) ([]api.Ref, error)
Ref(ctx context.Context, name string) (api.Ref, error)
SwapRef(ctx context.Context, name string, expect int64, commit string) (api.Ref, error)
DeleteRef(ctx context.Context, name string, expect int64) error
}
RefStore reads and swaps the refs of the native repo that the grant names. A lost swap is client.ErrGenerationConflict, and client.CurrentRef returns the stored ref.
type SegHandle ¶ added in v0.40.0
SegHandle is an open blob of a segment: the bytes at Off, N long, of F. The file belongs to the store, so a caller reads it and never closes it, and calls Close when it is done.
type Store ¶
type Store interface {
Commit(ctx context.Context, sha gitpack.SHA) (tree gitpack.SHA, when time.Time, err error)
// TreeBulk returns the tree and its subtrees breadth first until maxEntries entries, with blob sizes.
TreeBulk(ctx context.Context, sha gitpack.SHA, maxEntries int) ([]*Tree, error)
Blobs(ctx context.Context, shas []gitpack.SHA) ([][]byte, error)
PutObjects(ctx context.Context, objs []gitpack.Object) error
Object(ctx context.Context, sha gitpack.SHA) (gitpack.Type, []byte, error)
}
Store is what the daemon needs from the version control store. One method is one remote call.
type TreeCache ¶ added in v0.40.0
type TreeCache struct {
// contains filtered or unexported fields
}
TreeCache holds decoded trees and the tree of each commit that was asked for, in two generations of at most max/2 entries each, except one tree that is larger: a tree that nothing used since the last rotation goes when the next rotation comes.