-
Notifications
You must be signed in to change notification settings - Fork 9.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use monotonic time in lease #6888
Use monotonic time in lease #6888
Conversation
@@ -35,8 +35,8 @@ etcd_build() { | |||
if [ -n "${BINDIR}" ]; then out="${BINDIR}"; fi | |||
toggle_failpoints | |||
# Static compilation is useful when etcd is run in a container | |||
CGO_ENABLED=0 go build $GO_BUILD_FLAGS -installsuffix cgo -ldflags "$GO_LDFLAGS" -o ${out}/etcd ${REPO_PATH}/cmd/etcd || return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there anyway that we can enabled CGO only for darwin?
Maybe detect architecture in build script or make it configurable.
Linux still works fine with CGO disabled, as far as I know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Try if [[ "$OSTYPE" == "darwin"* ]]; then
152dcdb
to
86f0bfd
Compare
@@ -22,6 +22,7 @@ import ( | |||
"sync" | |||
"time" | |||
|
|||
"github.com/ScaleFT/monotime" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's put a space between external dependency and internal dependency (coreos/etcd/xxx)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@fanminshi The author suggests us to use https://github.com/aristanetworks/goarista/blob/master/monotime/nanotime.go instead of his library. |
@xiang90 the library that the author suggested imports unsafe. Not sure if that will cause a problem. |
86f0bfd
to
7d30c8a
Compare
I sent a PR(ScaleFT/monotime#1) ScaleFT to use aristanetworks/goarista/monotime as source of monotime. |
@fanminshi the scaleft package already imports unsafe anyway. The vendoring for all the w32 stuff seems like overkill. Just pulling in |
3db0b96
to
e99e48a
Compare
@heyitsanthony the scaleft guy decides to use "golang.org/x/sys/windows" for windows part. ScaleFT/monotime#2 |
All fixed. PLTAL @xiang90 @xiang90 @heyitsanthony |
@fanminshi vendor updates should be separate commits, but is there any reason not to use the arista code? The windows deps still seem excessive for what this does. |
@heyitsanthony I'll make separate commits for vendored stuff. My original PR to scaleFT uses arista code for windows,ScaleFT/monotime#1. However, I think scaleFT guy decided to use "golang.org/x/sys/windows". In this case, if I want to use ScaleFT, I have to import the windows deps. is there a way to get around that. I could just use our own version of their code like https://github.com/fanminshi/monotime |
2968469
to
584b431
Compare
37260f6
to
20841b7
Compare
All fixed. PTAL @xiang90 @heyitsanthony @gyuho |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package monotime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add blank line above? Otherwise it will break godoc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still see
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package monotime
?
Can you double-check?
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package monotime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fixed now
20841b7
to
2ccf41b
Compare
return Now() | ||
} | ||
|
||
func (t *monoTimer) Since(start uint64) time.Duration { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need separate Since
method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me Since() could be useful function. I could make it a private helper function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure why this is a method on monoTimer
since it doesn't use anything from monoTimer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok keeping it sounds good to me.
2ccf41b
to
e78ebb5
Compare
// Use of this source code is governed by the Apache License 2.0 | ||
// that can be found in the COPYING file. | ||
|
||
// Package monotime provides a fast monotonic clock source. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this comment
// that can be...
package monotime
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will change
lgtm. defer to @xiang90 @heyitsanthony |
return Now() | ||
} | ||
|
||
func (t *monoTimer) Since(start uint64) time.Duration { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure why this is a method on monoTimer
since it doesn't use anything from monoTimer
// expiry time in unixnano | ||
expiry time.Time | ||
// expiry is time when lease should expire | ||
expiry time.Duration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the wrong type; Durations aren't deadlines. Probably have a type monotime.Time uint64
(to indicate it's not a time based on the system time) or something?
"time" | ||
) | ||
|
||
type Timer interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought this interface wasn't going to be used? Why are monotime.Now()
and monotime.Since(uint64)
not good enough? I don't think wrapping Now/Since with this really buys anything
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, monotime.Now() and monotime.Since(uint64) should be sufficient. Will change to that
// Since returns duration between two points of time | ||
Since(uint64) time.Duration | ||
// SinceBegining returns duration between now and when timer is created | ||
SinceBegining() time.Duration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elapsed
forever = time.Unix(math.MaxInt64>>1, 0) | ||
|
||
monoTimer = monotime.New() | ||
forever = time.Duration(1>>63 - 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
math.MaxInt64
e78ebb5
to
3a8847f
Compare
All fixed. PTAL @heyitsanthony @gyuho |
CI fails with
|
"time" | ||
) | ||
|
||
// time represents a point in monotonic time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah let's change this to Time
... go vet complains
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I just changed that.
3a8847f
to
49a73be
Compare
// Use of this source code is governed by the Apache License 2.0 | ||
// that can be found in the COPYING file. | ||
|
||
// Package monotime provides a fast monotonic clock source. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be
// Package monotime provides a fast monotonic clock source.
package monotime
Otherwise godoc won't catch it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
// Copyright (C) 2016 Arista Networks, Inc. | ||
// Use of this source code is governed by the Apache License 2.0 | ||
|
||
// Package monotime provides a fast monotonic clock source. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this description is duplicate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
lease uses monotimer to calculate its expiration. In this way, changing system time won't affect in lease expiration. FIX etcd-io#6700
49a73be
to
e7f4010
Compare
All fixed. PTAL @xiang90 @heyitsanthony @gyuho |
lgtm |
lease uses monotimer to calculate its expiration. In this way, changing system time won't affect in lease expiration.
FIX #6700