Documentation
¶
Overview ¶
Package multipart serves the JFrog CLI's multipart upload protocol, as the pinned jfrog-client-go drives it (artifactory/services/utils/ multipartupload.go): create a session, get a URL per part, PUT the parts concurrently, complete with the file's SHA-1, poll the status, and abort on failure.
Role ¶
artifacts module, core layer: the multipart upload sessions. Once the status is FINISHED the CLI checksum-deploys the file, so a session only has to store the content and index it; the item, its properties and the package index come from that ordinary checksum deploy. Artifactory hands out presigned S3 URLs and the object store assembles the parts. artifactweave serves the part URLs itself and keeps one blob.Store upload session per multipart upload (decision 0004), so every backend, mirror included, takes multipart uploads. It checks API restrictions through access/api's Restrictions, the only way it reaches the access module (decision 0044, dependency rule 6), and as artifacts core it never imports the module's adapters or an ecosystem http package (dependency rule 8).
Inputs ¶
- Driving: the multipart upload routes under /artifactory/api/v1/uploads (create, urlPart, part, complete, status and abort); the checksum deploy, which asks Finished whether a checksum token lets it through; the garbage collector, which hands stale sessions under Backend to Reap; and the composition root, which runs Sweep at startup.
- Driven: the metadata store, through Store (the uploads table, and the blob index a completion records the content in), the blob store (platform/blob.Store) whose upload the parts are appended to, the staging directory Dir on local disk, and accessapi.Restrictions.
Outputs ¶
- Upload tokens, signed part URLs, the state a status poll reads (Status, with the Status* values the CLI understands) and, once finished, the checksum token the deploy presents.
- Errors: ErrBadToken, ErrInvalid, ErrState and ErrCorrupt, which the HTTP layer maps onto statuses.
Invariants ¶
- Backend ("jfrog-multipart") names the sessions' rows in the uploads table, so it is stored and never changes.
- Parts are staged on local disk as they arrive, in any order, and appended to the blob upload in order. Only the parts that arrive ahead of a missing one wait on disk, a few times the part size with the CLI's concurrency.
- The CLI sends parts without credentials, so a part URL carries a signature for that upload and part only, and a session's user is checked against API restrictions on every request that opens the session by its token and on every part (decision 0043).
- Error texts reach the CLI, ErrInvalid's and ErrState's in a response body and a failed completion's in Status, so they stay byte-identical.
References ¶
- Research 09: docs/research/09-jfrog-cli-compatibility.md, "Multipart upload" (the protocol at the commit the pinned jf uses).
- Decision 0004: docs/research/decisions/0004-storage-sql-metadata-and-blobs.md (blob store upload sessions).
- Decision 0043: docs/research/decisions/0043-api-reliability.md (temporary restrictions).
- Decision 0044: docs/research/decisions/0044-modular-monolith-migration.md, "Dependency rules".
- Target layout: docs/research/architecture-options/5-modular-monolith.md, line 205 (core/multipart), line 1030 (the mapping row) and rule 1 at lines 30 to 34.
- Plan: docs/implementation/plan.md#p3-repositories-generic-artifacts-cli-aql-shape (the JFrog CLI multipart protocol, #91) and #p9d-modular-monolith-migration, epic ART (https://github.com/weaveplatform/artifactweave/issues/941).
- https://github.com/weaveplatform/artifactweave/issues/1012 and https://github.com/weaveplatform/artifactweave/issues/1088
Status ¶
Implemented P3 to P9c. Moved here in P9d.
Testing ¶
- multipart_test.go: round trips with parts out of order, tokens and part signatures, API restrictions (from the access test kit, access/accesstest), the checksum token, invalid requests, completion, restarts, and abort, reap and sweep.
- fault_test.go: store, blob store and staging failures.
Index ¶
- Constants
- Variables
- type Service
- func (s *Service) Abort(ctx context.Context, token string) error
- func (s *Service) Complete(ctx context.Context, token, sha1 string) error
- func (s *Service) Create(ctx context.Context, repo, repoPath string, partSizeMB int64, by string) (string, error)
- func (s *Service) Finished(ctx context.Context, token, by, sum string) (bool, error)
- func (s *Service) PartURL(ctx context.Context, token string, part int) (string, error)
- func (s *Service) PutPart(ctx context.Context, id string, part int, sig string, body io.Reader) error
- func (s *Service) Reap(ctx context.Context, u blobsession.Upload) error
- func (s *Service) Status(ctx context.Context, token string) (Status, error)
- func (s *Service) Sweep(ctx context.Context) error
- type Status
- type Store
Constants ¶
const ( StatusParts = "PARTS" StatusProcessing = "PROCESSING" StatusFinished = "FINISHED" StatusRetryable = "RETRYABLE_ERROR" StatusFailed = "NON_RETRYABLE_ERROR" StatusAborted = "ABORTED" )
Statuses the CLI's status poll understands.
const Backend = "jfrog-multipart"
Backend names multipart sessions in the uploads table, so the garbage collector hands them to Reap rather than to the blob store.
const ( // MaxPartSize bounds partSizeMB: S3's largest part, which Artifactory // passes the size to. MaxPartSize = 5 << 30 )
Variables ¶
var ( // ErrBadToken reports a token or part signature that does not verify. ErrBadToken = errors.New("multipart: invalid upload token") // ErrInvalid reports a malformed request. ErrInvalid = errors.New("multipart: invalid request") // ErrState reports a request the session's state does not allow, such as // a part after completion started. ErrState = errors.New("multipart: upload is not accepting this request") // ErrCorrupt reports a blob upload holding bytes its session cannot // account for. ErrCorrupt = errors.New("multipart: the blob upload and its session disagree") )
Functions ¶
This section is empty.
Types ¶
type Service ¶
type Service struct {
Store Store
Blobs blob.Store
Dir string
// Restrictions is asked about the session's user, at Now, on every
// request that opens a session by its token and on every part: a
// session outlives the request that created it, and the CLI sends parts
// without credentials, so a user restricted mid-upload is refused here
// (decision 0043). It is required: a Service without it panics on those
// requests rather than skip the check.
Restrictions accessapi.Restrictions
// Now supplies the time; nil means time.Now.
Now func() time.Time
// contains filtered or unexported fields
}
Service runs multipart uploads over a metadata store and a blob store. Dir holds the staged parts, a directory per upload.
func (*Service) Abort ¶
Abort discards an upload: its staged parts, its blob upload and its session. Content already completed stays stored.
func (*Service) Complete ¶
Complete starts assembling the upload, checked against sha1, and returns at once: the CLI polls Status. Completing an upload that is already finished or being completed in this process changes nothing.
func (*Service) Create ¶
func (s *Service) Create( ctx context.Context, repo, repoPath string, partSizeMB int64, by string, ) (string, error)
Create starts an upload of repoPath in repo, whose caller by is already authorised to deploy there, and returns its token: "<id>.<secret>".
func (*Service) Finished ¶
Finished reports whether token is the checksum token of a finished upload that by made of the content with SHA-256 sum. That content is indexed with no item yet, so the checksum deploy that stores the item finds no file the caller may read; this lets it through instead, for that caller and that content only. A token that opens nothing is false rather than an error, so the deploy goes on to its other checks.
func (*Service) PartURL ¶
PartURL returns the path and query the CLI PUTs part to, relative to the server's base URL. The CLI sends that request without credentials, so the URL carries a signature for that upload and part only.
func (*Service) PutPart ¶
func (s *Service) PutPart( ctx context.Context, id string, part int, sig string, body io.Reader, ) error
PutPart stages part of upload id from body and appends every part that is now next in line to the blob upload.
func (*Service) Reap ¶
Reap discards a stale session for the garbage collector, which found it in the uploads table under Backend.
type Store ¶
type Store interface {
Uploads() blobsession.UploadStore
Blobs() port.BlobIndex
}
Store is what multipart uploads keep in the metadata store: the upload sessions, and the blob index that takes the assembled content's reference. Each composite store in app is a Store.