Repository navigation
snapshot: bootstrap changefeeds with an independent CSE pipeline #6732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 17 commits
9e79e04
a7b274b
6ff1398
92647d4
fb0a9c9
a3ca336
0c1b420
d2415b8
17a5cdf
25f2390
f74c070
9f9d2db
455ee4a
0ed3514
e5f91fb
0be992e
25c4474
99a46f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ import ( | |
| "github.com/pingcap/ticdc/pkg/errors" | ||
| "github.com/pingcap/ticdc/pkg/integrity" | ||
| "github.com/pingcap/ticdc/pkg/liveness" | ||
| "github.com/pingcap/ticdc/pkg/snapshot/protocol" | ||
| "github.com/pingcap/ticdc/pkg/util" | ||
| ) | ||
|
|
||
|
|
@@ -213,17 +214,18 @@ func (d *JSONDuration) UnmarshalText(text []byte) error { | |
|
|
||
| // ReplicaConfig is a duplicate of config.ReplicaConfig | ||
| type ReplicaConfig struct { | ||
| PerformanceMode *string `json:"performance_mode,omitempty" toml:"performance-mode,omitempty"` | ||
| MemoryQuota *uint64 `json:"memory_quota,omitempty" toml:"memory-quota,omitempty"` | ||
| EventCollectorBatchCount *int `json:"event_collector_batch_count,omitempty" toml:"event-collector-batch-count,omitempty"` | ||
| EventCollectorBatchBytes *int `json:"event_collector_batch_bytes,omitempty" toml:"event-collector-batch-bytes,omitempty"` | ||
| CaseSensitive *bool `json:"case_sensitive,omitempty" toml:"case-sensitive,omitempty"` | ||
| ForceReplicate *bool `json:"force_replicate,omitempty" toml:"force-replicate,omitempty"` | ||
| IgnoreIneligibleTable *bool `json:"ignore_ineligible_table,omitempty" toml:"ignore-ineligible-table,omitempty"` | ||
| CheckGCSafePoint *bool `json:"check_gc_safe_point,omitempty" toml:"check-gc-safe-point,omitempty"` | ||
| EnableSyncPoint *bool `json:"enable_sync_point,omitempty" toml:"enable-sync-point,omitempty"` | ||
| EnableTableMonitor *bool `json:"enable_table_monitor,omitempty" toml:"enable-table-monitor,omitempty"` | ||
| BDRMode *bool `json:"bdr_mode,omitempty" toml:"bdr-mode,omitempty"` | ||
| Snapshot *protocol.Config `json:"snapshot,omitempty"` | ||
| PerformanceMode *string `json:"performance_mode,omitempty" toml:"performance-mode,omitempty"` | ||
| MemoryQuota *uint64 `json:"memory_quota,omitempty" toml:"memory-quota,omitempty"` | ||
| EventCollectorBatchCount *int `json:"event_collector_batch_count,omitempty" toml:"event-collector-batch-count,omitempty"` | ||
| EventCollectorBatchBytes *int `json:"event_collector_batch_bytes,omitempty" toml:"event-collector-batch-bytes,omitempty"` | ||
| CaseSensitive *bool `json:"case_sensitive,omitempty" toml:"case-sensitive,omitempty"` | ||
| ForceReplicate *bool `json:"force_replicate,omitempty" toml:"force-replicate,omitempty"` | ||
| IgnoreIneligibleTable *bool `json:"ignore_ineligible_table,omitempty" toml:"ignore-ineligible-table,omitempty"` | ||
| CheckGCSafePoint *bool `json:"check_gc_safe_point,omitempty" toml:"check-gc-safe-point,omitempty"` | ||
| EnableSyncPoint *bool `json:"enable_sync_point,omitempty" toml:"enable-sync-point,omitempty"` | ||
| EnableTableMonitor *bool `json:"enable_table_monitor,omitempty" toml:"enable-table-monitor,omitempty"` | ||
| BDRMode *bool `json:"bdr_mode,omitempty" toml:"bdr-mode,omitempty"` | ||
| // AllowSameCluster allows the downstream to be the same TiDB logical cluster as the upstream. | ||
| // By default TiCDC rejects such a changefeed to avoid self-replication loops. | ||
| AllowSameCluster *bool `json:"allow_same_cluster,omitempty" toml:"allow-same-cluster,omitempty"` | ||
|
|
@@ -264,6 +266,9 @@ func (c *ReplicaConfig) ToInternalReplicaConfig() *config.ReplicaConfig { | |
| func (c *ReplicaConfig) toInternalReplicaConfigWithOriginConfig( | ||
| res *config.ReplicaConfig, | ||
| ) *config.ReplicaConfig { | ||
| if c.Snapshot != nil { | ||
| res.Snapshot = c.Snapshot | ||
| } | ||
| if c.PerformanceMode != nil { | ||
| res.PerformanceMode = c.PerformanceMode | ||
| } | ||
|
|
@@ -742,6 +747,7 @@ func ToAPIReplicaConfig(c *config.ReplicaConfig) *ReplicaConfig { | |
| cloned := c.Clone() | ||
|
|
||
| res := &ReplicaConfig{ | ||
| Snapshot: cloned.Snapshot, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| PerformanceMode: cloned.PerformanceMode, | ||
| MemoryQuota: cloned.MemoryQuota, | ||
| EventCollectorBatchCount: cloned.EventCollectorBatchCount, | ||
|
|
@@ -1446,11 +1452,13 @@ type ResolveLockReq struct { | |
|
|
||
| // ChangeFeedInfo describes the detail of a ChangeFeed | ||
| type ChangeFeedInfo struct { | ||
| UpstreamID uint64 `json:"upstream_id,omitempty" toml:"upstream-id,omitempty"` | ||
| ID string `json:"id" toml:"id"` | ||
| Keyspace string `json:"keyspace" toml:"keyspace"` | ||
| SinkURI string `json:"sink_uri,omitempty" toml:"sink-uri,omitempty"` | ||
| CreateTime time.Time `json:"create_time" toml:"create-time"` | ||
| Snapshot *protocol.State `json:"snapshot,omitempty"` | ||
| BootstrapComplete bool `json:"bootstrap_complete"` | ||
| UpstreamID uint64 `json:"upstream_id,omitempty" toml:"upstream-id,omitempty"` | ||
| ID string `json:"id" toml:"id"` | ||
| Keyspace string `json:"keyspace" toml:"keyspace"` | ||
| SinkURI string `json:"sink_uri,omitempty" toml:"sink-uri,omitempty"` | ||
| CreateTime time.Time `json:"create_time" toml:"create-time"` | ||
| // Start sync at this commit ts if `StartTs` is specify or using the CreateTime of changefeed. | ||
| StartTs uint64 `json:"start_ts,omitempty" toml:"start-ts,omitempty"` | ||
| // The ChangeFeed will exits until sync to timestamp TargetTs | ||
|
|
@@ -1559,6 +1567,9 @@ func (c *ReplicaConfig) omitSensitiveData() { | |
|
|
||
| // maskSensitiveData masks configured API fields without populating omitted fields. | ||
| func (c *ReplicaConfig) maskSensitiveData() { | ||
| if c != nil && c.Snapshot != nil { | ||
| c.Snapshot.BackupURI = util.MaskSensitiveDataInURI(c.Snapshot.BackupURI) | ||
| } | ||
| if c == nil { | ||
| return | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -181,30 +181,29 @@ func (b *EtcdBackend) UpdateChangefeed(ctx context.Context, info *config.ChangeF | |
| if err != nil { | ||
| return errors.Trace(err) | ||
| } | ||
| status := &config.ChangeFeedStatus{ | ||
| CheckpointTs: checkpointTs, | ||
| Progress: progress, | ||
| } | ||
| statusStr, err := status.Marshal() | ||
| if err != nil { | ||
| return errors.Trace(err) | ||
| } | ||
| jobKey := etcd.GetEtcdKeyJob(b.etcdClient.GetClusterID(), info.ChangefeedID.DisplayName) | ||
| opsThen := []clientv3.Op{} | ||
| opsThen = append(opsThen, | ||
| clientv3.OpPut(infoKey, newStr), | ||
| clientv3.OpPut(jobKey, statusStr), | ||
| ) | ||
|
|
||
| putResp, err := b.etcdClient.GetEtcdClient().Txn(ctx, []clientv3.Cmp{}, opsThen, []clientv3.Op{}) | ||
| if err != nil { | ||
| return errors.Trace(err) | ||
| } | ||
| if !putResp.Succeeded { | ||
| err = cerror.ErrMetaOpFailed.GenWithStackByArgs(fmt.Sprintf("update changefeed %s failed", info.ChangefeedID.Name())) | ||
| return errors.Trace(err) | ||
| for range 20 { | ||
| status, revision, err := b.etcdClient.GetChangeFeedStatus(ctx, info.ChangefeedID) | ||
| if err != nil { | ||
| return errors.Trace(err) | ||
| } | ||
| status.CheckpointTs = checkpointTs | ||
| status.Progress = progress | ||
| statusStr, err := status.Marshal() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| jobKey := etcd.GetEtcdKeyJob(b.etcdClient.GetClusterID(), info.ChangefeedID.DisplayName) | ||
| resp, err := b.etcdClient.GetEtcdClient().Txn(ctx, | ||
| []clientv3.Cmp{clientv3.Compare(clientv3.ModRevision(jobKey), "=", revision)}, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pause can overwrite an epoch bump that writes only the info key.
The pause write must fail when the info key changed after pause read it. Pause must re-read the info and its
|
||
| []clientv3.Op{clientv3.OpPut(infoKey, newStr), clientv3.OpPut(jobKey, statusStr)}, nil) | ||
| if err != nil { | ||
| return errors.Trace(err) | ||
| } | ||
| if resp.Succeeded { | ||
| return nil | ||
| } | ||
| } | ||
| return nil | ||
| return cerror.ErrMetaOpFailed.GenWithStackByArgs("update changefeed status contention") | ||
| } | ||
|
|
||
| // FinishInit acknowledges initialization without overwriting status | ||
|
|
@@ -387,35 +386,11 @@ func (b *EtcdBackend) PauseChangefeed(ctx context.Context, id common.ChangeFeedI | |
| return errors.Trace(err) | ||
| } | ||
| info.State = config.StateStopped | ||
| infoKey := etcd.GetEtcdKeyChangeFeedInfo(b.etcdClient.GetClusterID(), id.DisplayName) | ||
| inforValue, err := info.Marshal() | ||
| if err != nil { | ||
| return errors.Trace(err) | ||
| } | ||
| status, _, err := b.etcdClient.GetChangeFeedStatus(ctx, id) | ||
| if err != nil { | ||
| return errors.Trace(err) | ||
| } | ||
| status.Progress = config.ProgressStopping | ||
| jobValue, err := status.Marshal() | ||
| if err != nil { | ||
| return errors.Trace(err) | ||
| } | ||
| jobKey := etcd.GetEtcdKeyJob(b.etcdClient.GetClusterID(), id.DisplayName) | ||
| putResp, err := b.etcdClient.GetEtcdClient().Txn(ctx, nil, | ||
| []clientv3.Op{ | ||
| clientv3.OpPut(jobKey, jobValue), | ||
| clientv3.OpPut(infoKey, inforValue), | ||
| }, | ||
| []clientv3.Op{}) | ||
| if err != nil { | ||
| return errors.Trace(err) | ||
| } | ||
| if !putResp.Succeeded { | ||
| err = cerror.ErrMetaOpFailed.GenWithStackByArgs(fmt.Sprintf("pause changefeed %s failed", id.DisplayName)) | ||
| return errors.Trace(err) | ||
| } | ||
| return nil | ||
| return b.UpdateChangefeed(ctx, info, status.CheckpointTs, config.ProgressStopping) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve the latest checkpoint when pausing a changefeed. If the checkpoint advances from 100 to 120 after
|
||
| } | ||
|
|
||
| func (b *EtcdBackend) DeleteChangefeed(ctx context.Context, | ||
|
|
@@ -492,40 +467,40 @@ func (b *EtcdBackend) SetChangefeedProgress(ctx context.Context, id common.Chang | |
| } | ||
|
|
||
| func (b *EtcdBackend) UpdateChangefeedCheckpointTs(ctx context.Context, cps map[common.ChangeFeedID]uint64) error { | ||
| opsThen := make([]clientv3.Op, 0, 128) | ||
| batchSize := 0 | ||
|
|
||
| txnFunc := func() error { | ||
| putResp, err := b.etcdClient.GetEtcdClient().Txn(ctx, []clientv3.Cmp{}, opsThen, []clientv3.Op{}) | ||
| if err != nil { | ||
| return errors.Trace(err) | ||
| } | ||
| logEtcdOps(opsThen, putResp.Succeeded) | ||
| if !putResp.Succeeded { | ||
| return errors.New("commit failed") | ||
| } | ||
| return err | ||
| } | ||
| for cfID, checkpointTs := range cps { | ||
| status := &config.ChangeFeedStatus{CheckpointTs: checkpointTs, Progress: config.ProgressNone} | ||
| jobValue, err := status.Marshal() | ||
| if err != nil { | ||
| return errors.Trace(err) | ||
| } | ||
| jobKey := etcd.GetEtcdKeyJob(b.etcdClient.GetClusterID(), cfID.DisplayName) | ||
| opsThen = append(opsThen, clientv3.OpPut(jobKey, jobValue)) | ||
| batchSize++ | ||
| if batchSize >= 128 { | ||
| if err = txnFunc(); err != nil { | ||
| ids := make([]common.ChangeFeedID, 0, len(cps)) | ||
| for id := range cps { | ||
| ids = append(ids, id) | ||
| } | ||
| for start := 0; start < len(ids); start += 128 { | ||
| saved := false | ||
| for range 20 { | ||
| var ops []clientv3.Op | ||
| var comparisons []clientv3.Cmp | ||
| for _, id := range ids[start:min(start+128, len(ids))] { | ||
| status, revision, err := b.etcdClient.GetChangeFeedStatus(ctx, id) | ||
| if err != nil { | ||
| return errors.Trace(err) | ||
| } | ||
| status.CheckpointTs = max(status.CheckpointTs, cps[id]) | ||
| value, err := status.Marshal() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| key := etcd.GetEtcdKeyJob(b.etcdClient.GetClusterID(), id.DisplayName) | ||
| comparisons = append(comparisons, clientv3.Compare(clientv3.ModRevision(key), "=", revision)) | ||
| ops = append(ops, clientv3.OpPut(key, value)) | ||
| } | ||
| response, err := b.etcdClient.GetEtcdClient().Txn(ctx, comparisons, ops, nil) | ||
| if err != nil { | ||
| return errors.Trace(err) | ||
| } | ||
| opsThen = opsThen[:0] | ||
| batchSize = 0 | ||
| if response.Succeeded { | ||
| saved = true | ||
| break | ||
| } | ||
| } | ||
| } | ||
| if batchSize > 0 { | ||
| if err := txnFunc(); err != nil { | ||
| return errors.Trace(err) | ||
| if !saved { | ||
| return cerror.ErrMetaOpFailed.GenWithStackByArgs("checkpoint CAS contention") | ||
| } | ||
| } | ||
| return nil | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // Copyright 2026 PingCAP, Inc. Licensed under Apache-2.0. | ||
| package changefeed | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/pingcap/ticdc/pkg/common" | ||
| "github.com/pingcap/ticdc/pkg/snapshot/protocol" | ||
| "github.com/pingcap/ticdc/pkg/snapshot/state" | ||
| ) | ||
|
|
||
| func (b *EtcdBackend) LoadSnapshot(ctx context.Context, id common.ChangeFeedID, epoch uint64) (*protocol.State, error) { | ||
| return (&state.Repository{Client: b.etcdClient}).LoadSnapshot(ctx, id, epoch) | ||
| } | ||
|
|
||
| func (b *EtcdBackend) SaveSnapshot(ctx context.Context, id common.ChangeFeedID, epoch uint64, next *protocol.State) error { | ||
| return (&state.Repository{Client: b.etcdClient}).SaveSnapshot(ctx, id, epoch, next) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Snapshot backup changes can save a config that snapshot recovery rejects.
While a changefeed is stopped or failed,
replica_configcan replacesnapshot.backup_uriorsnapshot.backup_digestafter the snapshot input has been frozen.UpdateChangefeedpersists that config without comparing it with the stored snapshot state. On the next snapshot run, the input digest includes both fields. It no longer matches the storedInputDigest, so the run fails withfrozen snapshot input changed. The snapshot cannot finish until the backup settings are restored.Require one of these behaviors:
snapshot.backup_uriorsnapshot.backup_digestwhile a frozen snapshot input exists.Choose one policy and apply it before the update is persisted. Do not persist a change that recovery rejects.
Locations:
api/v2/changefeed.go:1074-1087and1174-1177;pkg/snapshot/bootstrap/controller.go:82-96.