Skip to content

Commit

Permalink
Merge pull request #166 from swapnilgm/hotfix/compact-version
Browse files Browse the repository at this point in the history
Fix error handling for initial delta snapshot
  • Loading branch information
swapnilgm authored Jun 12, 2019
2 parents ab7c896 + 2afb418 commit a95be60
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
34 changes: 15 additions & 19 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,12 @@ func NewServerCommand(stopCh <-chan struct{}) *cobra.Command {
// the delta snapshot memory limit), after which a full snapshot
// is taken and the regular snapshot schedule comes into effect.

var startWithFullSnapshot bool
var initialDeltaSnapshotTaken bool

// TODO: write code to find out if prev full snapshot is older than it is
// supposed to be, according to the given cron schedule, instead of the
// hard-coded "24 hours" full snapshot interval
if ssr.PrevFullSnapshot == nil || time.Now().Sub(ssr.PrevFullSnapshot.CreatedOn).Hours() > 24 {
startWithFullSnapshot = false
if err = ssr.TakeFullSnapshotAndResetTimer(); err != nil {
logger.Errorf("Failed to take first full snapshot: %v", err)
continue
}
} else {
startWithFullSnapshot = true
if ssr.PrevFullSnapshot != nil && time.Since(ssr.PrevFullSnapshot.CreatedOn).Hours() <= 24 {
ssrStopped, err := ssr.CollectEventsSincePrevSnapshot(ssrStopCh)
if ssrStopped {
logger.Info("Snapshotter stopped.")
Expand All @@ -193,16 +186,19 @@ func NewServerCommand(stopCh <-chan struct{}) *cobra.Command {
logger.Info("Shutting down...")
return
}
if err != nil {
if etcdErr, ok := err.(*errors.EtcdError); ok == true {
logger.Errorf("Failed to take first delta snapshot: snapshotter failed with etcd error: %v", etcdErr)
} else {
logger.Errorf("Failed to take first delta snapshot: snapshotter failed with error: %v", err)
if err == nil {
if err := ssr.TakeDeltaSnapshot(); err != nil {
logger.Warnf("Failed to take first delta snapshot: snapshotter failed with error: %v", err)
continue
}
continue
initialDeltaSnapshotTaken = true
} else {
logger.Warnf("Failed to collect events for first delta snapshot: %v", err)
}
if err = ssr.TakeDeltaSnapshot(); err != nil {
logger.Errorf("Failed to take first delta snapshot: snapshotter failed with error: %v", err)
}
if !initialDeltaSnapshotTaken {
if err := ssr.TakeFullSnapshotAndResetTimer(); err != nil {
logger.Errorf("Failed to take substitute first full snapshot: %v", err)
continue
}
}
Expand All @@ -217,11 +213,11 @@ func NewServerCommand(stopCh <-chan struct{}) *cobra.Command {
gcStopCh := make(chan struct{})
go ssr.RunGarbageCollector(gcStopCh)
logger.Infof("Starting snapshotter...")
if err := ssr.Run(ssrStopCh, startWithFullSnapshot); err != nil {
if err := ssr.Run(ssrStopCh, initialDeltaSnapshotTaken); err != nil {
if etcdErr, ok := err.(*errors.EtcdError); ok == true {
logger.Errorf("Snapshotter failed with etcd error: %v", etcdErr)
} else {
logger.Errorf("Snapshotter failed with error: %v", err)
logger.Fatalf("Snapshotter failed with error: %v", err)
}
}
logger.Infof("Snapshotter stopped.")
Expand Down
5 changes: 4 additions & 1 deletion pkg/snapstore/abs_snapstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ func GetABSSnapstoreFromClient(container, prefix, tempDir string, maxParallelChu
_, err := containerURL.GetProperties(ctx, azblob.LeaseAccessConditions{})
if err != nil {
aer, ok := err.(azblob.StorageError)
if !ok || aer.ServiceCode() != azblob.ServiceCodeContainerNotFound {
if !ok {
return nil, fmt.Errorf("failed to get properties of container %v with err, %v", container, err.Error())
}
if aer.ServiceCode() != azblob.ServiceCodeContainerNotFound {
return nil, fmt.Errorf("failed to get properties of container %v with err, %v", container, aer.Error())
}
return nil, fmt.Errorf("container %s does not exist", container)
Expand Down

0 comments on commit a95be60

Please sign in to comment.