@@ -675,13 +675,25 @@ func (twb *txnWriteBuffer) applyTransformations(
675
675
var ts transformations
676
676
for i , ru := range ba .Requests {
677
677
req := ru .GetInner ()
678
+ // Track a transformation for the request regardless of the type, and
679
+ // regardless of whether it was served from the buffer or not. For truly
680
+ // transformed requests (e.g. CPut) this is expected. For Gets and Scans, we
681
+ // need to track a transformation because we haven't buffered any writes
682
+ // from our current batch in the buffer yet, so checking the buffer here, at
683
+ // request time, isn't sufficient to determine whether the request needs to
684
+ // serve a read from the buffer before returning a response or not.
685
+ //
686
+ // Only QueryLocksRequest and LeaseInfoRequest don't require a tracking
687
+ // transformation, but it's harmless to add one, and it simplifies the code.
688
+ //
689
+ // The stripped field will be set below for specific stripped requests.
690
+ tr := transformation {
691
+ stripped : false ,
692
+ index : i ,
693
+ origRequest : req ,
694
+ }
678
695
switch t := req .(type ) {
679
696
case * kvpb.ConditionalPutRequest :
680
- ts = append (ts , transformation {
681
- stripped : false ,
682
- index : i ,
683
- origRequest : req ,
684
- })
685
697
// NB: Regardless of whether there is already a buffered write on
686
698
// this key or not, we need to send a locking Get to the KV layer to
687
699
// acquire a lock. However, if we had knowledge of what locks the
@@ -720,11 +732,7 @@ func (twb *txnWriteBuffer) applyTransformations(
720
732
})
721
733
baRemote .Requests = append (baRemote .Requests , getReqU )
722
734
}
723
- ts = append (ts , transformation {
724
- stripped : ! t .MustAcquireExclusiveLock ,
725
- index : i ,
726
- origRequest : req ,
727
- })
735
+ tr .stripped = ! t .MustAcquireExclusiveLock
728
736
729
737
case * kvpb.DeleteRequest :
730
738
// If MustAcquireExclusiveLock flag is set on the DeleteRequest,
@@ -744,11 +752,7 @@ func (twb *txnWriteBuffer) applyTransformations(
744
752
})
745
753
baRemote .Requests = append (baRemote .Requests , getReqU )
746
754
}
747
- ts = append (ts , transformation {
748
- stripped : ! t .MustAcquireExclusiveLock ,
749
- index : i ,
750
- origRequest : req ,
751
- })
755
+ tr .stripped = ! t .MustAcquireExclusiveLock
752
756
753
757
case * kvpb.GetRequest :
754
758
// If the key is in the buffer, we must serve the read from the buffer.
@@ -779,45 +783,14 @@ func (twb *txnWriteBuffer) applyTransformations(
779
783
// Wasn't served locally; send the request to the KV layer.
780
784
baRemote .Requests = append (baRemote .Requests , ru )
781
785
}
782
- // Even if the request wasn't served from the buffer here, we still track
783
- // a transformation for it. That's because we haven't buffered any writes
784
- // from our current batch in the buffer yet, so checking the buffer above
785
- // isn't sufficient to determine whether the request needs to serve a read
786
- // from the buffer before returning a response or not.
787
- ts = append (ts , transformation {
788
- stripped : stripped ,
789
- index : i ,
790
- origRequest : req ,
791
- })
786
+ tr .stripped = stripped
792
787
793
- case * kvpb.ScanRequest :
794
- overlaps := twb .scanOverlaps (t .Key , t .EndKey )
795
- if overlaps {
796
- ts = append (ts , transformation {
797
- stripped : false ,
798
- index : i ,
799
- origRequest : req ,
800
- })
801
- }
788
+ case * kvpb.ScanRequest , * kvpb.ReverseScanRequest :
802
789
// Regardless of whether the scan overlaps with any writes in the buffer
803
790
// or not, we must send the request to the KV layer. We can't know for
804
791
// sure that there's nothing else to read.
805
792
baRemote .Requests = append (baRemote .Requests , ru )
806
793
807
- case * kvpb.ReverseScanRequest :
808
- overlaps := twb .scanOverlaps (t .Key , t .EndKey )
809
- if overlaps {
810
- ts = append (ts , transformation {
811
- stripped : false ,
812
- index : i ,
813
- origRequest : req ,
814
- })
815
- }
816
- // Similar to the reasoning above, regardless of whether the reverse
817
- // scan overlaps with any writes in the buffer or not, we must send
818
- // the request to the KV layer.
819
- baRemote .Requests = append (baRemote .Requests , ru )
820
-
821
794
case * kvpb.QueryLocksRequest , * kvpb.LeaseInfoRequest :
822
795
// These requests don't interact with buffered writes, so we simply
823
796
// let them through.
@@ -826,6 +799,7 @@ func (twb *txnWriteBuffer) applyTransformations(
826
799
default :
827
800
return nil , nil , kvpb .NewError (unsupportedMethodError (t .Method ()))
828
801
}
802
+ ts = append (ts , tr )
829
803
}
830
804
return baRemote , ts , nil
831
805
}
0 commit comments