Skip to content

Commit

Permalink
Merge pull request #131328 from cockroachdb/blathers/backport-release…
Browse files Browse the repository at this point in the history
…-24.1-131220

release-24.1: storage: set correct key in WriteTooOld error from pebbleMVCCScanner
  • Loading branch information
nvanbenschoten authored Oct 14, 2024
2 parents 30f99a9 + c294f5e commit 578d876
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
13 changes: 5 additions & 8 deletions pkg/storage/pebble_mvcc_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,9 +845,8 @@ func (p *pebbleMVCCScanner) getOne(ctx context.Context) (ok, added bool) {
// timestamp with the maximum timestamp we've seen so we know to
// return an error, but then keep scanning so that we can return
// the largest possible time.
p.mostRecentTS.Forward(p.curUnsafeKey.Timestamp)
if len(p.mostRecentKey) == 0 {
p.mostRecentKey = append(p.mostRecentKey, p.curUnsafeKey.Key...)
if p.mostRecentTS.Forward(p.curUnsafeKey.Timestamp) {
p.mostRecentKey = append(p.mostRecentKey[:0], p.curUnsafeKey.Key...)
}
return true /* ok */, false
}
Expand Down Expand Up @@ -878,9 +877,8 @@ func (p *pebbleMVCCScanner) getOne(ctx context.Context) (ok, added bool) {
// timestamp with the maximum timestamp we've seen so we know to
// return an error, but then keep scanning so that we can return
// the largest possible time.
p.mostRecentTS.Forward(p.curUnsafeKey.Timestamp)
if len(p.mostRecentKey) == 0 {
p.mostRecentKey = append(p.mostRecentKey, p.curUnsafeKey.Key...)
if p.mostRecentTS.Forward(p.curUnsafeKey.Timestamp) {
p.mostRecentKey = append(p.mostRecentKey[:0], p.curUnsafeKey.Key...)
}
return true /* ok */, false
}
Expand Down Expand Up @@ -1516,8 +1514,7 @@ func (p *pebbleMVCCScanner) processRangeKeys(seeked bool, reverse bool) bool {
if p.failOnMoreRecent {
if key := p.parent.UnsafeKey(); !hasPoint || !key.Timestamp.IsEmpty() {
if newest := p.curRangeKeys.Newest(); p.ts.LessEq(newest) {
p.mostRecentTS.Forward(newest)
if len(p.mostRecentKey) == 0 {
if p.mostRecentTS.Forward(newest) {
p.mostRecentKey = append(p.mostRecentKey[:0], key.Key...)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/testdata/mvcc_histories/range_tombstone_scans
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ run error
scan k=a end=d ts=3 failOnMoreRecent
----
scan: "a"-"d" -> <no data>
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "a" at timestamp 3.000000000,0 too old; must write at or above 4.000000000,1
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "c" at timestamp 3.000000000,0 too old; must write at or above 4.000000000,1

run error
scan k=a end=d ts=4 failOnMoreRecent
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/testdata/mvcc_histories/read_fail_on_more_recent
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,13 @@ run error
scan k=a end=b_next ts=9,0 failOnMoreRecent
----
scan: "a"-"b_next" -> <no data>
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "a" at timestamp 9.000000000,0 too old; must write at or above 13.000000000,1
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "b" at timestamp 9.000000000,0 too old; must write at or above 13.000000000,1

run error
scan k=a end=c_next ts=9,0 failOnMoreRecent
----
scan: "a"-"c_next" -> <no data>
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "a" at timestamp 9.000000000,0 too old; must write at or above 13.000000000,1
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "b" at timestamp 9.000000000,0 too old; must write at or above 13.000000000,1

run error
scan k=b end=c_next ts=9,0 failOnMoreRecent
Expand Down
20 changes: 10 additions & 10 deletions pkg/storage/testdata/mvcc_histories/skip_locked
Original file line number Diff line number Diff line change
Expand Up @@ -764,13 +764,13 @@ run error
scan ts=10 k=k1 end=k9 skipLocked failOnMoreRecent str=shared
----
scan: "k1"-"k9" -> <no data>
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "k1" at timestamp 10.000000000,0 too old; must write at or above 17.000000000,1
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "k5" at timestamp 10.000000000,0 too old; must write at or above 17.000000000,1

run error
scan ts=10 k=k1 end=k9 reverse skipLocked failOnMoreRecent str=shared
----
scan: "k1"-"k9" -> <no data>
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "k6" at timestamp 10.000000000,0 too old; must write at or above 17.000000000,1
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "k5" at timestamp 10.000000000,0 too old; must write at or above 17.000000000,1

run error
get ts=11 k=k1 skipLocked failOnMoreRecent str=shared
Expand Down Expand Up @@ -812,13 +812,13 @@ run error
scan ts=11 k=k1 end=k9 skipLocked failOnMoreRecent str=shared
----
scan: "k1"-"k9" -> <no data>
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "k1" at timestamp 11.000000000,0 too old; must write at or above 17.000000000,1
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "k5" at timestamp 11.000000000,0 too old; must write at or above 17.000000000,1

run error
scan ts=11 k=k1 end=k9 reverse skipLocked failOnMoreRecent str=shared
----
scan: "k1"-"k9" -> <no data>
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "k6" at timestamp 11.000000000,0 too old; must write at or above 17.000000000,1
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "k5" at timestamp 11.000000000,0 too old; must write at or above 17.000000000,1

run ok
get ts=12 k=k1 skipLocked failOnMoreRecent str=shared
Expand Down Expand Up @@ -865,7 +865,7 @@ run error
scan ts=12 k=k1 end=k9 reverse skipLocked failOnMoreRecent str=shared
----
scan: "k1"-"k9" -> <no data>
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "k6" at timestamp 12.000000000,0 too old; must write at or above 17.000000000,1
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "k5" at timestamp 12.000000000,0 too old; must write at or above 17.000000000,1

run ok
get ts=12 t=A k=k1 skipLocked failOnMoreRecent str=shared
Expand Down Expand Up @@ -912,7 +912,7 @@ run error
scan ts=12 t=A k=k1 end=k9 reverse skipLocked failOnMoreRecent str=shared
----
scan: "k1"-"k9" -> <no data>
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "k6" at timestamp 12.000000000,0 too old; must write at or above 17.000000000,1
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "k5" at timestamp 12.000000000,0 too old; must write at or above 17.000000000,1

run ok
get ts=13 k=k1 skipLocked failOnMoreRecent str=shared
Expand Down Expand Up @@ -959,7 +959,7 @@ run error
scan ts=13 k=k1 end=k9 reverse skipLocked failOnMoreRecent str=shared
----
scan: "k1"-"k9" -> <no data>
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "k6" at timestamp 13.000000000,0 too old; must write at or above 17.000000000,1
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "k5" at timestamp 13.000000000,0 too old; must write at or above 17.000000000,1

run ok
get ts=13 t=B k=k1 skipLocked failOnMoreRecent str=shared
Expand Down Expand Up @@ -1005,7 +1005,7 @@ run error
scan ts=13 t=B k=k1 end=k9 reverse skipLocked failOnMoreRecent str=shared
----
scan: "k1"-"k9" -> <no data>
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "k6" at timestamp 13.000000000,0 too old; must write at or above 17.000000000,1
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "k5" at timestamp 13.000000000,0 too old; must write at or above 17.000000000,1

run ok
get ts=14 k=k1 skipLocked failOnMoreRecent str=shared
Expand Down Expand Up @@ -1424,7 +1424,7 @@ run error
scan ts=10 k=k1 end=k9 skipLocked failOnMoreRecent str=exclusive
----
scan: "k1"-"k9" -> <no data>
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "k1" at timestamp 10.000000000,0 too old; must write at or above 17.000000000,1
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "k5" at timestamp 10.000000000,0 too old; must write at or above 17.000000000,1

run error
scan ts=10 k=k1 end=k9 reverse skipLocked failOnMoreRecent str=exclusive
Expand Down Expand Up @@ -1472,7 +1472,7 @@ run error
scan ts=11 k=k1 end=k9 skipLocked failOnMoreRecent str=exclusive
----
scan: "k1"-"k9" -> <no data>
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "k1" at timestamp 11.000000000,0 too old; must write at or above 17.000000000,1
error: (*kvpb.WriteTooOldError:) WriteTooOldError: write for key "k5" at timestamp 11.000000000,0 too old; must write at or above 17.000000000,1

run error
scan ts=11 k=k1 end=k9 reverse skipLocked failOnMoreRecent str=exclusive
Expand Down

0 comments on commit 578d876

Please sign in to comment.