Merge pull request #14290 from ahrtr/3.4_no_prevkv_for_create

[3.4] Do not get previous K/V for create event
This commit is contained in:
Sahdev Zala 2022-08-01 08:39:19 -04:00 committed by GitHub
commit ee366151c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -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 {
@ -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,

2
test
View File

@ -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)