mirror of
https://github.com/containerd/containerd.git
synced 2026-11-06 05:17:02 +00:00
Add a layer_content_cache option to the erofs snapshotter: a directory of pre-converted, diffID-keyed erofs layer blobs (in production a read-only mountpoint-s3/FUSE mount) that the snapshotter sources layers from on pull instead of downloading and converting them per node. On an image-layer extraction Prepare, if the layer's blob is present in the cache the snapshotter stages it as a symlink, commits it as the target chainID in the same transaction, and returns ErrAlreadyExists. This uses the existing remote-snapshot protocol, so containerd skips both the layer download and the tar->erofs conversion; no core changes are needed. Any miss (cache disabled, no snapshot.ref/diff-id labels, blob absent, unreadable cache) falls through to the normal path, so pulls keep working. Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
38 lines
1.1 KiB
Go
38 lines
1.1 KiB
Go
/*
|
|
Copyright The containerd Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package erofsutils
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/opencontainers/go-digest"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestCacheBlobPath(t *testing.T) {
|
|
diffID := digest.FromString("hello")
|
|
enc := diffID.Encoded()
|
|
|
|
got := CacheBlobPath("/cache", diffID)
|
|
|
|
// <dir>/<algo>/<xx>/<hex>.erofs, where <xx> is the first two hex characters.
|
|
want := filepath.Join("/cache", "sha256", enc[:2], enc+".erofs")
|
|
assert.Equal(t, want, got)
|
|
assert.Equal(t, enc[:2], filepath.Base(filepath.Dir(got)), "blob must live under a 2-char prefix dir")
|
|
}
|