Skip to content

Commit

Permalink
Code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jwilder committed Jul 14, 2023
1 parent 00c7fab commit b094392
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pkg/wal/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (b *segmentIterator) Next() (bool, error) {
}

func (b *segmentIterator) nextValue() (bool, error) {
if b.n > len(b.buf) {
if b.n >= len(b.buf) {
return false, io.EOF
}
blockLen := binary.BigEndian.Uint32(b.buf[b.n : b.n+4])
Expand Down
5 changes: 4 additions & 1 deletion pkg/wal/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func (s *segment) Close() error {
return s.w.Close()
}

// repair truncates the last bytes in the segment if they don't are missing, corrupted or have extra data. This
// repair truncates the last bytes in the segment if they are missing, corrupted or have extra data. This
// repairs any corrupted segment that may not have fully flushed to disk safely.
func (s *segment) repair() error {
buf := make([]byte, 0, 4096)
Expand All @@ -304,6 +304,7 @@ func (s *segment) repair() error {
idx += n

if err != nil || n != 8 {
logger.Warn("Repairing segment %s, missing block header, truncating at %d", s.path, lastGoodIdx)
return s.truncate(int64(lastGoodIdx))
}

Expand All @@ -321,10 +322,12 @@ func (s *segment) repair() error {
}

if uint32(n) != blockLen {
logger.Warn("Repairing segment %s, short block, truncating at %d", s.path, lastGoodIdx)
return s.truncate(int64(lastGoodIdx))
}

if crc32.ChecksumIEEE(buf[:blockLen]) != crc {
logger.Warn("Repairing segment %s, checksum failed, truncating at %d", s.path, lastGoodIdx)
return s.truncate(int64(lastGoodIdx))
}

Expand Down
21 changes: 0 additions & 21 deletions tools/cmd/walreader/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package main

import (
"bytes"
"flag"
"io"
"os"

"github.com/Azure/adx-mon/pkg/logger"
Expand Down Expand Up @@ -39,23 +37,4 @@ func main() {
}
print(string(iter.Value()))
}

return
reader, err := wal.NewSegmentReader(dataFile)
if err != nil {
logger.Fatal("open file: %s", err)
}

defer reader.Close()

b, err := io.ReadAll(reader)
if err != nil {
// logger.Fatal("read: %s", err)
}

lines := bytes.Split(b, []byte("\n"))
for _, line := range lines {
println(string(line))
}

}

0 comments on commit b094392

Please sign in to comment.