mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
fix(store): TTL should range 1..n rather than 1..n+1
was experiencing intermittent functional test fails where TTL was eg 101 when 100 was expected informal testing on a windows platform shows Go times resolving to the nanosecond but with an accuracy of approximately 1 millisecond I believe some of the functional test steps would run in under a millisecond and cause the TTL to be recomputed with the same time.Now() value resulting in a TTL that was +1 from the expected
This commit is contained in:
parent
77887e8253
commit
a2e5bae951
@ -113,7 +113,19 @@ func (n *node) Write(value string, index uint64) *etcdErr.Error {
|
||||
|
||||
func (n *node) ExpirationAndTTL() (*time.Time, int64) {
|
||||
if !n.IsPermanent() {
|
||||
return &n.ExpireTime, int64(n.ExpireTime.Sub(time.Now())/time.Second) + 1
|
||||
/* compute ttl as:
|
||||
ceiling( (expireTime - timeNow) / nanosecondsPerSecond )
|
||||
which ranges from 1..n
|
||||
rather than as:
|
||||
( (expireTime - timeNow) / nanosecondsPerSecond ) + 1
|
||||
which ranges 1..n+1
|
||||
*/
|
||||
ttlN := n.ExpireTime.Sub(time.Now())
|
||||
ttl := ttlN / time.Second
|
||||
if (ttlN % time.Second) > 0 {
|
||||
ttl++
|
||||
}
|
||||
return &n.ExpireTime, int64(ttl)
|
||||
}
|
||||
return nil, 0
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user