Skip to content

Commit

Permalink
Merge pull request #12739 from LeoYang90/optimization_watch_prevkv
Browse files Browse the repository at this point in the history
create event do not need prevkv range
  • Loading branch information
gyuho authored Mar 10, 2021
2 parents 633e927 + d70f35f commit 3ead91c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion server/etcdserver/api/v3rpc/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func (sws *serverWatchStream) sendLoop() {
sws.mu.RUnlock()
for i := range evs {
events[i] = &evs[i]
if needPrevKV {
if needPrevKV && !IsCreateEvent(evs[i]) {
opt := mvcc.RangeOptions{Rev: evs[i].Kv.ModRevision - 1}
r, err := sws.watchable.Range(context.TODO(), evs[i].Kv.Key, nil, opt)
if err == nil && len(r.KVs) != 0 {
Expand Down Expand Up @@ -501,6 +501,10 @@ func (sws *serverWatchStream) sendLoop() {
}
}

func IsCreateEvent(e mvccpb.Event) bool {
return e.Type == mvccpb.PUT && e.Kv.CreateRevision == e.Kv.ModRevision
}

func sendFragments(
wr *pb.WatchResponse,
maxRequestBytes int,
Expand Down

0 comments on commit 3ead91c

Please sign in to comment.