Skip to content

Commit

Permalink
manifest & model etag
Browse files Browse the repository at this point in the history
  • Loading branch information
gertd committed Nov 17, 2023
1 parent fedbb66 commit f06d5b0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/bdb/migrate/mig003/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions pkg/ds/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit f06d5b0

Please sign in to comment.