From dda5606e4f7becb49cd367b783b76432420b8e72 Mon Sep 17 00:00:00 2001 From: aloknerurkar Date: Wed, 16 Mar 2022 18:59:04 +0530 Subject: [PATCH] fix: incorrect release of sharky locations (#2848) --- pkg/localstore/mode_put.go | 21 ++++++++++++++++++--- pkg/localstore/mode_put_test.go | 8 ++++++++ pkg/sharky/store.go | 2 +- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/pkg/localstore/mode_put.go b/pkg/localstore/mode_put.go index ef297635620..d462c98b638 100644 --- a/pkg/localstore/mode_put.go +++ b/pkg/localstore/mode_put.go @@ -295,7 +295,12 @@ func (db *DB) putRequest( return false, 0, 0, err } - l, err := sharky.LocationFromBinary(previous.Location) + previousIdx, err := db.retrievalDataIndex.Get(previous) + if err != nil { + return false, 0, 0, fmt.Errorf("could not fetch previous item: %w", err) + } + + l, err := sharky.LocationFromBinary(previousIdx.Location) if err != nil { return false, 0, 0, err } @@ -383,7 +388,12 @@ func (db *DB) putUpload( return false, 0, fmt.Errorf("same slot remove: %w", err) } - l, err := sharky.LocationFromBinary(previous.Location) + previousIdx, err := db.retrievalDataIndex.Get(previous) + if err != nil { + return false, 0, fmt.Errorf("could not fetch previous item: %w", err) + } + + l, err := sharky.LocationFromBinary(previousIdx.Location) if err != nil { return false, 0, err } @@ -443,7 +453,12 @@ func (db *DB) putSync(batch *leveldb.Batch, loc *releaseLocations, binIDs map[ui return false, 0, 0, err } - l, err := sharky.LocationFromBinary(previous.Location) + previousIdx, err := db.retrievalDataIndex.Get(previous) + if err != nil { + return false, 0, 0, fmt.Errorf("could not fetch previous item: %w", err) + } + + l, err := sharky.LocationFromBinary(previousIdx.Location) if err != nil { return false, 0, 0, err } diff --git a/pkg/localstore/mode_put_test.go b/pkg/localstore/mode_put_test.go index b531ae698f1..13b2753d5d6 100644 --- a/pkg/localstore/mode_put_test.go +++ b/pkg/localstore/mode_put_test.go @@ -320,6 +320,14 @@ func TestModePutSyncUpload_SameIndex(t *testing.T) { if !yes { t.Fatal("chunk should be there") } + + out, err := db.retrievalDataIndex.Get(chunkToItem(chunks[1])) + if err != nil { + t.Fatal(err) + } + + validateData(t, db, out, chunks[1].Data()) + binIDs := make(map[uint8]uint64) for _, ch := range chunks { diff --git a/pkg/sharky/store.go b/pkg/sharky/store.go index 46f09b2dccc..08fde62457c 100644 --- a/pkg/sharky/store.go +++ b/pkg/sharky/store.go @@ -187,7 +187,7 @@ func (s *Store) Release(ctx context.Context, loc Location) error { s.metrics.TotalReleaseCalls.Inc() if err == nil { shard := strconv.Itoa(int(sh.index)) - s.metrics.CurrentShardSize.WithLabelValues(shard).Inc() + s.metrics.CurrentShardSize.WithLabelValues(shard).Dec() s.metrics.ShardFragmentation.WithLabelValues(shard).Sub(float64(s.maxDataSize - int(loc.Length))) } else { s.metrics.TotalReleaseCallsErr.Inc()