From 708f35e5c1155f75b3fa2808d460720c44193532 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Tue, 22 May 2018 17:05:54 +0400 Subject: [PATCH] do not look for height in older files if we've seen height - 1 Refs #1600 --- CHANGELOG.md | 1 + consensus/wal.go | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 599c66073..bf3059374 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ IMPROVEMENTS: - [consensus] consensus reactor now receives events from a separate event bus, which is not dependant on external RPC load +- [consensus/wal] do not look for height in older files if we've seen height - 1 ## 0.19.5 diff --git a/consensus/wal.go b/consensus/wal.go index c00fec614..80cb8fc3c 100644 --- a/consensus/wal.go +++ b/consensus/wal.go @@ -151,6 +151,7 @@ type WALSearchOptions struct { // CONTRACT: caller must close group reader. func (wal *baseWAL) SearchForEndHeight(height int64, options *WALSearchOptions) (gr *auto.GroupReader, found bool, err error) { var msg *TimedWALMessage + lastHeightFound := int64(-1) // NOTE: starting from the last file in the group because we're usually // searching for the last height. See replay.go @@ -166,6 +167,11 @@ func (wal *baseWAL) SearchForEndHeight(height int64, options *WALSearchOptions) for { msg, err = dec.Decode() if err == io.EOF { + // OPTIMISATION: no need to look for height in older files if we've seen h < height + if lastHeightFound > 0 && lastHeightFound < height { + gr.Close() + return nil, false, nil + } // check next file break } @@ -179,6 +185,7 @@ func (wal *baseWAL) SearchForEndHeight(height int64, options *WALSearchOptions) } if m, ok := msg.Msg.(EndHeightMessage); ok { + lastHeightFound = m.Height if m.Height == height { // found wal.Logger.Debug("Found", "height", height, "index", index) return gr, true, nil