github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cdc/redo/writer/factory/factory.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 factory 15 16 import ( 17 "context" 18 "strings" 19 20 "github.com/pingcap/tidb/br/pkg/storage" 21 "github.com/pingcap/tiflow/cdc/redo/writer" 22 "github.com/pingcap/tiflow/cdc/redo/writer/blackhole" 23 "github.com/pingcap/tiflow/cdc/redo/writer/file" 24 "github.com/pingcap/tiflow/cdc/redo/writer/memory" 25 "github.com/pingcap/tiflow/pkg/errors" 26 "github.com/pingcap/tiflow/pkg/redo" 27 ) 28 29 // NewRedoLogWriter creates a new RedoLogWriter. 30 func NewRedoLogWriter( 31 ctx context.Context, lwCfg *writer.LogWriterConfig, 32 ) (writer.RedoLogWriter, error) { 33 uri, err := storage.ParseRawURL(lwCfg.Storage) 34 if err != nil { 35 return nil, err 36 } 37 38 if !redo.IsValidConsistentStorage(uri.Scheme) { 39 return nil, errors.ErrConsistentStorage.GenWithStackByArgs(uri.Scheme) 40 } 41 42 lwCfg.URI = uri 43 lwCfg.UseExternalStorage = redo.IsExternalStorage(uri.Scheme) 44 45 if redo.IsBlackholeStorage(uri.Scheme) { 46 invalid := strings.HasSuffix(uri.Scheme, "invalid") 47 return blackhole.NewLogWriter(invalid), nil 48 } 49 50 if lwCfg.UseFileBackend { 51 return file.NewLogWriter(ctx, lwCfg) 52 } 53 return memory.NewLogWriter(ctx, lwCfg) 54 }