datamanager: accept optional datastatus in initEtcd

This commit is contained in:
Simone Gotti 2019-07-18 14:54:07 +02:00
parent df716fccc6
commit c034819087
2 changed files with 14 additions and 10 deletions

View File

@ -193,7 +193,7 @@ func (d *DataManager) deleteEtcd(ctx context.Context) error {
func (d *DataManager) Run(ctx context.Context, readyCh chan struct{}) error {
for {
err := d.InitEtcd(ctx)
err := d.InitEtcd(ctx, nil)
if err == nil {
break
}

View File

@ -907,7 +907,7 @@ func (d *DataManager) etcdPinger(ctx context.Context) error {
return nil
}
func (d *DataManager) InitEtcd(ctx context.Context) error {
func (d *DataManager) InitEtcd(ctx context.Context, dataStatus *DataStatus) error {
writeWal := func(wal *WalFile) error {
walFile, err := d.ost.ReadObject(d.storageWalStatusFile(wal.WalSequence) + ".committed")
if err != nil {
@ -1002,15 +1002,19 @@ 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 dataStatus != nil {
firstWal = dataStatus.WalSequence
} else {
dataStatus, 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)
if err == nil {
firstWal = dataStatus.WalSequence
}
}
// if there're some wals in the objectstorage this means etcd has been reset.