@@ -31,7 +31,9 @@ type Event interface {
31
31
GetDispatcherID () DispatcherID
32
32
GetCommitTs () Ts
33
33
GetStartTs () Ts
34
- GetChunkSize () int64
34
+ // GetSize returns the approximate size of the event in bytes.
35
+ // It's used for memory control and monitoring.
36
+ GetSize () int64
35
37
}
36
38
37
39
// FlushableEvent is an event that can be flushed to downstream by a dispatcher.
@@ -109,7 +111,8 @@ func (b *BatchResolvedEvent) Unmarshal(data []byte) error {
109
111
return nil
110
112
}
111
113
112
- func (b * BatchResolvedEvent ) GetChunkSize () int64 {
114
+ // No one will use this method, just for implementing Event interface.
115
+ func (b * BatchResolvedEvent ) GetSize () int64 {
113
116
return 0
114
117
}
115
118
@@ -155,7 +158,8 @@ func (e ResolvedEvent) String() string {
155
158
return fmt .Sprintf ("ResolvedEvent{DispatcherID: %s, ResolvedTs: %d}" , e .DispatcherID , e .ResolvedTs )
156
159
}
157
160
158
- func (e ResolvedEvent ) GetChunkSize () int64 {
161
+ // No one will use this method, just for implementing Event interface.
162
+ func (e ResolvedEvent ) GetSize () int64 {
159
163
return 0
160
164
}
161
165
@@ -170,9 +174,10 @@ type DMLEvent struct {
170
174
Offset int `json:"offset"`
171
175
len int
172
176
173
- TableInfo * TableInfo `json:"table_info"`
174
- Rows * chunk.Chunk `json:"rows"`
175
- RowTypes []RowType `json:"row_types"`
177
+ TableInfo * TableInfo `json:"table_info"`
178
+ Rows * chunk.Chunk `json:"rows"`
179
+ RowTypes []RowType `json:"row_types"`
180
+ ApproximateSize int64 `json:"approximate_size"`
176
181
177
182
// The following fields are set and used by dispatcher.
178
183
ReplicatingTs uint64 `json:"replicating_ts"`
@@ -221,6 +226,7 @@ func (t *DMLEvent) AppendRow(raw *RawKVEntry,
221
226
t .RowTypes = append (t .RowTypes , RowType , RowType )
222
227
}
223
228
t .len += 1
229
+ t .ApproximateSize += int64 (len (raw .Key ) + len (raw .Value ) + len (raw .OldValue ))
224
230
return nil
225
231
}
226
232
@@ -250,28 +256,28 @@ func (t *DMLEvent) AddPostFlushFunc(f func()) {
250
256
t .PostTxnFlushed = append (t .PostTxnFlushed , f )
251
257
}
252
258
253
- func (t * DMLEvent ) GetNextRow () (RowDelta , bool ) {
259
+ func (t * DMLEvent ) GetNextRow () (RowChange , bool ) {
254
260
if t .Offset >= len (t .RowTypes ) {
255
- return RowDelta {}, false
261
+ return RowChange {}, false
256
262
}
257
263
rowType := t .RowTypes [t .Offset ]
258
264
switch rowType {
259
265
case RowTypeInsert :
260
- row := RowDelta {
266
+ row := RowChange {
261
267
Row : t .Rows .GetRow (t .Offset ),
262
268
RowType : rowType ,
263
269
}
264
270
t .Offset ++
265
271
return row , true
266
272
case RowTypeDelete :
267
- row := RowDelta {
273
+ row := RowChange {
268
274
PreRow : t .Rows .GetRow (t .Offset ),
269
275
RowType : rowType ,
270
276
}
271
277
t .Offset ++
272
278
return row , true
273
279
case RowTypeUpdate :
274
- row := RowDelta {
280
+ row := RowChange {
275
281
PreRow : t .Rows .GetRow (t .Offset ),
276
282
Row : t .Rows .GetRow (t .Offset + 1 ),
277
283
RowType : rowType ,
@@ -281,7 +287,7 @@ func (t *DMLEvent) GetNextRow() (RowDelta, bool) {
281
287
default :
282
288
log .Panic ("TEvent.GetNextRow: invalid row type" )
283
289
}
284
- return RowDelta {}, false
290
+ return RowChange {}, false
285
291
}
286
292
287
293
// Len returns the number of row change events in the transaction.
@@ -303,11 +309,11 @@ func (t *DMLEvent) Unmarshal(data []byte) error {
303
309
return nil
304
310
}
305
311
306
- func (t * DMLEvent ) GetChunkSize () int64 {
307
- return t .Rows . MemoryUsage ()
312
+ func (t * DMLEvent ) GetSize () int64 {
313
+ return t .ApproximateSize
308
314
}
309
315
310
- type RowDelta struct {
316
+ type RowChange struct {
311
317
PreRow chunk.Row
312
318
Row chunk.Row
313
319
RowType RowType
@@ -454,7 +460,7 @@ func (t *DDLEvent) Unmarshal(data []byte) error {
454
460
}
455
461
456
462
// TODO: fix it
457
- func (t * DDLEvent ) GetChunkSize () int64 {
463
+ func (t * DDLEvent ) GetSize () int64 {
458
464
return 0
459
465
}
460
466
0 commit comments