diff --git a/state/history.go b/state/history.go index 4fa228f2b..a07e876ec 100644 --- a/state/history.go +++ b/state/history.go @@ -504,7 +504,9 @@ func (h *historyWAL) close() { if h == nil { // allow dobule-close return } - h.historyVals.Close() + if h.historyVals != nil { + h.historyVals.Close() + } } func (h *History) newWriter(tmpdir string, buffered, discard bool) *historyWAL { @@ -518,8 +520,8 @@ func (h *History) newWriter(tmpdir string, buffered, discard bool) *historyWAL { } if buffered { w.historyVals = etl.NewCollector(h.historyValsTable, tmpdir, etl.NewSortableBuffer(WALCollectorRam)) + w.historyVals.LogLvl(log.LvlTrace) } - w.historyVals.LogLvl(log.LvlTrace) val, err := h.tx.GetOne(h.settingsTable, historyValCountKey) if err != nil { @@ -535,6 +537,9 @@ func (h *History) newWriter(tmpdir string, buffered, discard bool) *historyWAL { } func (h *historyWAL) flush(tx kv.RwTx) error { + if h.discard { + return nil + } binary.BigEndian.PutUint64(h.autoIncrementBuf, h.autoIncrement) if err := tx.Put(h.h.settingsTable, historyValCountKey, h.autoIncrementBuf); err != nil { return err diff --git a/state/inverted_index.go b/state/inverted_index.go index fe894bf60..f4485446f 100644 --- a/state/inverted_index.go +++ b/state/inverted_index.go @@ -364,6 +364,9 @@ func loadFunc(k, v []byte, table etl.CurrentTableReader, next etl.LoadNextFunc) } func (ii *invertedIndexWAL) Flush(tx kv.RwTx) error { + if ii.discard { + return nil + } if err := ii.index.Load(tx, ii.ii.indexTable, loadFunc, etl.TransformArgs{}); err != nil { return err } @@ -378,8 +381,12 @@ func (ii *invertedIndexWAL) close() { if ii == nil { return } - ii.index.Close() - ii.indexKeys.Close() + if ii.index != nil { + ii.index.Close() + } + if ii.indexKeys != nil { + ii.indexKeys.Close() + } } var WALCollectorRam = etl.BufferOptimalSize / 16 @@ -406,9 +413,9 @@ func (ii *InvertedIndex) newWriter(tmpdir string, buffered, discard bool) *inver // etl collector doesn't fsync: means if have enough ram, all files produced by all collectors will be in ram w.index = etl.NewCollector(ii.indexTable, tmpdir, etl.NewSortableBuffer(WALCollectorRam)) w.indexKeys = etl.NewCollector(ii.indexKeysTable, tmpdir, etl.NewSortableBuffer(WALCollectorRam)) + w.index.LogLvl(log.LvlTrace) + w.indexKeys.LogLvl(log.LvlTrace) } - w.index.LogLvl(log.LvlTrace) - w.indexKeys.LogLvl(log.LvlTrace) return w }