Skip to content

Commit

Permalink
etcdserver: do not send v2 sync if ttl keys do not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
xiang90 committed Dec 7, 2016
1 parent da3b71b commit 2f96a68
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/mock/mockstore/store_recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ type Store interface {

JsonStats() []byte
DeleteExpiredKeys(cutoff time.Time)

HasTTLKeys() bool
}

type TTLOptionSet struct {
Expand Down Expand Up @@ -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
}

0 comments on commit 2f96a68

Please sign in to comment.