etcdserver: do not send v2 sync if ttl keys do not exist

This commit is contained in:
Xiang Li 2016-12-07 10:17:04 -08:00
parent da3b71b531
commit 2f96a68a20
3 changed files with 18 additions and 1 deletions

View File

@ -733,7 +733,9 @@ func (s *EtcdServer) run() {
plog.Infof("the data-dir used by this member must be removed.")
return
case <-getSyncC():
s.sync(s.Cfg.ReqTimeout())
if s.store.HasTTLKeys() {
s.sync(s.Cfg.ReqTimeout())
}
case <-s.stop:
return
}

View File

@ -127,6 +127,13 @@ func (s *storeRecorder) DeleteExpiredKeys(cutoff time.Time) {
})
}
func (s *storeRecorder) HasTTLKeys() bool {
s.Record(testutil.Action{
Name: "HasTTLKeys",
})
return true
}
// errStoreRecorder is a storeRecorder, but returns the given error on
// Get, Watch methods.
type errStoreRecorder struct {

View File

@ -61,6 +61,8 @@ type Store interface {
JsonStats() []byte
DeleteExpiredKeys(cutoff time.Time)
HasTTLKeys() bool
}
type TTLOptionSet struct {
@ -778,3 +780,9 @@ func (s *store) JsonStats() []byte {
s.Stats.Watchers = uint64(s.WatcherHub.count)
return s.Stats.toJson()
}
func (s *store) HasTTLKeys() bool {
s.worldLock.RLock()
defer s.worldLock.RUnlock()
return s.ttlKeyHeap.Len() != 0
}