Skip to content

Commit 3c6902e

Browse files
committed
fix: botdb fixes
1 parent b57c349 commit 3c6902e

File tree

2 files changed

+55
-24
lines changed

2 files changed

+55
-24
lines changed

pkg/storage/cache/boltdb.go

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -285,19 +285,21 @@ func (d *BoltDBDriver) HasBlob(digest godigest.Digest, blob string) bool {
285285
return zerr.ErrCacheMiss
286286
}
287287

288+
if origin.Get([]byte(blob)) != nil {
289+
d.log.Debug().Str("key", blob).Msg("found in original bucket")
290+
return nil
291+
}
292+
288293
deduped := bucket.Bucket([]byte(constants.DuplicatesBucket))
289294
if deduped == nil {
290295
return zerr.ErrCacheMiss
291296
}
292297

293-
if origin.Get([]byte(blob)) == nil {
294-
if deduped.Get([]byte(blob)) == nil {
295-
return zerr.ErrCacheMiss
296-
}
297-
d.log.Debug().Str("key", blob).Msg("found in dedupe bucket")
298+
if deduped.Get([]byte(blob)) == nil {
299+
return zerr.ErrCacheMiss
298300
}
299301

300-
d.log.Debug().Str("key", blob).Msg("found in original bucket")
302+
d.log.Debug().Str("key", blob).Msg("found in duplicates bucket")
301303

302304
return nil
303305
}); err != nil {
@@ -343,30 +345,34 @@ func (d *BoltDBDriver) DeleteBlob(digest godigest.Digest, path string) error {
343345
return zerr.ErrCacheMiss
344346
}
345347

348+
// look first in the duplicates bucket
346349
deduped := bucket.Bucket([]byte(constants.DuplicatesBucket))
347-
if deduped == nil {
348-
return zerr.ErrCacheMiss
349-
}
350-
351-
if err := deduped.Delete([]byte(path)); err != nil {
352-
d.log.Error().Err(err).Str("digest", digest.String()).Str("bucket", constants.DuplicatesBucket).
353-
Str("path", path).Msg("failed to delete")
350+
if deduped != nil {
351+
if deduped.Get([]byte(path)) != nil {
352+
if err := deduped.Delete([]byte(path)); err != nil {
353+
d.log.Error().Err(err).Str("digest", digest.String()).Str("bucket", constants.DuplicatesBucket).
354+
Str("path", path).Msg("failed to delete")
354355

355-
return err
356-
}
356+
return err
357+
}
357358

358-
d.log.Debug().Str("digest", digest.String()).Str("path", path).Msg("deleted from dedupe bucket")
359+
d.log.Debug().Str("digest", digest.String()).Str("path", path).Msg("deleted from dedupe bucket")
359360

360-
dedupeBlob := d.getOne(deduped)
361-
if dedupeBlob != nil {
362-
d.log.Debug().Str("digest", digest.String()).Str("path", path).Msg("more in dedupe bucket, leaving original alone")
363-
return nil
361+
return nil
362+
}
364363
}
365364

366365
origin := bucket.Bucket([]byte(constants.OriginalBucket))
367366
if origin != nil {
368-
originBlob := d.getOne(origin)
369-
if originBlob != nil {
367+
if origin.Get([]byte(path)) != nil {
368+
369+
dedupeBlob := d.getOne(deduped)
370+
if dedupeBlob != nil {
371+
d.log.Debug().Str("digest", digest.String()).Str("path", path).Msg("more in dedupe bucket, leaving original alone")
372+
373+
return nil
374+
}
375+
370376
if err := origin.Delete([]byte(path)); err != nil {
371377
d.log.Error().Err(err).Str("digest", digest.String()).Str("bucket", constants.OriginalBucket).
372378
Str("path", path).Msg("failed to delete")
@@ -401,9 +407,11 @@ func (d *BoltDBDriver) DeleteBlob(digest godigest.Digest, path string) error {
401407

402408
return err
403409
}
410+
411+
return nil
404412
}
405413

406-
return nil
414+
return zerr.ErrCacheMiss
407415
}); err != nil {
408416
return err
409417
}

pkg/storage/cache/boltdb_test.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,39 @@ func TestBoltDBCache(t *testing.T) {
3838
exists := cacheDriver.HasBlob("key", "value")
3939
So(exists, ShouldBeFalse)
4040

41+
Print("BDB1")
42+
4143
err = cacheDriver.PutBlob("key", path.Join(dir, "value"))
4244
So(err, ShouldBeNil)
4345

46+
Print("BDB2")
47+
4448
err = cacheDriver.PutBlob("key", "value")
4549
So(err, ShouldNotBeNil)
4650

51+
Print("BDB3")
52+
4753
exists = cacheDriver.HasBlob("key", "value")
4854
So(exists, ShouldBeTrue)
4955

56+
Print("BDB4")
57+
5058
val, err = cacheDriver.GetBlob("key")
5159
So(err, ShouldBeNil)
5260
So(val, ShouldNotBeEmpty)
5361

62+
Print("BDB5")
63+
5464
err = cacheDriver.DeleteBlob("bogusKey", "bogusValue")
5565
So(err, ShouldEqual, errors.ErrCacheMiss)
5666

67+
Print("BDB6")
68+
5769
err = cacheDriver.DeleteBlob("key", "bogusValue")
58-
So(err, ShouldBeNil)
70+
So(err, ShouldEqual, errors.ErrCacheMiss)
71+
//So(err, ShouldBeNil)
72+
73+
Print("BDB7")
5974

6075
// try to insert empty path
6176
err = cacheDriver.PutBlob("key", "")
@@ -78,20 +93,28 @@ func TestBoltDBCache(t *testing.T) {
7893
err = cacheDriver.DeleteBlob("key1", "duplicateBlobPath")
7994
So(err, ShouldBeNil)
8095

96+
Print("BDB8")
97+
8198
val, err = cacheDriver.GetBlob("key1")
8299
So(val, ShouldEqual, "originalBlobPath")
83100
So(err, ShouldBeNil)
84101

85102
err = cacheDriver.PutBlob("key1", "duplicateBlobPath")
86103
So(err, ShouldBeNil)
87104

105+
Print("BDB9")
106+
88107
err = cacheDriver.DeleteBlob("key1", "originalBlobPath")
89108
So(err, ShouldBeNil)
90109

110+
Print("BDB10")
111+
91112
val, err = cacheDriver.GetBlob("key1")
92113
So(val, ShouldEqual, "originalBlobPath")
93114
So(err, ShouldBeNil)
94115

116+
Print("BDB11")
117+
95118
err = cacheDriver.DeleteBlob("key1", "duplicateBlobPath")
96119
So(err, ShouldBeNil)
97120

0 commit comments

Comments
 (0)