github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cdc/sink/dmlsink/event.go (about) 1 // Copyright 2022 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package dmlsink 15 16 import ( 17 "github.com/pingcap/tiflow/cdc/model" 18 "github.com/pingcap/tiflow/cdc/sink/tablesink/state" 19 ) 20 21 // TableEvent is the interface for events which can be written to sink by TableSink. 22 type TableEvent interface { 23 // GetCommitTs returns the commit timestamp of the event. 24 GetCommitTs() uint64 25 // TrySplitAndSortUpdateEvent split the update to delete and insert if the unique key is updated 26 TrySplitAndSortUpdateEvent(scheme string) error 27 } 28 29 // CallbackFunc is the callback function for callbackable event. 30 type CallbackFunc func() 31 32 // CallbackableEvent means the event can be callbacked. 33 // It also contains the table status. 34 type CallbackableEvent[E TableEvent] struct { 35 Event E 36 Callback CallbackFunc 37 SinkState *state.TableSinkState 38 } 39 40 // GetTableSinkState returns the table sink state. 41 func (ce *CallbackableEvent[E]) GetTableSinkState() state.TableSinkState { 42 return ce.SinkState.Load() 43 } 44 45 // RowChangeCallbackableEvent is the row change event which can be callbacked. 46 type RowChangeCallbackableEvent = CallbackableEvent[*model.RowChangedEvent] 47 48 // TxnCallbackableEvent is the txn event which can be callbacked. 49 type TxnCallbackableEvent = CallbackableEvent[*model.SingleTableTxn]