github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cdc/syncpointstore/syncpoint_store.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 syncpointstore
    15  
    16  import (
    17  	"context"
    18  	"net/url"
    19  	"strings"
    20  	"time"
    21  
    22  	"github.com/pingcap/tiflow/cdc/model"
    23  	cerror "github.com/pingcap/tiflow/pkg/errors"
    24  )
    25  
    26  // SyncPointStore is an abstraction for anything that a changefeed may emit into.
    27  type SyncPointStore interface {
    28  	// CreateSyncTable create a table to record the syncpoints
    29  	CreateSyncTable(ctx context.Context) error
    30  
    31  	// SinkSyncPoint record the syncpoint(a map with ts) in downstream db
    32  	SinkSyncPoint(ctx context.Context, id model.ChangeFeedID, checkpointTs uint64) error
    33  
    34  	// Close closes the SyncPointSink
    35  	Close() error
    36  }
    37  
    38  // NewSyncPointStore creates a new SyncPoint sink with the sink-uri
    39  func NewSyncPointStore(
    40  	ctx context.Context,
    41  	changefeedID model.ChangeFeedID,
    42  	sinkURIStr string,
    43  	syncPointRetention time.Duration,
    44  ) (SyncPointStore, error) {
    45  	// parse sinkURI as a URI
    46  	sinkURI, err := url.Parse(sinkURIStr)
    47  	if err != nil {
    48  		return nil, cerror.WrapError(cerror.ErrSinkURIInvalid, err)
    49  	}
    50  	switch strings.ToLower(sinkURI.Scheme) {
    51  	case "mysql", "tidb", "mysql+ssl", "tidb+ssl":
    52  		return newMySQLSyncPointStore(ctx, changefeedID, sinkURI, syncPointRetention)
    53  	default:
    54  		return nil, cerror.ErrSinkURIInvalid.
    55  			GenWithStack("the sink scheme (%s) is not supported", sinkURI.Scheme)
    56  	}
    57  }