Skip to content

Commit 23f1ebc

Browse files
committed
fix: botldb
Signed-off-by: Ramkumar Chinchani <[email protected]>
1 parent 6845162 commit 23f1ebc

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

pkg/storage/cache/boltdb.go

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,6 @@ func (d *BoltDBDriver) PutBlob(digest godigest.Digest, path string) error {
132132
return err
133133
}
134134

135-
// create nested deduped bucket where we store all the deduped blobs + original blob
136-
deduped, err := bucket.CreateBucketIfNotExists([]byte(constants.DuplicatesBucket))
137-
if err != nil {
138-
// this is a serious failure
139-
d.log.Error().Err(err).Str("bucket", constants.DuplicatesBucket).Msg("failed to create a bucket")
140-
141-
return err
142-
}
143-
144-
if err := deduped.Put([]byte(path), nil); err != nil {
145-
d.log.Error().Err(err).Str("bucket", constants.DuplicatesBucket).Str("value", path).Msg("failed to put record")
146-
147-
return err
148-
}
149-
150-
d.log.Debug().Str("digest", digest.String()).Str("path", path).Msg("inserted in duplicates bucket")
151-
152135
// create origin bucket and insert only the original blob
153136
origin := bucket.Bucket([]byte(constants.OriginalBucket))
154137
if origin == nil {
@@ -167,8 +150,30 @@ func (d *BoltDBDriver) PutBlob(digest godigest.Digest, path string) error {
167150
return err
168151
}
169152
d.log.Debug().Str("digest", digest.String()).Str("path", path).Msg("inserted in original bucket")
153+
154+
return nil
155+
} else if origin.Get([]byte(path)) != nil { // idempotent
156+
d.log.Debug().Str("digest", digest.String()).Str("path", path).Msg("inserted same key in original bucket")
157+
return nil
158+
}
159+
160+
// create nested deduped bucket where we store all the deduped blobs + original blob
161+
deduped, err := bucket.CreateBucketIfNotExists([]byte(constants.DuplicatesBucket))
162+
if err != nil {
163+
// this is a serious failure
164+
d.log.Error().Err(err).Str("bucket", constants.DuplicatesBucket).Msg("failed to create a bucket")
165+
166+
return err
170167
}
171168

169+
if err := deduped.Put([]byte(path), nil); err != nil {
170+
d.log.Error().Err(err).Str("bucket", constants.DuplicatesBucket).Str("value", path).Msg("failed to put record")
171+
172+
return err
173+
}
174+
175+
d.log.Debug().Str("digest", digest.String()).Str("path", path).Msg("inserted in duplicates bucket")
176+
172177
return nil
173178
}); err != nil {
174179
return err

0 commit comments

Comments
 (0)