-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add --blob-meta and --blob-cache arg use to generate raw blob cache a…
…nd meta generate blob cache and blob meta through the —blob-met and —blob-cache parameters, so that nydusd can be started directly from these two files without going to the backend to download. this can improve the performance of data loading in localfs mode. Signed-off-by: zyfjeff <[email protected]>
- Loading branch information
Showing
10 changed files
with
258 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package tests | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"io/fs" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/containerd/containerd/log" | ||
"github.com/dragonflyoss/image-service/smoke/tests/texture" | ||
"github.com/dragonflyoss/image-service/smoke/tests/tool" | ||
"github.com/dragonflyoss/image-service/smoke/tests/tool/test" | ||
"github.com/opencontainers/go-digest" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type BlobCacheTestSuite struct { | ||
T *testing.T | ||
} | ||
|
||
func (a *BlobCacheTestSuite) compare_two_files(t *testing.T, left, right string) { | ||
|
||
leftHash := digest.Digest("") | ||
lf, err := os.Open(left) | ||
require.NoError(t, err) | ||
defer lf.Close() | ||
digester := digest.Canonical.Digester() | ||
_, err = io.Copy(digester.Hash(), lf) | ||
require.NoError(t, err) | ||
leftHash = digester.Digest() | ||
|
||
rightHash := digest.Digest("") | ||
rf, err := os.Open(right) | ||
require.NoError(t, err) | ||
defer rf.Close() | ||
digester = digest.Canonical.Digester() | ||
_, err = io.Copy(digester.Hash(), rf) | ||
require.NoError(t, err) | ||
rightHash = digester.Digest() | ||
require.Equal(t, leftHash, rightHash) | ||
} | ||
|
||
func (a *BlobCacheTestSuite) TestGenerateBlobcache(t *testing.T) { | ||
|
||
ctx := tool.DefaultContext(t) | ||
|
||
ctx.PrepareWorkDir(t) | ||
defer ctx.Destroy(t) | ||
|
||
rootFs := texture.MakeLowerLayer(t, filepath.Join(ctx.Env.WorkDir, "root-fs")) | ||
|
||
rootfsReader := rootFs.ToOCITar(t); | ||
|
||
ociBlobDigester := digest.Canonical.Digester() | ||
ociBlob, err := ioutil.TempFile(ctx.Env.BlobDir, "oci-blob-") | ||
require.NoError(t, err) | ||
|
||
_, err = io.Copy(io.MultiWriter(ociBlobDigester.Hash(), ociBlob), rootfsReader) | ||
require.NoError(t, err) | ||
|
||
ociBlobDigest := ociBlobDigester.Digest() | ||
err = os.Rename(ociBlob.Name(), filepath.Join(ctx.Env.BlobDir, ociBlobDigest.Hex())) | ||
require.NoError(t, err) | ||
|
||
// use to generate blob.data and blob.meta | ||
blobcacheDir := filepath.Join(ctx.Env.WorkDir, "blobcache") | ||
err = os.MkdirAll(blobcacheDir, 0755) | ||
require.NoError(t, err) | ||
|
||
ctx.Env.BootstrapPath = filepath.Join(ctx.Env.WorkDir, "bootstrap") | ||
|
||
|
||
tool.Run(t, fmt.Sprintf("%s create -t targz-ref --bootstrap %s --blob-dir %s --blob-cache %s --blob-meta %s %s", | ||
ctx.Binary.Builder, ctx.Env.BootstrapPath, ctx.Env.BlobDir, | ||
filepath.Join(blobcacheDir, "blob.data"), filepath.Join(blobcacheDir, "blob.meta"), | ||
filepath.Join(ctx.Env.BlobDir, ociBlobDigest.Hex()))); | ||
|
||
nydusd, err := tool.NewNydusd(tool.NydusdConfig{ | ||
NydusdPath: ctx.Binary.Nydusd, | ||
BootstrapPath: ctx.Env.BootstrapPath, | ||
ConfigPath: filepath.Join(ctx.Env.WorkDir, "nydusd-config.fusedev.json"), | ||
MountPath: ctx.Env.MountDir, | ||
APISockPath: filepath.Join(ctx.Env.WorkDir, "nydusd-api.sock"), | ||
BackendType: "localfs", | ||
BackendConfig: fmt.Sprintf(`{"dir": "%s"}`, ctx.Env.BlobDir), | ||
EnablePrefetch: ctx.Runtime.EnablePrefetch, | ||
BlobCacheDir: ctx.Env.CacheDir, | ||
CacheType: ctx.Runtime.CacheType, | ||
CacheCompressed: ctx.Runtime.CacheCompressed, | ||
RafsMode: ctx.Runtime.RafsMode, | ||
DigestValidate: false, | ||
}) | ||
require.NoError(t, err) | ||
|
||
err = nydusd.Mount() | ||
require.NoError(t, err) | ||
defer func() { | ||
if err := nydusd.Umount(); err != nil { | ||
log.L.WithError(err).Errorf("umount") | ||
} | ||
}() | ||
|
||
// make sure blobcache ready | ||
err = filepath.WalkDir(ctx.Env.MountDir, func(path string, entry fs.DirEntry, err error) error { | ||
require.Nil(t, err) | ||
if entry.Type().IsRegular() { | ||
targetPath, err := filepath.Rel(ctx.Env.MountDir, path) | ||
require.NoError(t, err) | ||
_, _ = os.ReadFile(targetPath) | ||
} | ||
return nil | ||
}) | ||
require.NoError(t, err) | ||
|
||
a.compare_two_files(t, filepath.Join(blobcacheDir, "blob.data"), filepath.Join(ctx.Env.CacheDir, fmt.Sprintf("%s.blob.data", ociBlobDigest.Hex()))) | ||
a.compare_two_files(t, filepath.Join(blobcacheDir, "blob.meta"), filepath.Join(ctx.Env.CacheDir, fmt.Sprintf("%s.blob.meta", ociBlobDigest.Hex()))) | ||
} | ||
|
||
|
||
func TestBlobCache(t *testing.T) { | ||
test.Run(t, &BlobCacheTestSuite{T: t}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.