Skip to content

Commit

Permalink
Skip snap store specific sanity check when not configured
Browse files Browse the repository at this point in the history
Signed-off-by: Swapnil Mhamane <swapnil.mhamane@sap.com>
  • Loading branch information
Swapnil Mhamane committed Feb 19, 2019
1 parent 5943b65 commit 3fdf4dd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
4 changes: 4 additions & 0 deletions pkg/initializer/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ func (e *EtcdInitializer) restoreCorruptData() error {

if e.Config.SnapstoreConfig == nil {
logger.Warnf("No snapstore storage provider configured.")
logger.Infof("Removing data directory(%s) for snapshot restoration.", dataDir)
if err := os.RemoveAll(filepath.Join(dataDir)); err != nil {
return fmt.Errorf("failed to delete data directory %s with err: %v", dataDir, err)
}
return nil
}
store, err := snapstore.GetSnapstore(e.Config.SnapstoreConfig)
Expand Down
20 changes: 12 additions & 8 deletions pkg/initializer/validator/datavalidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,14 @@ func (d *DataValidator) Validate() (DataDirStatus, error) {
return DataDirectoryInvStruct, nil
}

d.Logger.Info("Checking for revision consistency...")
if err = d.CheckRevisionConsistency(); err != nil {
d.Logger.Infof("Etcd revision inconsistent with latest snapshot revision: %v", err)
return RevisionConsistencyError, nil
if d.Config.SnapstoreConfig != nil {
d.Logger.Info("Checking for revision consistency...")
if err = checkRevisionConsistency(d.backendPath(), *d.Config.SnapstoreConfig); err != nil {
d.Logger.Infof("Etcd revision inconsistent with latest snapshot revision: %v", err)
return RevisionConsistencyError, nil
}
} else {
d.Logger.Info("Skipping check for revision consistency, since no snapstore configured.")
}

d.Logger.Info("Checking for data directory files corruption...")
Expand Down Expand Up @@ -338,14 +342,14 @@ func verifyDB(path string) error {
})
}

// CheckRevisionConsistency compares the latest revisions on the etcd db file and the latest snapshot to verify that the etcd revision is not lesser than snapshot revision.
func (d *DataValidator) CheckRevisionConsistency() error {
etcdRevision, err := getLatestEtcdRevision(d.backendPath())
// checkRevisionConsistency compares the latest revisions on the etcd db file and the latest snapshot to verify that the etcd revision is not lesser than snapshot revision.
func checkRevisionConsistency(dbPath string, config snapstore.Config) error {
etcdRevision, err := getLatestEtcdRevision(dbPath)
if err != nil {
return fmt.Errorf("unable to get current etcd revision from backend db file: %v", err)
}

store, err := snapstore.GetSnapstore(d.Config.SnapstoreConfig)
store, err := snapstore.GetSnapstore(&config)
if err != nil {
return fmt.Errorf("unable to fetch snapstore: %v", err)
}
Expand Down

0 comments on commit 3fdf4dd

Please sign in to comment.