-
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-cache-dir arg use to generate raw blob cache and meta
generate blob cache and blob meta through the —-blob-cache-dir 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
7 changed files
with
248 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
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) compareTwoFiles(t *testing.T, left, right string) { | ||
|
||
lf, err := os.Open(left) | ||
require.NoError(t, err) | ||
defer lf.Close() | ||
leftDigester, err := digest.FromReader(lf) | ||
require.NoError(t, err) | ||
|
||
|
||
rf, err := os.Open(right) | ||
require.NoError(t, err) | ||
defer rf.Close() | ||
rightDigester, err := digest.FromReader(rf) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, leftDigester, rightDigester) | ||
} | ||
|
||
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-dir %s %s", | ||
ctx.Binary.Builder, ctx.Env.BootstrapPath, ctx.Env.BlobDir, blobcacheDir, | ||
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.compareTwoFiles(t, filepath.Join(blobcacheDir,fmt.Sprintf("%s.blob.data", ociBlobDigest.Hex())), filepath.Join(ctx.Env.CacheDir, fmt.Sprintf("%s.blob.data", ociBlobDigest.Hex()))) | ||
a.compareTwoFiles(t, filepath.Join(blobcacheDir, fmt.Sprintf("%s.blob.meta", ociBlobDigest.Hex())), 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.