github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cdc/redo/writer/blackhole/blackhole_log_writer.go (about) 1 // Copyright 2023 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 blackhole 15 16 import ( 17 "context" 18 "errors" 19 20 "github.com/pingcap/log" 21 "github.com/pingcap/tiflow/cdc/redo/writer" 22 "go.uber.org/zap" 23 ) 24 25 var _ writer.RedoLogWriter = (*blackHoleWriter)(nil) 26 27 // blackHoleSink defines a blackHole storage, it receives events and persists 28 // without any latency 29 type blackHoleWriter struct { 30 invalid bool 31 } 32 33 // NewLogWriter creates a blackHole writer 34 func NewLogWriter(invalid bool) *blackHoleWriter { 35 return &blackHoleWriter{ 36 invalid: invalid, 37 } 38 } 39 40 func (bs *blackHoleWriter) WriteEvents(_ context.Context, events ...writer.RedoEvent) (err error) { 41 if bs.invalid { 42 return errors.New("[WriteLog] invalid black hole writer") 43 } 44 if len(events) == 0 { 45 return nil 46 } 47 rl := events[len(events)-1].ToRedoLog() 48 current := rl.GetCommitTs() 49 log.Debug("write redo events", zap.Int("count", len(events)), 50 zap.Uint64("current", current)) 51 return 52 } 53 54 func (bs *blackHoleWriter) FlushLog(_ context.Context) error { 55 if bs.invalid { 56 return errors.New("[FlushLog] invalid black hole writer") 57 } 58 return nil 59 } 60 61 func (bs *blackHoleWriter) Close() error { 62 return nil 63 }