Skip to content

Commit

Permalink
Merge branch 'release-7.5' into cherry-pick-11856-to-release-7.5
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesCheung96 authored Dec 22, 2024
2 parents 4675ce6 + 5e61d5a commit aa9b7b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 32 deletions.
18 changes: 0 additions & 18 deletions cdc/entry/schema/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,6 @@ func (s *Snapshot) FillSchemaName(job *timodel.Job) error {
return nil
}

// GetSchemaVersion returns the schema version of the meta.
func GetSchemaVersion(meta *timeta.Meta) (int64, error) {
// After we get the schema version at startTs, if the diff corresponding to that version does not exist,
// it means that the job is not committed yet, so we should subtract one from the version, i.e., version--.
version, err := meta.GetSchemaVersion()
if err != nil {
return 0, errors.Trace(err)
}
diff, err := meta.GetSchemaDiff(version)
if err != nil {
return 0, errors.Trace(err)
}
if diff == nil {
version--
}
return version, nil
}

// NewSnapshotFromMeta creates a schema snapshot from meta.
func NewSnapshotFromMeta(
id model.ChangeFeedID,
Expand Down
20 changes: 6 additions & 14 deletions cdc/entry/schema_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ type schemaStorage struct {
snaps []*schema.Snapshot
snapsMu sync.RWMutex

gcTs uint64
resolvedTs uint64
schemaVersion int64
gcTs uint64
resolvedTs uint64

filter filter.Filter

Expand All @@ -91,9 +90,8 @@ func NewSchemaStorage(
role util.Role, filter filter.Filter,
) (SchemaStorage, error) {
var (
snap *schema.Snapshot
version int64
err error
snap *schema.Snapshot
err error
)
// storage may be nil in some unit test cases.
if storage == nil {
Expand All @@ -104,7 +102,6 @@ func NewSchemaStorage(
if err != nil {
return nil, errors.Trace(err)
}
version, err = schema.GetSchemaVersion(meta)
if err != nil {
return nil, errors.Trace(err)
}
Expand All @@ -115,7 +112,6 @@ func NewSchemaStorage(
forceReplicate: forceReplicate,
filter: filter,
id: id,
schemaVersion: version,
role: role,
}, nil
}
Expand Down Expand Up @@ -193,7 +189,6 @@ func (s *schemaStorage) GetLastSnapshot() *schema.Snapshot {
// HandleDDLJob creates a new snapshot in storage and handles the ddl job
func (s *schemaStorage) HandleDDLJob(job *timodel.Job) error {
if s.skipJob(job) {
s.schemaVersion = job.BinlogInfo.SchemaVersion
s.AdvanceResolvedTs(job.BinlogInfo.FinishedTS)
return nil
}
Expand All @@ -202,16 +197,15 @@ func (s *schemaStorage) HandleDDLJob(job *timodel.Job) error {
var snap *schema.Snapshot
if len(s.snaps) > 0 {
lastSnap := s.snaps[len(s.snaps)-1]
// already-executed DDL could filted by finishedTs.
if job.BinlogInfo.FinishedTS <= lastSnap.CurrentTs() || job.BinlogInfo.SchemaVersion <= s.schemaVersion {
// already-executed DDL could filted by finishedTs.
if job.BinlogInfo.FinishedTS <= lastSnap.CurrentTs() {
log.Info("schemaStorage: ignore foregone DDL",
zap.String("namespace", s.id.Namespace),
zap.String("changefeed", s.id.ID),
zap.String("DDL", job.Query),
zap.String("state", job.State.String()),
zap.Int64("jobID", job.ID),
zap.Uint64("finishTs", job.BinlogInfo.FinishedTS),
zap.Int64("schemaVersion", s.schemaVersion),
zap.Int64("jobSchemaVersion", job.BinlogInfo.SchemaVersion),
zap.String("role", s.role.String()))
return nil
Expand All @@ -233,7 +227,6 @@ func (s *schemaStorage) HandleDDLJob(job *timodel.Job) error {
return errors.Trace(err)
}
s.snaps = append(s.snaps, snap)
s.schemaVersion = job.BinlogInfo.SchemaVersion
s.AdvanceResolvedTs(job.BinlogInfo.FinishedTS)
log.Info("schemaStorage: update snapshot by the DDL job",
zap.String("namespace", s.id.Namespace),
Expand All @@ -242,7 +235,6 @@ func (s *schemaStorage) HandleDDLJob(job *timodel.Job) error {
zap.String("table", job.TableName),
zap.String("query", job.Query),
zap.Uint64("finishedTs", job.BinlogInfo.FinishedTS),
zap.Uint64("schemaVersion", uint64(s.schemaVersion)),
zap.String("role", s.role.String()))
return nil
}
Expand Down

0 comments on commit aa9b7b3

Please sign in to comment.