mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
refactor use time.IsZero
This commit is contained in:
parent
c05df9e3f5
commit
3f6d6cf4c6
@ -9,15 +9,13 @@ import (
|
|||||||
etcdErr "github.com/coreos/etcd/error"
|
etcdErr "github.com/coreos/etcd/error"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
Permanent time.Time
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
normal = iota
|
normal = iota
|
||||||
removed
|
removed
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var Permanent time.Time
|
||||||
|
|
||||||
// Node is the basic element in the store system.
|
// Node is the basic element in the store system.
|
||||||
// A key-value pair will have a string value
|
// A key-value pair will have a string value
|
||||||
// A directory will have a children map
|
// A directory will have a children map
|
||||||
@ -97,7 +95,7 @@ func (n *Node) IsHidden() bool {
|
|||||||
|
|
||||||
// IsPermanent function checks if the node is a permanent one.
|
// IsPermanent function checks if the node is a permanent one.
|
||||||
func (n *Node) IsPermanent() bool {
|
func (n *Node) IsPermanent() bool {
|
||||||
return n.ExpireTime.Sub(Permanent) == 0
|
return !n.ExpireTime.IsZero()
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsExpired function checks if the node has been expired.
|
// IsExpired function checks if the node has been expired.
|
||||||
@ -146,7 +144,7 @@ func (n *Node) Write(value string, index uint64, term uint64) *etcdErr.Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) ExpirationAndTTL() (*time.Time, int64) {
|
func (n *Node) ExpirationAndTTL() (*time.Time, int64) {
|
||||||
if n.ExpireTime.Sub(Permanent) != 0 {
|
if n.IsPermanent() {
|
||||||
return &n.ExpireTime, int64(n.ExpireTime.Sub(time.Now())/time.Second) + 1
|
return &n.ExpireTime, int64(n.ExpireTime.Sub(time.Now())/time.Second) + 1
|
||||||
}
|
}
|
||||||
return nil, 0
|
return nil, 0
|
||||||
@ -376,7 +374,7 @@ func (n *Node) UpdateTTL(expireTime time.Time) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
n.ExpireTime = expireTime
|
n.ExpireTime = expireTime
|
||||||
if expireTime.Sub(Permanent) != 0 {
|
if !n.IsPermanent() {
|
||||||
n.Expire()
|
n.Expire()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ type Store interface {
|
|||||||
type store struct {
|
type store struct {
|
||||||
Root *Node
|
Root *Node
|
||||||
WatcherHub *watcherHub
|
WatcherHub *watcherHub
|
||||||
|
TTLKeyHeap *TTLKeyHeap
|
||||||
Index uint64
|
Index uint64
|
||||||
Term uint64
|
Term uint64
|
||||||
Stats *Stats
|
Stats *Stats
|
||||||
@ -54,6 +55,7 @@ func newStore() *store {
|
|||||||
s.Root = newDir(s, "/", UndefIndex, UndefTerm, nil, "", Permanent)
|
s.Root = newDir(s, "/", UndefIndex, UndefTerm, nil, "", Permanent)
|
||||||
s.Stats = newStats()
|
s.Stats = newStats()
|
||||||
s.WatcherHub = newWatchHub(1000)
|
s.WatcherHub = newWatchHub(1000)
|
||||||
|
s.TTLKeyHeap = newTTLKeyHeap()
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -390,7 +392,7 @@ func (s *store) internalCreate(nodePath string, value string, unique bool, repla
|
|||||||
d.Add(n)
|
d.Add(n)
|
||||||
|
|
||||||
// Node with TTL
|
// Node with TTL
|
||||||
if expireTime.Sub(Permanent) != 0 {
|
if !n.IsPermanent() {
|
||||||
n.Expire()
|
n.Expire()
|
||||||
e.Expiration, e.TTL = n.ExpirationAndTTL()
|
e.Expiration, e.TTL = n.ExpirationAndTTL()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user