github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/cdc/sink/syncpointStore.go (about) 1 // Copyright 2020 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 sink 15 16 import ( 17 "context" 18 "net/url" 19 "strings" 20 21 "github.com/pingcap/ticdc/cdc/model" 22 cerror "github.com/pingcap/ticdc/pkg/errors" 23 ) 24 25 // SyncpointStore is an abstraction for anything that a changefeed may emit into. 26 type SyncpointStore interface { 27 // CreateSynctable create a table to record the syncpoints 28 CreateSynctable(ctx context.Context) error 29 30 // SinkSyncpoint record the syncpoint(a map with ts) in downstream db 31 SinkSyncpoint(ctx context.Context, id string, checkpointTs uint64) error 32 33 // Close closes the SyncpointSink 34 Close() error 35 } 36 37 // NewSyncpointStore creates a new Spyncpoint sink with the sink-uri 38 func NewSyncpointStore(ctx context.Context, changefeedID model.ChangeFeedID, sinkURIStr string) (SyncpointStore, error) { 39 // parse sinkURI as a URI 40 sinkURI, err := url.Parse(sinkURIStr) 41 if err != nil { 42 return nil, cerror.WrapError(cerror.ErrSinkURIInvalid, err) 43 } 44 switch strings.ToLower(sinkURI.Scheme) { 45 case "mysql", "tidb", "mysql+ssl", "tidb+ssl": 46 return newMySQLSyncpointStore(ctx, changefeedID, sinkURI) 47 default: 48 return nil, cerror.ErrSinkURIInvalid.GenWithStack("the sink scheme (%s) is not supported", sinkURI.Scheme) 49 } 50 }