Merge pull request #167 from sgotti/datamanager_writedatasnapshot_skip_already_checkpointed_wals

datamanager: skip already applied wals in writeDataSnapshot
This commit is contained in:
Simone Gotti 2019-11-12 14:57:42 +01:00 committed by GitHub
commit 24a9563872
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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), Files: make(map[string][]*DataStatusFile),
} }
wi, err := d.walIndex(ctx, wals) curDataStatus, err := d.GetLastDataStatus()
if err != nil { if err != nil && !errors.Is(err, ErrNoDataStatus) {
return err return err
} }
curDataStatus, err := d.GetLastDataStatus() startWalIndex := 0
if err != nil && !errors.Is(err, ErrNoDataStatus) { 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 return err
} }