clock: discard monotonic clock component in clock.Now() (#1437)

The dual time measurement is described in
https://go.googlesource.com/proposal/+/master/design/12914-monotonic.md

The fix is to discard hidden monotonic time component of time.Time
by converting to unix time and back.

Reviewed usage of clock.Now() and replaced with timetrack.StartTimer()
when measuring time.

The problem in #1402 was that passage of time was measured using
the monotonic time and not wall clock time. When the computer goes
to sleep, monotonic time is still monotonic while wall clock time makes
a leap when the computer wakes up. This is the behavior that
epoch manager (and most other compontents in Kopia) rely upon.

Fixes #1402

Co-authored-by: Julio Lopez <julio+gh@kasten.io>
This commit is contained in:
Jarek KowalskiandJulio Lopez authored and GitHub committed 2021-10-22 15:35:09 -07:00
1 parent c8c433fb60
commit 0d0f48a7ee
29 files changed
+123 -89

No files matched your search

+2 -2
View File
@@ -48,13 +48,13 @@ func (c *logSelectionCriteria) filterLogSessions(allSessions []*logSessionInfo)
if c.youngerThan > 0 {
allSessions = filterLogSessions(allSessions, func(ls *logSessionInfo) bool {
return clock.Since(ls.startTime) < c.youngerThan
return clock.Now().Sub(ls.startTime) < c.youngerThan
})
}
if c.olderThan > 0 {
allSessions = filterLogSessions(allSessions, func(ls *logSessionInfo) bool {
return clock.Since(ls.startTime) > c.olderThan
return clock.Now().Sub(ls.startTime) > c.olderThan
})
}
+1 -1
View File
@@ -97,7 +97,7 @@ func (c *commandMaintenanceInfo) displayCycleInfo(cp *maintenance.CycleParams, t
c.out.printStdout(" interval: %v\n", cp.Interval)
if rep.Time().Before(t) {
c.out.printStdout(" next run: %v (in %v)\n", formatTimestamp(t), clock.Until(t).Truncate(time.Second))
c.out.printStdout(" next run: %v (in %v)\n", formatTimestamp(t), t.Sub(clock.Now()).Truncate(time.Second))
} else {
c.out.printStdout(" next run: now\n")
}