Skip to content

Commit 4fe5b55

Browse files
craig[bot]stevendanna
andcommitted
Merge #154021
154021: kvnemesis: expect nil bytes in CPuts r=miraradeva a=stevendanna A CPut that expects a non-existent key needs to set a nil expected bytes. MakeValueFromBytes will return a non-nil byte slice (containing the BYTES type tag) if given a nil byte slice. Epic: none Release note: None Co-authored-by: Steven Danna <[email protected]>
2 parents 0eccabf + 0a5e83d commit 4fe5b55

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

pkg/kv/kvnemesis/applier.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,14 @@ func applyClientOp(
349349
o.Result.OptionalTimestamp = ts
350350
case *CPutOperation:
351351
_, ts, err := dbRunWithResultAndTimestamp(ctx, db, func(b *kv.Batch) {
352-
expVal := roachpb.MakeValueFromBytes(o.ExpVal)
352+
var expBytes []byte
353+
if o.ExpVal != nil {
354+
expBytes = roachpb.MakeValueFromBytes(o.ExpVal).TagAndDataBytes()
355+
}
353356
if o.AllowIfDoesNotExist {
354-
b.CPutAllowingIfNotExists(o.Key, o.Value(), expVal.TagAndDataBytes())
357+
b.CPutAllowingIfNotExists(o.Key, o.Value(), expBytes)
355358
} else {
356-
b.CPut(o.Key, o.Value(), expVal.TagAndDataBytes())
359+
b.CPut(o.Key, o.Value(), expBytes)
357360
}
358361
setLastReqSeq(b, o.Seq)
359362
})

pkg/kv/kvnemesis/validator.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,11 +499,11 @@ func (v *validator) processOp(op Operation) {
499499
if e := (*kvpb.ConditionFailedError)(nil); errors.As(err, &e) {
500500
// If the CPut failed, the actual value (in the ConditionFailedError) is
501501
// observed, and the CPut's write is not observed.
502+
observedVal := roachpb.Value{}
502503
if e.ActualValue != nil {
503-
if valueBytes, err := e.ActualValue.GetBytes(); err == nil {
504-
readObservation.Value = roachpb.MakeValueFromBytes(valueBytes)
505-
}
504+
observedVal.RawBytes = e.ActualValue.RawBytes
506505
}
506+
readObservation.Value = observedVal
507507
v.curObservations = append(v.curObservations, readObservation)
508508
} else {
509509
// If the CPut succeeded, the expected value is observed, and the CPut's
@@ -512,7 +512,11 @@ func (v *validator) processOp(op Operation) {
512512
// If AllowIfDoesNotExist == true, we don't know if the read found the
513513
// expected value or no value, so we can't add a read observation.
514514
// Otherwise, it must have observed the expected value.
515-
readObservation.Value = roachpb.MakeValueFromBytes(t.ExpVal)
515+
observedVal := roachpb.Value{}
516+
if t.ExpVal != nil {
517+
observedVal = roachpb.MakeValueFromBytes(t.ExpVal)
518+
}
519+
readObservation.Value = observedVal
516520
v.curObservations = append(v.curObservations, readObservation)
517521
}
518522
if sv, ok := v.tryConsumeWrite(t.Key, t.Seq); ok {

0 commit comments

Comments
 (0)