Files
kopia/internal/clock/now.go
Jarek Kowalski 0d0f48a7ee 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>
2021-10-22 15:35:09 -07:00

15 lines
569 B
Go

// Package clock provides indirection for accessing current wall clock time.
// this is suitable for timestamps and long-term time operations, not short-term time measurements.
package clock
import "time"
// discardMonotonicTime discards any monotonic time component of time,
// which behaves incorrectly when the computer goes to sleep and we want to measure durations
// between points in time.
//
// See https://go.googlesource.com/proposal/+/master/design/12914-monotonic.md
func discardMonotonicTime(t time.Time) time.Time {
return time.Unix(0, t.UnixNano())
}