Skip to content

Commit

Permalink
Address review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
ishan16696 committed Feb 10, 2023
1 parent aab027c commit 4478894
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/snapshot/snapshotter/snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"io"
"path"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -792,10 +793,14 @@ func (ssr *Snapshotter) GetFullSnapshotMaxTimeWindow(fullSnapScheduleSpec string
return defaultFullSnapMaxTimeWindow
}

if schedule[dayOfMonth] == "*" && schedule[dayOfWeek] == "*" {
if schedule[dayOfMonth] == "*" && schedule[dayOfWeek] == "*" && !strings.Contains(schedule[hour], "/") {
return defaultFullSnapMaxTimeWindow
} else if schedule[dayOfWeek] != "*" {
return defaultFullSnapMaxTimeWindow * 7
} else if schedule[dayOfMonth] == "*" && schedule[dayOfWeek] == "*" && strings.Contains(schedule[hour], "/") {
if timeWindow, err := strconv.ParseFloat(schedule[hour][strings.Index(schedule[hour], "/")+1:], 64); err == nil {
return timeWindow
}
}

return defaultFullSnapMaxTimeWindow
Expand Down
16 changes: 16 additions & 0 deletions pkg/snapshot/snapshotter/snapshotter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,22 @@ var _ = Describe("Snapshotter", func() {
Expect(timeWindow).Should(Equal(fullSnapshotTimeWindow * 7))
})
})

Context("Full snapshot schedule for every 4 hours", func() {
It("should return 4 hours of timeWindow", func() {
// every 4 hour
scheduleHour := 4
snapshotterConfig := &brtypes.SnapshotterConfig{
FullSnapshotSchedule: fmt.Sprintf("%d */%d * * *", 0, scheduleHour),
}

ssr, err = NewSnapshotter(logger, snapshotterConfig, store, etcdConnectionConfig, compressionConfig, healthConfig, snapstoreConfig)
Expect(err).ShouldNot(HaveOccurred())

timeWindow := ssr.GetFullSnapshotMaxTimeWindow(snapshotterConfig.FullSnapshotSchedule)
Expect(timeWindow).Should(Equal(float64(scheduleHour)))
})
})
})

})
Expand Down

0 comments on commit 4478894

Please sign in to comment.