-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
lease: use monotime in time.Time for Go 1.9 #8507
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,22 +20,18 @@ import ( | |
"math" | ||
"sort" | ||
"sync" | ||
"sync/atomic" | ||
"time" | ||
|
||
"github.com/coreos/etcd/lease/leasepb" | ||
"github.com/coreos/etcd/mvcc/backend" | ||
"github.com/coreos/etcd/pkg/monotime" | ||
) | ||
|
||
const ( | ||
// NoLease is a special LeaseID representing the absence of a lease. | ||
NoLease = LeaseID(0) | ||
|
||
forever = monotime.Time(math.MaxInt64) | ||
) | ||
// NoLease is a special LeaseID representing the absence of a lease. | ||
const NoLease = LeaseID(0) | ||
|
||
var ( | ||
forever = time.Time{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a comment here to explain why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fanminshi How about this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's too detailed. I am thinking about just say There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe use an explicit flag
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please just use time.IsZero(); a separate type is excessive. The comment can be: expiry time.Time // no expiration when expiry.IsZero() is true There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. |
||
|
||
leaseBucketName = []byte("lease") | ||
|
||
// maximum number of leases to revoke per second; configurable for tests | ||
|
@@ -560,8 +556,10 @@ func (le *lessor) initAndRecover() { | |
type Lease struct { | ||
ID LeaseID | ||
ttl int64 // time to live in seconds | ||
// expiry is time when lease should expire; must be 64-bit aligned. | ||
expiry monotime.Time | ||
// expiryMu protects concurrent accesses to expiry | ||
expiryMu sync.RWMutex | ||
// expiry is time when lease should expire. no expiration when expiry.IsZero() is true | ||
expiry time.Time | ||
|
||
// mu protects concurrent accesses to itemSet | ||
mu sync.RWMutex | ||
|
@@ -594,12 +592,18 @@ func (l *Lease) TTL() int64 { | |
|
||
// refresh refreshes the expiry of the lease. | ||
func (l *Lease) refresh(extend time.Duration) { | ||
t := monotime.Now().Add(extend + time.Duration(l.ttl)*time.Second) | ||
atomic.StoreUint64((*uint64)(&l.expiry), uint64(t)) | ||
newExpiry := time.Now().Add(extend + time.Duration(l.ttl)*time.Second) | ||
l.expiryMu.Lock() | ||
defer l.expiryMu.Unlock() | ||
l.expiry = newExpiry | ||
} | ||
|
||
// forever sets the expiry of lease to be forever. | ||
func (l *Lease) forever() { atomic.StoreUint64((*uint64)(&l.expiry), uint64(forever)) } | ||
func (l *Lease) forever() { | ||
l.expiryMu.Lock() | ||
defer l.expiryMu.Unlock() | ||
l.expiry = forever | ||
} | ||
|
||
// Keys returns all the keys attached to the lease. | ||
func (l *Lease) Keys() []string { | ||
|
@@ -614,8 +618,12 @@ func (l *Lease) Keys() []string { | |
|
||
// Remaining returns the remaining time of the lease. | ||
func (l *Lease) Remaining() time.Duration { | ||
t := monotime.Time(atomic.LoadUint64((*uint64)(&l.expiry))) | ||
return time.Duration(t - monotime.Now()) | ||
l.expiryMu.RLock() | ||
defer l.expiryMu.RUnlock() | ||
if l.expiry.IsZero() { | ||
return time.Duration(math.MaxInt64) | ||
} | ||
return l.expiry.Sub(time.Now()) | ||
} | ||
|
||
type LeaseItem struct { | ||
|
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
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.
git rm -r pkg/monotime
too since this orphans the package