-
Notifications
You must be signed in to change notification settings - Fork 205
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
254 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,126 @@ | ||
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) { | ||
|
||
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-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) { | ||
os.Setenv("NYDUS_BUILDER_latest", "/root/code/image-service/target/release/nydus-image") | ||
os.Setenv("NYDUS_NYDUSD_latest", "/root/code/image-service/target/release/nydusd") | ||
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.