Skip to content
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

schemaStorage(ticdc): remove schemaVersion in schemaStorage (#11869) #11916

Open
wants to merge 2 commits into
base: release-6.5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions cdc/entry/schema/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,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
}

// NewSingleSnapshotFromMeta creates a new single schema snapshot from a tidb meta
func NewSingleSnapshotFromMeta(
meta *timeta.Meta,
Expand Down
25 changes: 8 additions & 17 deletions cdc/entry/schema_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ type SchemaStorage interface {
}

type schemaStorageImpl struct {
snaps []*schema.Snapshot
snapsMu sync.RWMutex
gcTs uint64
resolvedTs uint64
schemaVersion int64
snaps []*schema.Snapshot
snapsMu sync.RWMutex
gcTs uint64
resolvedTs uint64

forceReplicate bool

Expand All @@ -73,9 +72,8 @@ func NewSchemaStorage(
role util.Role, filter filter.Filter,
) (SchemaStorage, error) {
var (
snap *schema.Snapshot
err error
version int64
snap *schema.Snapshot
err error
)
if meta == nil {
snap = schema.NewEmptySnapshot(forceReplicate)
Expand All @@ -84,7 +82,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 @@ -98,7 +95,6 @@ func NewSchemaStorage(
resolvedTs: startTs,
forceReplicate: forceReplicate,
id: id,
schemaVersion: version,
role: role,
}
return schema, nil
Expand Down Expand Up @@ -177,7 +173,6 @@ func (s *schemaStorageImpl) GetLastSnapshot() *schema.Snapshot {
// HandleDDLJob creates a new snapshot in storage and handles the ddl job
func (s *schemaStorageImpl) HandleDDLJob(job *timodel.Job) error {
if s.skipJob(job) {
s.schemaVersion = job.BinlogInfo.SchemaVersion
s.AdvanceResolvedTs(job.BinlogInfo.FinishedTS)
return nil
}
Expand All @@ -186,16 +181,13 @@ func (s *schemaStorageImpl) HandleDDLJob(job *timodel.Job) error {
var snap *schema.Snapshot
if len(s.snaps) > 0 {
lastSnap := s.snaps[len(s.snaps)-1]
// We use schemaVersion to check if an already-executed DDL job is processed for a second time.
// Unexecuted DDL jobs should have largest schemaVersions.
if job.BinlogInfo.FinishedTS <= lastSnap.CurrentTs() || job.BinlogInfo.SchemaVersion <= s.schemaVersion {
log.Info("ignore foregone DDL",
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.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 Down Expand Up @@ -223,7 +215,6 @@ func (s *schemaStorageImpl) HandleDDLJob(job *timodel.Job) error {
zap.String("role", s.role.String()))

s.snaps = append(s.snaps, snap)
s.schemaVersion = job.BinlogInfo.SchemaVersion
s.AdvanceResolvedTs(job.BinlogInfo.FinishedTS)
return nil
}
Expand Down
Loading