From 09142e4dd19564cea35d5cee25230137f2cf84ba Mon Sep 17 00:00:00 2001 From: Mario Trangoni Date: Wed, 21 Mar 2018 21:23:47 +0100 Subject: [PATCH 1/4] fix unconvert issues: unnecessary conversion --- chunkenc/xor.go | 2 +- chunks/chunks.go | 2 +- db.go | 2 +- index/index.go | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/chunkenc/xor.go b/chunkenc/xor.go index ff690f222..0f14cf720 100644 --- a/chunkenc/xor.go +++ b/chunkenc/xor.go @@ -259,7 +259,7 @@ func (it *xorIterator) Next() bool { it.err = err return false } - it.t = int64(t) + it.t = t it.val = math.Float64frombits(v) it.numRead++ diff --git a/chunks/chunks.go b/chunks/chunks.go index e32ea0f99..fa2bf3b4e 100644 --- a/chunks/chunks.go +++ b/chunks/chunks.go @@ -349,7 +349,7 @@ func (s *Reader) Chunk(ref uint64) (chunkenc.Chunk, error) { } b := s.bs[seq] - if int(off) >= b.Len() { + if off >= b.Len() { return nil, errors.Errorf("offset %d beyond data size %d", off, b.Len()) } // With the minimum chunk length this should never cause us reading diff --git a/db.go b/db.go index 489f3a12e..8328355ea 100644 --- a/db.go +++ b/db.go @@ -737,7 +737,7 @@ func (db *DB) CleanTombstones() error { defer db.cmtx.Unlock() start := time.Now() - defer db.metrics.tombCleanTimer.Observe(float64(time.Since(start).Seconds())) + defer db.metrics.tombCleanTimer.Observe(time.Since(start).Seconds()) db.mtx.RLock() blocks := db.blocks[:] diff --git a/index/index.go b/index/index.go index 3cad716c0..72ca3835a 100644 --- a/index/index.go +++ b/index/index.go @@ -780,7 +780,7 @@ func (r *Reader) readSymbols(off int) error { for d.err() == nil && d.len() > 0 && cnt > 0 { s := d.uvarintStr() - r.symbols[uint32(nextPos)] = s + r.symbols[nextPos] = s if r.version == 2 { nextPos++ @@ -800,7 +800,7 @@ func (r *Reader) readOffsetTable(off uint64, f func([]string, uint64) error) err cnt := d.be32() for d.err() == nil && d.len() > 0 && cnt > 0 { - keyCount := int(d.uvarint()) + keyCount := d.uvarint() keys := make([]string, 0, keyCount) for i := 0; i < keyCount; i++ { @@ -1038,7 +1038,7 @@ func (dec *Decoder) Series(b []byte, lbls *labels.Labels, chks *[]chunks.Meta) e d := decbuf{b: b} - k := int(d.uvarint()) + k := d.uvarint() for i := 0; i < k; i++ { lno := uint32(d.uvarint()) @@ -1061,7 +1061,7 @@ func (dec *Decoder) Series(b []byte, lbls *labels.Labels, chks *[]chunks.Meta) e } // Read the chunks meta data. - k = int(d.uvarint()) + k = d.uvarint() if k == 0 { return nil From c0e888e82b6bab94b15094de0aa40f14257ebc07 Mon Sep 17 00:00:00 2001 From: Mario Trangoni Date: Wed, 21 Mar 2018 21:39:43 +0100 Subject: [PATCH 2/4] fix megacheck issues: os.SEEK_SET is deprecated: Use io.SeekStart, io.SeekCurrent, and io.SeekEnd. --- chunks/chunks.go | 2 +- wal.go | 8 ++++---- wal_test.go | 9 +++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/chunks/chunks.go b/chunks/chunks.go index fa2bf3b4e..9c80767ff 100644 --- a/chunks/chunks.go +++ b/chunks/chunks.go @@ -133,7 +133,7 @@ func (w *Writer) finalizeTail() error { return err } // As the file was pre-allocated, we truncate any superfluous zero bytes. - off, err := tf.Seek(0, os.SEEK_CUR) + off, err := tf.Seek(0, io.SeekCurrent) if err != nil { return err } diff --git a/wal.go b/wal.go index 72e8bc070..3f1cf7d45 100644 --- a/wal.go +++ b/wal.go @@ -290,7 +290,7 @@ func (w *SegmentWAL) truncate(err error, file int, lastOffset int64) error { w.files = w.files[:file+1] // Seek the current file to the last valid offset where we continue writing from. - _, err = w.files[file].Seek(lastOffset, os.SEEK_SET) + _, err = w.files[file].Seek(lastOffset, io.SeekStart) return err } @@ -393,7 +393,7 @@ func (w *SegmentWAL) Truncate(mint int64, keep func(uint64) bool) error { return errors.Wrap(r.Err(), "read candidate WAL files") } - off, err := csf.Seek(0, os.SEEK_CUR) + off, err := csf.Seek(0, io.SeekCurrent) if err != nil { return err } @@ -583,7 +583,7 @@ func (w *SegmentWAL) cut() error { // in the new segment. go func() { w.actorc <- func() error { - off, err := hf.Seek(0, os.SEEK_CUR) + off, err := hf.Seek(0, io.SeekCurrent) if err != nil { return errors.Wrapf(err, "finish old segment %s", hf.Name()) } @@ -1024,7 +1024,7 @@ func (r *walReader) next() bool { // Remember the offset after the last correctly read entry. If the next one // is corrupted, this is where we can safely truncate. - r.lastOffset, r.err = cf.Seek(0, os.SEEK_CUR) + r.lastOffset, r.err = cf.Seek(0, io.SeekCurrent) if r.err != nil { return false } diff --git a/wal_test.go b/wal_test.go index c6552eb62..6d559f5d9 100644 --- a/wal_test.go +++ b/wal_test.go @@ -15,6 +15,7 @@ package tsdb import ( "encoding/binary" + "io" "io/ioutil" "math/rand" "os" @@ -305,7 +306,7 @@ func TestWALRestoreCorrupted(t *testing.T) { testutil.Ok(t, err) defer f.Close() - off, err := f.Seek(0, os.SEEK_END) + off, err := f.Seek(0, io.SeekEnd) testutil.Ok(t, err) testutil.Ok(t, f.Truncate(off-1)) @@ -318,7 +319,7 @@ func TestWALRestoreCorrupted(t *testing.T) { testutil.Ok(t, err) defer f.Close() - off, err := f.Seek(0, os.SEEK_END) + off, err := f.Seek(0, io.SeekEnd) testutil.Ok(t, err) testutil.Ok(t, f.Truncate(off-8)) @@ -331,7 +332,7 @@ func TestWALRestoreCorrupted(t *testing.T) { testutil.Ok(t, err) defer f.Close() - off, err := f.Seek(0, os.SEEK_END) + off, err := f.Seek(0, io.SeekEnd) testutil.Ok(t, err) // Write junk before checksum starts. @@ -346,7 +347,7 @@ func TestWALRestoreCorrupted(t *testing.T) { testutil.Ok(t, err) defer f.Close() - off, err := f.Seek(0, os.SEEK_END) + off, err := f.Seek(0, io.SeekEnd) testutil.Ok(t, err) // Write junk into checksum From c2182820ede79b70507a8f657dce2ef14dc0f657 Mon Sep 17 00:00:00 2001 From: Mario Trangoni Date: Wed, 21 Mar 2018 22:17:09 +0100 Subject: [PATCH 3/4] fix megacheck issue: should omit values from range --- block.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block.go b/block.go index 7dc3af9d8..53c4c47fd 100644 --- a/block.go +++ b/block.go @@ -474,7 +474,7 @@ func (pb *Block) CleanTombstones(dest string, c Compactor) (bool, error) { numStones := 0 pb.tombstones.Iter(func(id uint64, ivs Intervals) error { - for _ = range ivs { + for range ivs { numStones++ } From e5dabad1d703f96825492ab726426637b151ab76 Mon Sep 17 00:00:00 2001 From: Mario Trangoni Date: Wed, 21 Mar 2018 22:23:47 +0100 Subject: [PATCH 4/4] fix megacheck issue: simplified return err --- db.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/db.go b/db.go index 8328355ea..53bc65ade 100644 --- a/db.go +++ b/db.go @@ -725,10 +725,7 @@ func (db *DB) Delete(mint, maxt int64, ms ...labels.Matcher) error { g.Go(func() error { return db.head.Delete(mint, maxt, ms...) }) - if err := g.Wait(); err != nil { - return err - } - return nil + return g.Wait() } // CleanTombstones re-writes any blocks with tombstones.