From 1e70e3404b9c475e58efbe0ee7906c873a571e1a Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Tue, 5 Nov 2019 17:48:11 +0100 Subject: [PATCH] datamanager: skip already applied wals in writeDataSnapshot As an optimization don't apply already applied wals. --- internal/datamanager/data.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/internal/datamanager/data.go b/internal/datamanager/data.go index cdc5c8c..f6352c7 100644 --- a/internal/datamanager/data.go +++ b/internal/datamanager/data.go @@ -163,13 +163,28 @@ func (d *DataManager) writeDataSnapshot(ctx context.Context, wals []*WalData) er Files: make(map[string][]*DataStatusFile), } - wi, err := d.walIndex(ctx, wals) - if err != nil { + curDataStatus, err := d.GetLastDataStatus() + if err != nil && !errors.Is(err, ErrNoDataStatus) { return err } - curDataStatus, err := d.GetLastDataStatus() - if err != nil && !errors.Is(err, ErrNoDataStatus) { + startWalIndex := 0 + if curDataStatus != nil { + // skip wals already checkpointed in this data status + for i, wal := range wals { + if wal.WalSequence <= curDataStatus.WalSequence { + continue + } + + startWalIndex = i + break + } + } + + wals = wals[startWalIndex:] + + wi, err := d.walIndex(ctx, wals) + if err != nil { return err }