@@ -97,9 +97,12 @@ type Sender struct {
9797type streamState struct {
9898 // lastSeqNum is the sequence number of the last message published.
9999 lastSeqNum ctpb.SeqNum
100- // lastClosed is the closed timestamp published for each policy in the
101- // last message.
102- lastClosed [roachpb .MAX_CLOSED_TIMESTAMP_POLICY ]hlc.Timestamp
100+ // lastClosed is the closed timestamp published for each policy in the last
101+ // message. During mixed version clusters with nodes running both v25.1 and
102+ // v25.2, lastClosed will only be populated for enums with a corresponding
103+ // roachpb.RangeClosedTimestampPolicy (LAG_BY_CLUSTER_SETTING and
104+ // LEAD_FOR_GLOBAL_READS) until the cluster is fully upgraded to v25.2.
105+ lastClosed map [ctpb.RangeClosedTimestampPolicy ]hlc.Timestamp
103106 // tracked maintains the information that was communicated to connections in
104107 // the last sent message (implicitly or explicitly). A range enters this
105108 // structure as soon as it's included in a message, and exits it when it's
@@ -151,7 +154,7 @@ type Replica interface {
151154 BumpSideTransportClosed (
152155 ctx context.Context ,
153156 now hlc.ClockTimestamp ,
154- targetByPolicy [ roachpb . MAX_CLOSED_TIMESTAMP_POLICY ]hlc.Timestamp ,
157+ targetByPolicy map [ctpb. RangeClosedTimestampPolicy ]hlc.Timestamp ,
155158 ) BumpSideTransportClosedResult
156159}
157160
@@ -210,6 +213,7 @@ func newSenderWithConnFactory(
210213 buf : newUpdatesBuf (),
211214 }
212215 s .trackedMu .tracked = make (map [roachpb.RangeID ]trackedRange )
216+ s .trackedMu .lastClosed = make (map [ctpb.RangeClosedTimestampPolicy ]hlc.Timestamp )
213217 s .leaseholdersMu .leaseholders = make (map [roachpb.RangeID ]leaseholder )
214218 s .connsMu .conns = make (map [roachpb.NodeID ]conn )
215219 return s
@@ -305,10 +309,14 @@ func (s *Sender) publish(ctx context.Context) hlc.ClockTimestamp {
305309 defer s .trackedMu .Unlock ()
306310 log .VEventf (ctx , 4 , "side-transport generating a new message" )
307311 s .trackedMu .closingFailures = [MaxReason ]int {}
308-
312+ // TODO(wenyihu6): a cluster version check is needed here once we add new
313+ // policies to ctpb.RangeClosedTimestampPolicies that do not have a
314+ // corresponding roachpb.RangeClosedTimestampPolicy.
315+ numPolicies := int (roachpb .MAX_CLOSED_TIMESTAMP_POLICY )
316+ s .trackedMu .lastClosed = make (map [ctpb.RangeClosedTimestampPolicy ]hlc.Timestamp , numPolicies )
309317 msg := & ctpb.Update {
310318 NodeID : s .nodeID ,
311- ClosedTimestamps : make ([]ctpb.Update_GroupUpdate , len ( s . trackedMu . lastClosed ) ),
319+ ClosedTimestamps : make ([]ctpb.Update_GroupUpdate , numPolicies ),
312320 }
313321
314322 // Determine the message's sequence number.
@@ -326,8 +334,7 @@ func (s *Sender) publish(ctx context.Context) hlc.ClockTimestamp {
326334 lagTargetDuration := closedts .TargetDuration .Get (& s .st .SV )
327335 leadTargetOverride := closedts .LeadForGlobalReadsOverride .Get (& s .st .SV )
328336 sideTransportCloseInterval := closedts .SideTransportCloseInterval .Get (& s .st .SV )
329- for i := range s .trackedMu .lastClosed {
330- pol := ctpb .RangeClosedTimestampPolicy (i )
337+ for pol := ctpb .RangeClosedTimestampPolicy (0 ); pol < ctpb .RangeClosedTimestampPolicy (numPolicies ); pol ++ {
331338 target := closedts .TargetForPolicy (
332339 now ,
333340 maxClockOffset ,
@@ -482,14 +489,14 @@ func (s *Sender) GetSnapshot() *ctpb.Update {
482489 // of incremental messages.
483490 SeqNum : s .trackedMu .lastSeqNum ,
484491 Snapshot : true ,
485- ClosedTimestamps : make ([]ctpb.Update_GroupUpdate , len (s .trackedMu .lastClosed )),
492+ ClosedTimestamps : make ([]ctpb.Update_GroupUpdate , 0 , len (s .trackedMu .lastClosed )),
486493 AddedOrUpdated : make ([]ctpb.Update_RangeUpdate , 0 , len (s .trackedMu .tracked )),
487494 }
488495 for pol , ts := range s .trackedMu .lastClosed {
489- msg .ClosedTimestamps [ pol ] = ctpb.Update_GroupUpdate {
490- Policy : ctpb . RangeClosedTimestampPolicy ( pol ) ,
496+ msg .ClosedTimestamps = append ( msg . ClosedTimestamps , ctpb.Update_GroupUpdate {
497+ Policy : pol ,
491498 ClosedTimestamp : ts ,
492- }
499+ })
493500 }
494501 for rid , r := range s .trackedMu .tracked {
495502 msg .AddedOrUpdated = append (msg .AddedOrUpdated , ctpb.Update_RangeUpdate {
@@ -886,7 +893,7 @@ func (s streamState) String() string {
886893 } else {
887894 agoMsg = fmt .Sprintf ("%s in the future" , - ago )
888895 }
889- fmt .Fprintf (sb , "%s:%s (%s)" , roachpb . RangeClosedTimestampPolicy ( policy ) , closedTS , agoMsg )
896+ fmt .Fprintf (sb , "%s:%s (%s)" , policy , closedTS , agoMsg )
890897 }
891898
892899 // List the tracked ranges.
0 commit comments