Skip to content

Commit

Permalink
validate snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
naoki9911 committed Mar 21, 2024
1 parent cddd49f commit 3fee60d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/ctr-cli/load/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func LoadImage(snClient *sns.Client, ctx context.Context, imageName, imageVersio
}

// now ready to create snapshot
err = sns.CreateSnapshot(ctx, snClient.SnClient, &image.Header.ManifestDigest, &image.DImgDigest)
err = sns.CreateSnapshot(ctx, snClient.SnClient, &image.Header.ManifestDigest, &image.DImgDigest, imageName+":"+imageVersion)
if err != nil {
return err
}
Expand Down
16 changes: 13 additions & 3 deletions pkg/snapshotter/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ const SnapshotLabelRefImagePath = "containerd.io/snapshot/di3fs.ref.imagepath"
const SnapshotLabelRefLayer = "containerd.io/snapshot/di3fs.ref.layer"
const SnapshotLabelImageName = "containerd.io/snapshot/di3fs.image.name"
const SnapshotLabelImageVersion = "containerd.io/snapshot/di3fs.image.version"
const SnapshotLabelMount = "containerd.io/snapshot/di3fs.mount"
const NerverGC = "containerd.io/gc.root"
const TargetSnapshotLabel = "containerd.io/snapshot.ref"

func CreateSnapshot(ctx context.Context, ss snapshots.Snapshotter, manifestDigest, dimgDigest *digest.Digest) error {
func CreateSnapshot(ctx context.Context, ss snapshots.Snapshotter, manifestDigest, dimgDigest *digest.Digest, imageName string) error {
opts := snapshots.WithLabels(map[string]string{
NerverGC: "hogehoge",
SnapshotLabelRefImage: manifestDigest.String(),
SnapshotLabelRefLayer: fmt.Sprintf("%d", 0),
SnapshotLabelRefUncompressed: dimgDigest.String(),
SnapshotLabelImageName: imageName,
//targetSnapshotLabel: chain.Hex(),
//remoteLabel: "true",
})
Expand All @@ -37,12 +39,20 @@ func CreateSnapshot(ctx context.Context, ss snapshots.Snapshotter, manifestDiges
// TODO: handle this correctly
_ = ss.Remove(ctx, dimgDigest.String())

_, err := ss.Prepare(ctx, randId, "", opts)
mounts, err := ss.Prepare(ctx, randId, "", opts)
if err != nil {
log.G(ctx).WithField("opts", opts).Error("failed to prepare")
return err
}
err = ss.Commit(ctx, dimgDigest.String(), randId, opts)
log.G(ctx).Infof("mounts=%v", mounts)
mountPath := ""
if len(mounts) > 0 {
mountPath = mounts[0].Source
}
optsWithMount := snapshots.WithLabels(map[string]string{
SnapshotLabelMount: mountPath,
})
err = ss.Commit(ctx, dimgDigest.String(), randId, opts, optsWithMount)
if err != nil {
log.G(ctx).Errorf("failed to commit snapshot :%w", err)
return err
Expand Down
18 changes: 18 additions & 0 deletions tests/bench_pull_impl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ IMAGE_PATH=$(pwd)

systemd-run --unit=d4c-server $BIN_SERVER
systemd-run --unit=d4c-snapshotter $BIN_SNAPSHOTTER
sleep 1
systemctl status d4c-snapshotter

curl -XDELETE http://$SERVER_HOST/diffData/cleanup

Expand Down Expand Up @@ -173,5 +175,21 @@ for ((j=0; j < $RUN_NUM; j++));do
done
ctr image rm $IMAGE_NAME-file:$IMAGE_LOWER

sleep 1
ctr snapshot --snapshotter=di3fs tree | while read SNP; do
SNP_IMAGE_TAG=$(ctr snapshot --snapshotter=di3fs info $SNP | jq -r '.Labels."containerd.io/snapshot/di3fs.image.name"')
MOUNT_PATH=$(ctr snapshot --snapshotter=di3fs info $SNP | jq -r '.Labels."containerd.io/snapshot/di3fs.mount"')
IMAGE_TAG=(${SNP_IMAGE_TAG//:/ })
SNP_IMAGE_NAME=${IMAGE_TAG[0]}
SNP_IMAGE_NAME=(${SNP_IMAGE_NAME//-/ })
SNP_IMAGE_NAME=${SNP_IMAGE_NAME[0]}
SNP_IMAGE_VERSION=${IMAGE_TAG[1]}

if [ "$SNP_IMAGE_NAME" == "$IMAGE_NAME" ]; then
echo "Checking $SNP_IMAGE_TAG at $MOUNT_PATH"
sudo diff -r $SNP_IMAGE_VERSION $MOUNT_PATH --no-dereference
fi
done

systemctl stop d4c-server
systemctl stop d4c-snapshotter

0 comments on commit 3fee60d

Please sign in to comment.