From cb2a871be65eda22e70e5df028b8de3587a8708c Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Thu, 18 Jul 2019 15:02:11 +0200 Subject: [PATCH] datamanager: start initEtcd from last datastatus --- internal/datamanager/wal.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/internal/datamanager/wal.go b/internal/datamanager/wal.go index c66cfb2..847aaf3 100644 --- a/internal/datamanager/wal.go +++ b/internal/datamanager/wal.go @@ -1002,6 +1002,17 @@ func (d *DataManager) InitEtcd(ctx context.Context) error { // walsdata not found in etcd + curDataStatus, err := d.GetLastDataStatus() + if err != nil && err != ostypes.ErrNotExist { + return err + } + // set the first wal to import in etcd if there's a snapshot. In this way we'll + // ignore older wals (or wals left after an import) + var firstWal string + if err == nil { + firstWal = curDataStatus.WalSequence + } + // if there're some wals in the objectstorage this means etcd has been reset. // So take all the wals in committed or checkpointed state starting from the // first not checkpointed wal and put them in etcd @@ -1015,6 +1026,10 @@ func (d *DataManager) InitEtcd(ctx context.Context) error { return wal.Err } + if wal.WalSequence < firstWal { + continue + } + lastCommittedStorageWalElem.Value = wal lastCommittedStorageWalElem = lastCommittedStorageWalElem.Next() lastCommittedStorageWalSequence = wal.WalSequence