diff --git a/pkg/sharky/recovery.go b/pkg/sharky/recovery.go index 5a223e4c233..2b19ee93935 100644 --- a/pkg/sharky/recovery.go +++ b/pkg/sharky/recovery.go @@ -75,14 +75,7 @@ func (r *Recovery) Add(loc Location) error { func (r *Recovery) Read(ctx context.Context, loc Location, buf []byte) error { r.mtx.Lock() defer r.mtx.Unlock() - - shFile := r.shardFiles[loc.Shard] - if stat, err := shFile.Stat(); err != nil { - return err - } else if stat.Size() < int64(loc.Slot)*int64(r.datasize) { - return errors.New("slot not found") - } - _, err := shFile.ReadAt(buf, int64(loc.Slot)*int64(r.datasize)) + _, err := r.shardFiles[loc.Shard].ReadAt(buf, int64(loc.Slot)*int64(r.datasize)) return err } diff --git a/pkg/sharky/shard.go b/pkg/sharky/shard.go index e0b0909cc34..edb2faa8fee 100644 --- a/pkg/sharky/shard.go +++ b/pkg/sharky/shard.go @@ -7,6 +7,7 @@ package sharky import ( "context" "encoding/binary" + "fmt" "io" ) @@ -20,6 +21,10 @@ type Location struct { Length uint16 } +func (l Location) String() string { + return fmt.Sprintf("shard: %d, slot: %d, length: %d", l.Shard, l.Slot, l.Length) +} + // MarshalBinary returns byte representation of location func (l *Location) MarshalBinary() ([]byte, error) { b := make([]byte, LocationSize) diff --git a/pkg/storer/compact.go b/pkg/storer/compact.go index c44aab54e32..1cb6ebc14f8 100644 --- a/pkg/storer/compact.go +++ b/pkg/storer/compact.go @@ -93,13 +93,13 @@ func Compact(ctx context.Context, basePath string, opts *Options, validate bool) for start < end { - if slots[end] == nil { - end-- // walk to the left until a used slot found + if slots[start] != nil { + start++ // walk to the right until a free slot is found continue } - if slots[start] != nil { - start++ // walk to the right until a free slot is found + if slots[end] == nil { + end-- // walk to the left until a used slot found continue } @@ -154,7 +154,7 @@ func validationWork(logger log.Logger, store storage.Store, sharky *sharky.Recov validChunk := func(item *chunkstore.RetrievalIndexItem, buf []byte) { err := sharky.Read(context.Background(), item.Location, buf) if err != nil { - logger.Warning("invalid chunk", "address", item.Address, "timestamp", time.Unix(int64(item.Timestamp), 0), "error", err) + logger.Warning("invalid chunk", "address", item.Address, "timestamp", time.Unix(int64(item.Timestamp), 0), "location", item.Location, "error", err) return }