Skip to content

Commit 3da7b4b

Browse files
committed
fix: add redis support
1 parent e4d2e9e commit 3da7b4b

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

pkg/storage/cache/boltdb.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ func (d *BoltDBDriver) PutBlob(digest godigest.Digest, path string) error {
114114
}
115115
}
116116

117+
if len(path) == 0 {
118+
return zerr.ErrEmptyValue
119+
}
120+
117121
if err := d.db.Update(func(tx *bbolt.Tx) error {
118122
root := tx.Bucket([]byte(constants.BlobsCache))
119123
if root == nil {

pkg/storage/cache/redis.go

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,28 @@ func (d *RedisDriver) PutBlob(digest godigest.Digest, path string) error {
145145

146146
return err
147147
}
148+
149+
d.log.Debug().Str("digest", digest.String()).Str("path", path).Msg("inserted in original bucket")
150+
151+
return nil
152+
}
153+
ctx := context.TODO()
154+
// see if we are in the set
155+
exists, err := d.db.SIsMember(ctx, d.join(constants.BlobsCache, constants.OriginalBucket,
156+
digest.String()), path).Result()
157+
if err != nil {
158+
d.log.Error().Err(err).Str("sismember", d.join(constants.BlobsCache, constants.DuplicatesBucket, digest.String())).
159+
Str("digest", digest.String()).Msg("unable to get record")
160+
161+
return err
162+
}
163+
164+
if exists {
165+
d.log.Debug().Str("digest", digest.String()).Str("path", path).Msg("inserted same key in original bucket")
166+
167+
return nil
148168
}
169+
149170
// add path to the set of paths which the digest represents
150171
if err := txrp.SAdd(ctx, d.join(constants.BlobsCache, constants.DuplicatesBucket,
151172
digest.String()), path).Err(); err != nil {
@@ -234,8 +255,9 @@ func (d *RedisDriver) HasBlob(digest godigest.Digest, path string) bool {
234255
}
235256

236257
ctx := context.TODO()
258+
237259
// see if we are in the set
238-
exists, err := d.db.SIsMember(ctx, d.join(constants.BlobsCache, constants.DuplicatesBucket,
260+
exists, err := d.db.SIsMember(ctx, d.join(constants.BlobsCache, constants.OriginalBucket,
239261
digest.String()), path).Result()
240262
if err != nil {
241263
d.log.Error().Err(err).Str("sismember", d.join(constants.BlobsCache, constants.DuplicatesBucket, digest.String())).
@@ -248,13 +270,13 @@ func (d *RedisDriver) HasBlob(digest godigest.Digest, path string) bool {
248270
return false
249271
}
250272

251-
// see if the path entry exists. is this actually needed? i guess it doesn't really hurt (it is fast)
252-
exists, err = d.db.HExists(ctx, d.join(constants.BlobsCache, constants.OriginalBucket), digest.String()).Result()
253-
254-
d.log.Error().Err(err).Str("hexists", d.join(constants.BlobsCache, constants.OriginalBucket)).
255-
Str("digest", digest.String()).Msg("unable to get record")
256-
273+
// see if we are in the set
274+
exists, err = d.db.SIsMember(ctx, d.join(constants.BlobsCache, constants.DuplicatesBucket,
275+
digest.String()), path).Result()
257276
if err != nil {
277+
d.log.Error().Err(err).Str("sismember", d.join(constants.BlobsCache, constants.DuplicatesBucket, digest.String())).
278+
Str("digest", digest.String()).Msg("unable to get record")
279+
258280
return false
259281
}
260282

0 commit comments

Comments
 (0)