Skip to content

Commit

Permalink
fix: logs
Browse files Browse the repository at this point in the history
  • Loading branch information
istae committed Sep 28, 2023
1 parent 9f779ff commit 2497762
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
9 changes: 1 addition & 8 deletions pkg/sharky/recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/sharky/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package sharky
import (
"context"
"encoding/binary"
"fmt"
"io"
)

Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions pkg/storer/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 2497762

Please sign in to comment.