Documentation
¶
Overview ¶
Package session is the upload session shared by the object-store blob backends (s3, gcs, azure; decision 0027). Object stores cannot append, so each backend buffers appended bytes into parts and uploads a part whenever one is full; between HTTP requests the session must survive in the metadata store so a Docker chunked upload or a CLI multipart upload resumes in a later request or another process.
A Session holds what every backend needs: the size, the declared digest, the saved blob.Hasher state and the pending tail shorter than one part, plus a backend-specific document D (S3's multipart upload ID and part list, GCS's part objects, Azure's block count). It is persisted through a Store after every append. InUploads keeps sessions in the uploads table under a per-store backend name such as "s3:hot", so two stores of one kind never share or misattribute sessions.
Index ¶
- type FlushFunc
- type Memory
- type Session
- func (s *Session[D]) Append(ctx context.Context, r io.Reader, partSize int64, flush FlushFunc) (int64, error)
- func (s *Session[D]) Flush(ctx context.Context, flush FlushFunc) error
- func (s *Session[D]) Forget(ctx context.Context) error
- func (s *Session[D]) Live(ctx context.Context) error
- func (s *Session[D]) Save(ctx context.Context) error
- func (s *Session[D]) Verify(want blob.Digests) (blob.Digests, error)
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FlushFunc ¶
FlushFunc hands one part to the backend. On success the session drops the part from Pending; on error the bytes stay pending (and hashed), so the next Append or Commit retries the same part.
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory is a Store in process memory. Sessions do not survive a restart; it serves tests and embedders without a metadata store.
type Session ¶
type Session[D any] struct { // ID names the session for Resume. ID string // Size counts every appended byte, uploaded or pending. Size int64 // Expected is the SHA-256 declared at BeginUpload, or "". Expected string // Pending is the tail not yet handed to the backend. Pending []byte // Data is the backend's state. Data D // contains filtered or unexported fields }
Session is one upload session. D is the backend's own state; it is stored as JSON, so its fields carry json tags and are the storage format.
func Resume ¶
Resume loads a saved session. Unknown or malformed IDs, and sessions whose state cannot be restored, return an error wrapping blob.ErrUploadUnknown: there is no local copy of the uploaded parts to rehash, so a damaged session ends.
func (*Session[D]) Append ¶
func (s *Session[D]) Append( ctx context.Context, r io.Reader, partSize int64, flush FlushFunc, ) (int64, error)
Append reads r into Pending, calling flush whenever partSize bytes are buffered, and saves the session. Bytes read are hashed and counted even when flush or the read fails, so the session stays consistent and the client may continue from Size.
func (*Session[D]) Flush ¶
Flush hands the pending bytes to flush when there are any and drops them on success.
func (*Session[D]) Live ¶
Live reports, with an error wrapping blob.ErrUploadUnknown, a session that was committed or aborted since this handle was resumed.
type Store ¶
type Store interface {
Put(ctx context.Context, id string, state []byte, size int64) error
Get(ctx context.Context, id string) ([]byte, error)
Delete(ctx context.Context, id string) error
}
Store keeps encoded sessions between requests. Get returns an error wrapping blob.ErrUploadUnknown for an unknown ID; Delete of a missing session succeeds.
func InUploads ¶
func InUploads(us store.UploadStore, backend string) Store
InUploads keeps sessions in the metadata store's uploads table (decision 0004) under backend, which names the blob store instance, for example "s3:hot" or "gcs:archive". A session stored under another backend name is unknown here, so the stale-upload reaper always knows which store aborts a session.