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 }