github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cdc/sink/tablesink/table_sink.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 tablesink 15 16 import ( 17 "github.com/pingcap/tiflow/cdc/model" 18 ) 19 20 // TableSink is the interface for table sink. 21 // It is used to sink data in table units. 22 type TableSink interface { 23 // AppendRowChangedEvents appends row changed events to the table sink. 24 // Usually, it is used to cache the row changed events into table sink. 25 // This is a not thread-safe method. Please do not call it concurrently. 26 AppendRowChangedEvents(rows ...*model.RowChangedEvent) 27 // UpdateResolvedTs writes the buffered row changed events to the eventTableSink. 28 // Note: This is an asynchronous and not thread-safe method. 29 // Please do not call it concurrently. 30 UpdateResolvedTs(resolvedTs model.ResolvedTs) error 31 // GetCheckpointTs returns the current checkpoint ts of table sink. 32 // For example, calculating the current progress from the statistics of the table sink. 33 // This is a thread-safe method. 34 GetCheckpointTs() model.ResolvedTs 35 // GetLastSyncedTs returns the last synced ts of table sink. 36 // the last synced ts means the biggest commits of the events 37 // that have been flushed to the downstream. 38 // This is a thread-safe method. 39 GetLastSyncedTs() model.Ts 40 // Close closes the table sink. 41 // After it returns, no more events will be sent out from this capture. 42 Close() 43 // AsyncClose closes the table sink asynchronously. Returns true if it's closed. 44 AsyncClose() bool 45 // CheckHealth checks whether the associated sink backend is healthy or not. 46 CheckHealth() error 47 } 48 49 // SinkInternalError means the error comes from sink internal. 50 type SinkInternalError struct { 51 err error 52 } 53 54 // Error implements builtin `error` interface. 55 func (e SinkInternalError) Error() string { 56 return e.err.Error() 57 } 58 59 // NewSinkInternalError creates a SinkInternalError. 60 func NewSinkInternalError(err error) SinkInternalError { 61 return SinkInternalError{err} 62 }