diff --git a/compress/decompress.go b/compress/decompress.go index af32596bc..cc89e4c50 100644 --- a/compress/decompress.go +++ b/compress/decompress.go @@ -382,7 +382,12 @@ func (d *Decompressor) WithReadAhead(f func() error) error { } // DisableReadAhead - usage: `defer d.EnableReadAhead().DisableReadAhead()`. Please don't use this funcs without `defer` to avoid leak. -func (d *Decompressor) DisableReadAhead() { _ = mmap.MadviseRandom(d.mmapHandle1) } +func (d *Decompressor) DisableReadAhead() { + if d == nil || d.mmapHandle1 == nil { + return + } + _ = mmap.MadviseRandom(d.mmapHandle1) +} func (d *Decompressor) EnableReadAhead() *Decompressor { _ = mmap.MadviseSequential(d.mmapHandle1) return d diff --git a/recsplit/index.go b/recsplit/index.go index cfea6b209..0cd92a14c 100644 --- a/recsplit/index.go +++ b/recsplit/index.go @@ -315,7 +315,12 @@ func (idx *Index) RewriteWithOffsets(w *bufio.Writer, m map[uint64]uint64) error } // DisableReadAhead - usage: `defer d.EnableReadAhead().DisableReadAhead()`. Please don't use this funcs without `defer` to avoid leak. -func (idx *Index) DisableReadAhead() { _ = mmap.MadviseRandom(idx.mmapHandle1) } +func (idx *Index) DisableReadAhead() { + if idx == nil || idx.mmapHandle1 == nil { + return + } + _ = mmap.MadviseRandom(idx.mmapHandle1) +} func (idx *Index) EnableReadAhead() *Index { _ = mmap.MadviseSequential(idx.mmapHandle1) return idx diff --git a/state/history.go b/state/history.go index 7f6a2e2e0..9c6444e25 100644 --- a/state/history.go +++ b/state/history.go @@ -489,6 +489,7 @@ type historyWAL struct { historyVals *etl.Collector tmpdir string autoIncrementBuf []byte + historyKey []byte autoIncrement uint64 buffered bool } @@ -504,6 +505,7 @@ func (h *History) newWriter(tmpdir string) *historyWAL { w := &historyWAL{h: h, tmpdir: tmpdir, autoIncrementBuf: make([]byte, 8), + historyKey: make([]byte, 0, 128), buffered: true, historyVals: etl.NewCollector(h.historyValsTable, tmpdir, etl.NewSortableBuffer(etl.BufferOptimalSize/16)), @@ -564,7 +566,7 @@ func (h *historyWAL) addPrevValue(key1, key2, original []byte) error { */ lk := len(key1) + len(key2) - historyKey := make([]byte, lk+8) + historyKey := h.historyKey[:lk+8] copy(historyKey, key1) if len(key2) > 0 { copy(historyKey[len(key1):], key2) @@ -585,6 +587,8 @@ func (h *historyWAL) addPrevValue(key1, key2, original []byte) error { return err } } + } else { + binary.BigEndian.PutUint64(historyKey[lk:], 0) } if err := h.h.InvertedIndex.add(historyKey, historyKey[:lk]); err != nil {