@@ -112,7 +112,7 @@ type Conductor struct {
112112 partitionPendingBytes []int64
113113 pausedPartitions []bool
114114 pausedCount int
115- pendingDMLBytes int64
115+ queuedDMLBytes int64
116116 partitionPauseBytes int64
117117 partitionResumeBytes int64
118118 watermark uint64
@@ -134,7 +134,11 @@ type Conductor struct {
134134// pending-DML assembly.
135135func New (reader source.Reader , schemas * codecCommon.TableInfoProvider , decoder * decode.Group ) * Conductor {
136136 partitions := reader .Partitions ()
137- pauseBytes , resumeBytes := partitionBufferLimits (partitions )
137+ var pauseBytes , resumeBytes int64
138+ if partitions > 1 {
139+ pauseBytes = min (maxPartitionPauseBytes , max (minPartitionPauseBytes , maxTotalPendingBytes / int64 (partitions )))
140+ resumeBytes = pauseBytes / 2
141+ }
138142 c := & Conductor {
139143 schemas : schemas ,
140144 decoder : decoder ,
@@ -240,7 +244,7 @@ func (c *Conductor) logProgress(w *writer.Writer, inBytes int64, lastLogTime *ti
240244 zap .Uint64 ("effectiveWatermark" , c .effectiveWatermark ()),
241245 zap .Uint64 ("checkpoint" , checkpoint ),
242246 zap .Int ("pendingDMLTables" , len (c .pendingDML )),
243- zap .Int64 ("pendingDMLBytes " , c .pendingDMLBytes ),
247+ zap .Int64 ("queuedDMLBytes " , c .queuedDMLBytes ),
244248 zap .Int ("pendingDDL" , len (c .pendingDDL )),
245249 zap .Int ("pendingDecode" , c .waitingCount ),
246250 }
@@ -299,12 +303,7 @@ func (c *Conductor) acceptPending(items []*simple.PendingMessage, payload *sourc
299303 var (
300304 marker uint64
301305 perItemBytes int64
302- offset int64
303306 )
304- partition := payloadPartition (payload )
305- if payload != nil {
306- offset = payload .Offset
307- }
308307 if len (items ) > 0 {
309308 perItemBytes = max (payloadBytes / int64 (len (items )), dmlEventOverheadBytes )
310309 }
@@ -315,7 +314,7 @@ func (c *Conductor) acceptPending(items []*simple.PendingMessage, payload *sourc
315314 marker = max (marker , pending .CommitTs )
316315
317316 if tableInfo := c .schemas .Read (pending .Schema , pending .Table , pending .SchemaVersion ); tableInfo != nil {
318- c .queueDML (c .decoder .DecodePending (pending , tableInfo , partition , offset ), partition )
317+ c .queueDML (c .decoder .DecodePending (pending , tableInfo , payload . Partition , payload . Offset ), payload . Partition )
319318 continue
320319 }
321320
@@ -326,11 +325,11 @@ func (c *Conductor) acceptPending(items []*simple.PendingMessage, payload *sourc
326325 }
327326 c .waiting [key ] = append (c .waiting [key ], waitingDML {
328327 pending : pending ,
329- partition : partition ,
330- offset : offset ,
328+ partition : payload . Partition ,
329+ offset : payload . Offset ,
331330 bytes : perItemBytes ,
332331 })
333- c .addPartitionBytes (partition , perItemBytes )
332+ c .addPartitionBytes (payload . Partition , perItemBytes )
334333 c .waitingCount ++
335334 if pending .CommitTs != 0 && (c .minWaitingTs == 0 || pending .CommitTs < c .minWaitingTs ) {
336335 c .minWaitingTs = pending .CommitTs
@@ -379,10 +378,10 @@ func (c *Conductor) recomputeMinWaiting() {
379378func (c * Conductor ) acceptEvent (e event.Event , payload * source.Payload ) uint64 {
380379 switch e := e .(type ) {
381380 case * event.DMLEvent :
382- c .queueDML (e , payloadPartition ( payload ) )
381+ c .queueDML (e , payload . Partition )
383382 return e .CommitTs
384383 case * event.ResolvedEvent :
385- c .advanceWatermark (e .ResolvedTs , payloadPartition ( payload ) )
384+ c .advanceWatermark (e .ResolvedTs , payload . Partition )
386385 case * event.DDLEvent :
387386 c .wakeWaiting (e .TableInfo )
388387 for _ , info := range e .MultipleTableInfos {
@@ -550,7 +549,7 @@ func (c *Conductor) syncTable(q *tableQueue) {
550549// queueDML records a decoded row until the writer can accept it.
551550func (c * Conductor ) queueDML (item * event.DMLEvent , partition int32 ) {
552551 bytes := dmlMemoryBytes (item )
553- c .pendingDMLBytes += bytes
552+ c .queuedDMLBytes += bytes
554553 c .addPartitionBytes (partition , bytes )
555554
556555 entry := queuedDML {
@@ -642,7 +641,7 @@ func (c *Conductor) popDML(row *event.DMLEvent) {
642641 q .rows [0 ] = queuedDML {}
643642 q .rows = q .rows [1 :]
644643 q .dropped ++
645- c .pendingDMLBytes -= entry .bytes
644+ c .queuedDMLBytes -= entry .bytes
646645 c .subPartitionBytes (entry .partition , entry .bytes )
647646
648647 if len (q .rows ) == 0 {
@@ -770,7 +769,7 @@ func (c *Conductor) advanceWatermark(ts uint64, partition int32) {
770769 return
771770 }
772771
773- if partition < 0 || int (partition ) >= len (c .partitionWatermarks ) {
772+ if int (partition ) >= len (c .partitionWatermarks ) {
774773 return
775774 }
776775
@@ -802,39 +801,20 @@ func (c *Conductor) advanceWriter(w *writer.Writer) {
802801 w .Advance (c .effectiveWatermark (), pending )
803802}
804803
805- func partitionBufferLimits (partitions int32 ) (pauseBytes , resumeBytes int64 ) {
806- if partitions <= 1 {
807- return maxPartitionPauseBytes , maxPartitionPauseBytes / 2
808- }
809- pauseBytes = min (maxPartitionPauseBytes , max (minPartitionPauseBytes , maxTotalPendingBytes / int64 (partitions )))
810- return pauseBytes , pauseBytes / 2
811- }
812-
813- func payloadPartition (payload * source.Payload ) int32 {
814- if payload == nil {
815- return - 1
816- }
817- return payload .Partition
818- }
819-
820804func dmlMemoryBytes (item * event.DMLEvent ) int64 {
821- if item == nil || item .Rows == nil {
822- return dmlEventOverheadBytes
823- }
824805 return dmlEventOverheadBytes + item .Rows .MemoryUsage ()
825806}
826807
827808func (c * Conductor ) addPartitionBytes (partition int32 , bytes int64 ) {
828- if partition >= 0 && int (partition ) < len (c .partitionPendingBytes ) {
809+ if int (partition ) < len (c .partitionPendingBytes ) {
829810 c .partitionPendingBytes [partition ] += bytes
830811 }
831812}
832813
833814func (c * Conductor ) subPartitionBytes (partition int32 , bytes int64 ) {
834- if partition < 0 || int (partition ) >= len (c .partitionPendingBytes ) {
835- return
815+ if int (partition ) < len (c .partitionPendingBytes ) {
816+ c . partitionPendingBytes [ partition ] -= bytes
836817 }
837- c .partitionPendingBytes [partition ] = max (0 , c .partitionPendingBytes [partition ]- bytes )
838818}
839819
840820// syncPartitionPacing pauses partitions whose resolved progress leads the slowest
0 commit comments