572ce80230
This commit adds a transfer manager which deduplicates and schedules transfers, and also an upload manager and download manager that build on top of the transfer manager to provide high-level interfaces for uploads and downloads. The push and pull code is modified to use these building blocks. Some benefits of the changes: - Simplification of push/pull code - Pushes can upload layers concurrently - Failed downloads and uploads are retried after backoff delays - Cancellation is supported, but individual transfers will only be cancelled if all pushes or pulls using them are cancelled. - The distribution code is decoupled from Docker Engine packages and API conventions (i.e. streamformatter), which will make it easier to split out. This commit also includes unit tests for the new distribution/xfer package. The tests cover 87.8% of the statements in the package. Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
44 lines
1 KiB
Go
44 lines
1 KiB
Go
package metadata
|
|
|
|
import (
|
|
"github.com/docker/docker/image/v1"
|
|
"github.com/docker/docker/layer"
|
|
)
|
|
|
|
// V1IDService maps v1 IDs to layers on disk.
|
|
type V1IDService struct {
|
|
store Store
|
|
}
|
|
|
|
// NewV1IDService creates a new V1 ID mapping service.
|
|
func NewV1IDService(store Store) *V1IDService {
|
|
return &V1IDService{
|
|
store: store,
|
|
}
|
|
}
|
|
|
|
// namespace returns the namespace used by this service.
|
|
func (idserv *V1IDService) namespace() string {
|
|
return "v1id"
|
|
}
|
|
|
|
// Get finds a layer by its V1 ID.
|
|
func (idserv *V1IDService) Get(v1ID, registry string) (layer.DiffID, error) {
|
|
if err := v1.ValidateID(v1ID); err != nil {
|
|
return layer.DiffID(""), err
|
|
}
|
|
|
|
idBytes, err := idserv.store.Get(idserv.namespace(), registry+","+v1ID)
|
|
if err != nil {
|
|
return layer.DiffID(""), err
|
|
}
|
|
return layer.DiffID(idBytes), nil
|
|
}
|
|
|
|
// Set associates an image with a V1 ID.
|
|
func (idserv *V1IDService) Set(v1ID, registry string, id layer.DiffID) error {
|
|
if err := v1.ValidateID(v1ID); err != nil {
|
|
return err
|
|
}
|
|
return idserv.store.Set(idserv.namespace(), registry+","+v1ID, []byte(id))
|
|
}
|