Skip to content
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

RFC: etcdserver, pkg: skip needless log entry applying #5689

Merged
merged 1 commit into from
Jul 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions etcdserver/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,3 +784,7 @@ func compareInt64(a, b int64) int {
func isGteRange(rangeEnd []byte) bool {
return len(rangeEnd) == 1 && rangeEnd[0] == 0
}

func noSideEffect(r *pb.InternalRaftRequest) bool {
return r.Range != nil || r.AuthUserGet != nil || r.AuthRoleGet != nil
}
10 changes: 9 additions & 1 deletion etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1082,8 +1082,16 @@ func (s *EtcdServer) applyEntryNormal(e *raftpb.Entry) {
id = raftReq.Header.ID
}

ar := s.applyV3.Apply(&raftReq)
var ar *applyResult
if s.w.IsRegistered(id) || !noSideEffect(&raftReq) {
ar = s.applyV3.Apply(&raftReq)
}
s.setAppliedIndex(e.Index)

if ar == nil {
return
}

if ar.err != ErrNoSpace || len(s.alarmStore.Get(pb.AlarmType_NOSPACE)) > 0 {
s.w.Trigger(id, ar)
return
Expand Down
4 changes: 4 additions & 0 deletions pkg/mock/mockwait/wait_recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ func (w *waitRecorder) Register(id uint64) <-chan interface{} {
func (w *waitRecorder) Trigger(id uint64, x interface{}) {
w.Record(testutil.Action{Name: "Trigger"})
}

func (w *waitRecorder) IsRegistered(id uint64) bool {
panic("waitRecorder.IsRegistered() shouldn't be called")
}
11 changes: 11 additions & 0 deletions pkg/wait/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
type Wait interface {
Register(id uint64) <-chan interface{}
Trigger(id uint64, x interface{})
IsRegistered(id uint64) bool
}

type List struct {
Expand Down Expand Up @@ -59,6 +60,13 @@ func (w *List) Trigger(id uint64, x interface{}) {
}
}

func (w *List) IsRegistered(id uint64) bool {
w.l.Lock()
defer w.l.Unlock()
_, ok := w.m[id]
return ok
}

type waitWithResponse struct {
ch <-chan interface{}
}
Expand All @@ -71,3 +79,6 @@ func (w *waitWithResponse) Register(id uint64) <-chan interface{} {
return w.ch
}
func (w *waitWithResponse) Trigger(id uint64, x interface{}) {}
func (w *waitWithResponse) IsRegistered(id uint64) bool {
panic("waitWithResponse.IsRegistered() shouldn't be called")
}
23 changes: 23 additions & 0 deletions pkg/wait/wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,26 @@ func TestTriggerDupSuppression(t *testing.T) {
t.Errorf("unexpected non-nil value: %v (%T)", g, g)
}
}

func TestIsRegistered(t *testing.T) {
wt := New()

wt.Register(0)
wt.Register(1)
wt.Register(2)

for i := uint64(0); i < 3; i++ {
if !wt.IsRegistered(i) {
t.Errorf("event ID %d isn't registered", i)
}
}

if wt.IsRegistered(4) {
t.Errorf("event ID 4 shouldn't be registered")
}

wt.Trigger(0, "foo")
if wt.IsRegistered(0) {
t.Errorf("event ID 0 is already triggered, shouldn't be registered")
}
}