datamanager: skip already applied wals in writeDataSnapshot

As an optimization don't apply already applied wals.
This commit is contained in:
Simone Gotti 2019-11-05 17:48:11 +01:00
parent aff44f7e89
commit 1e70e3404b
1 changed files with 19 additions and 4 deletions

View File

@ -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
}