Skip to content

Commit e4d2e9e

Browse files
committed
fix: dynamodb fixes
Signed-off-by: Ramkumar Chinchani <rchincha.dev@gmail.com>
1 parent b2bd4d2 commit e4d2e9e

1 file changed

Lines changed: 35 additions & 12 deletions

File tree

pkg/storage/cache/dynamodb.go

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
zerr "zotregistry.dev/zot/v2/errors"
1616
zlog "zotregistry.dev/zot/v2/pkg/log"
17+
"zotregistry.dev/zot/v2/pkg/storage/constants"
1718
)
1819

1920
type DynamoDBDriver struct {
@@ -186,11 +187,22 @@ func (d *DynamoDBDriver) PutBlob(digest godigest.Digest, path string) error {
186187
return zerr.ErrEmptyValue
187188
}
188189

189-
if originBlob, _ := d.GetBlob(digest); originBlob == "" {
190+
originBlob, _ := d.GetBlob(digest)
191+
if originBlob == "" {
190192
// first entry, so add original blob
191193
if err := d.putOriginBlob(digest, path); err != nil {
194+
d.log.Error().Err(err).Str("bucket", constants.OriginalBucket).Str("value", path).Msg("failed to put record")
195+
192196
return err
193197
}
198+
199+
d.log.Debug().Str("digest", digest.String()).Str("path", path).Msg("inserted in original bucket")
200+
201+
return nil
202+
} else if originBlob == path { // idempotent
203+
d.log.Debug().Str("digest", digest.String()).Str("path", path).Msg("inserted same key in original bucket")
204+
205+
return nil
194206
}
195207

196208
expression := "ADD DuplicateBlobPath :i"
@@ -202,6 +214,8 @@ func (d *DynamoDBDriver) PutBlob(digest godigest.Digest, path string) error {
202214
return err
203215
}
204216

217+
d.log.Debug().Str("digest", digest.String()).Str("path", path).Msg("inserted in duplicates bucket")
218+
205219
return nil
206220
}
207221

@@ -244,17 +258,21 @@ func (d *DynamoDBDriver) HasBlob(digest godigest.Digest, path string) bool {
244258
func (d *DynamoDBDriver) DeleteBlob(digest godigest.Digest, path string) error {
245259
marshaledKey, _ := attributevalue.MarshalMap(map[string]any{"Digest": digest.String()})
246260

247-
expression := "DELETE DuplicateBlobPath :i"
248-
attrPath := types.AttributeValueMemberSS{Value: []string{path}}
261+
// look first in the duplicates bucket
262+
originBlob, _ := d.GetDuplicateBlob(digest)
263+
if originBlob != "" {
249264

250-
if err := d.updateItem(digest, expression, map[string]types.AttributeValue{":i": &attrPath}); err != nil {
251-
d.log.Error().Err(err).Str("digest", digest.String()).Str("path", path).Msg("failed to delete")
265+
expression := "DELETE DuplicateBlobPath :i"
266+
attrPath := types.AttributeValueMemberSS{Value: []string{path}}
252267

253-
return err
254-
}
268+
if err := d.updateItem(digest, expression, map[string]types.AttributeValue{":i": &attrPath}); err != nil {
269+
d.log.Error().Err(err).Str("digest", digest.String()).Str("path", path).Msg("failed to delete")
270+
271+
return err
272+
}
273+
274+
d.log.Debug().Str("digest", digest.String()).Str("path", path).Msg("deleted from dedupe bucket")
255275

256-
originBlob, _ := d.GetDuplicateBlob(digest)
257-
if originBlob != "" {
258276
return nil
259277
}
260278

@@ -264,9 +282,14 @@ func (d *DynamoDBDriver) DeleteBlob(digest godigest.Digest, path string) error {
264282
// move duplicate blob to original, storage will move content here
265283
originBlob, _ = d.GetDuplicateBlob(digest)
266284
if originBlob != "" {
267-
if err := d.putOriginBlob(digest, originBlob); err != nil {
268-
return err
269-
}
285+
d.log.Debug().Str("digest", digest.String()).Str("path", path).Msg("more in dedupe bucket, leaving original alone")
286+
287+
return nil
288+
/*
289+
if err := d.putOriginBlob(digest, originBlob); err != nil {
290+
return err
291+
}
292+
*/
270293
}
271294
}
272295

0 commit comments

Comments
 (0)