From f06d5b02a273cf3b3bd0fa279471b49e02d132f4 Mon Sep 17 00:00:00 2001 From: Gert Drapers Date: Thu, 16 Nov 2023 21:05:30 -0800 Subject: [PATCH] manifest & model etag --- pkg/bdb/migrate/mig003/migrate.go | 7 +++++++ pkg/ds/manifest.go | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/pkg/bdb/migrate/mig003/migrate.go b/pkg/bdb/migrate/mig003/migrate.go index 20a15a6..ffa7257 100644 --- a/pkg/bdb/migrate/mig003/migrate.go +++ b/pkg/bdb/migrate/mig003/migrate.go @@ -3,8 +3,10 @@ package mig003 import ( "bytes" "context" + "hash/fnv" "os" "path/filepath" + "strconv" "github.com/aserto-dev/azm/migrate" v3 "github.com/aserto-dev/azm/v3" @@ -91,8 +93,13 @@ func createModel() func(*zerolog.Logger, *bolt.DB, *bolt.DB) error { return err } + h := fnv.New64a() + h.Reset() + _, _ = h.Write(manifestBuf.Bytes()) + md := &dsm3.Metadata{ UpdatedAt: timestamppb.Now(), + Etag: strconv.FormatUint(h.Sum64(), 10), } if err := rwDB.Update(func(tx *bolt.Tx) error { if err := ds.Manifest(md).Set(ctx, tx, manifestBuf); err != nil { diff --git a/pkg/ds/manifest.go b/pkg/ds/manifest.go index d219084..9389f36 100644 --- a/pkg/ds/manifest.go +++ b/pkg/ds/manifest.go @@ -84,6 +84,12 @@ func (m *manifest) Set(ctx context.Context, tx *bolt.Tx, buf *bytes.Buffer) erro // SetModel, persists the model cache in the _manifest bucket // _metadata/{name}/{version}/model. func (m *manifest) SetModel(ctx context.Context, tx *bolt.Tx, mod *model.Model) error { + if mod.Metadata == nil { + mod.Metadata = &model.Metadata{} + } + mod.Metadata.ETag = m.Metadata.Etag + mod.Metadata.UpdatedAt = m.Metadata.UpdatedAt.AsTime() + if _, err := bdb.SetAny[model.Model](ctx, tx, bdb.ManifestPath, bdb.ModelKey, mod); err != nil { return err }