Skip to content

Commit

Permalink
Merge pull request #14290 from ahrtr/3.4_no_prevkv_for_create
Browse files Browse the repository at this point in the history
[3.4] Do not get previous K/V for create event
  • Loading branch information
spzala authored Aug 1, 2022
2 parents 314dcbf + 095bbfc commit ee36615
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion etcdserver/api/v3rpc/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,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(evs[i].Kv.Key, nil, opt)
if err == nil && len(r.KVs) != 0 {
Expand Down Expand Up @@ -534,6 +534,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
2 changes: 1 addition & 1 deletion test
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ function govet_shadow_pass {
# shellcheck disable=SC2206
fmtpkgs=($fmtpkgs)
# Golang 1.12 onwards the experimental -shadow option is no longer available with go vet
go get golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
go get golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@v0.1.11
export PATH=${GOPATH}/bin:${PATH}
# shellcheck disable=SC2230
shadow_tool=$(which shadow)
Expand Down

0 comments on commit ee36615

Please sign in to comment.