Skip to content

[WIP]#5149

Draft
lidezhu wants to merge 3 commits into
masterfrom
ldz/add-ignore-config
Draft

[WIP]#5149
lidezhu wants to merge 3 commits into
masterfrom
ldz/add-ignore-config

Conversation

@lidezhu
Copy link
Copy Markdown
Collaborator

@lidezhu lidezhu commented May 28, 2026

What problem does this PR solve?

Issue Number: close #xxx

What is changed and how it works?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Questions

Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?

Release note

Please refer to [Release Notes Language Style Guide](https://pingcap.github.io/tidb-dev-guide/contribute-to-tidb/release-notes-style-guide.html) to write a quality release note.

If you don't think this PR needs a release note then fill it with `None`.

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 28, 2026

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot Bot added do-not-merge/needs-linked-issue do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note Denotes a PR that will be considered when it comes time to generate release notes. labels May 28, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 28, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign flowbehappy for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 28, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b99e7ace-6d17-4191-ae60-910adb48102c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ldz/add-ignore-config

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ti-chi-bot ti-chi-bot Bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label May 28, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the ability to ignore specific DDL event types in the schema store via the ignore-ddl-types configuration. It updates the binlog-filter package to support classifying and mapping additional DDL types (such as foreign keys and full-text indexes), adds configuration validation, and includes integration tests. The code review feedback suggests critical performance optimizations, specifically constructing the BinlogEvent filter once rather than recreating it for every single DDL event, updating the associated tests to match this optimized signature, and passing configuration slices directly to allow in-place normalization.

Comment thread logservice/schemastore/schema_store.go Outdated
Comment on lines +191 to +266
func filterIgnoredDDLEvents(events []commonEvent.DDLEvent) []commonEvent.DDLEvent {
serverConfig := config.GetGlobalServerConfig()
ignoreDDLTypes := serverConfig.Debug.SchemaStore.IgnoreDDLTypes
if len(ignoreDDLTypes) == 0 || len(events) == 0 {
return events
}

filteredEvents := events[:0]
for _, event := range events {
if shouldIgnoreDDLEventByType(event, ignoreDDLTypes) {
log.Info("ignore ddl event by type",
zap.Any("type", event.GetDDLType()),
zap.Uint64("finishedTs", event.FinishedTs),
zap.String("query", event.Query))
continue
}
filteredEvents = append(filteredEvents, event)
}
return filteredEvents
}

func shouldIgnoreDDLEventByType(ddlEvent commonEvent.DDLEvent, ignoreDDLTypes []bf.EventType) bool {
if len(ignoreDDLTypes) == 0 {
return false
}

actionType := ddlEvent.GetDDLType()
ddlType := filter.DDLToEventType(actionType)
if ddlType == bf.NullEvent {
log.Warn("schema store ignore ddl type found unsupported ddl",
zap.String("type", actionType.String()),
zap.String("query", ddlEvent.Query))
return false
}

eventFilter, err := bf.NewBinlogEvent(false, []*bf.BinlogEventRule{
{
SchemaPattern: "schema-store",
TablePattern: "ddl",
Events: append([]bf.EventType(nil), ignoreDDLTypes...),
Action: bf.Ignore,
},
})
if err != nil {
log.Warn("schema store ignore ddl type config is invalid",
zap.Any("ignoreDDLTypes", ignoreDDLTypes),
zap.Error(err))
return false
}

ignored, err := matchIgnoreDDLType(eventFilter, ddlType, ddlEvent.Query)
if err != nil {
log.Warn("schema store ignore ddl type failed",
zap.String("type", actionType.String()),
zap.String("query", ddlEvent.Query),
zap.Error(err))
return false
}
if ignored {
return true
}

if !filter.IsAlterTableDDL(actionType) {
return false
}

ignored, err = matchIgnoreDDLType(eventFilter, bf.AlterTable, ddlEvent.Query)
if err != nil {
log.Warn("schema store ignore alter table ddl type failed",
zap.String("type", actionType.String()),
zap.String("query", ddlEvent.Query),
zap.Error(err))
return false
}
return ignored
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Recreating the BinlogEvent filter for every single DDL event in shouldIgnoreDDLEventByType is highly inefficient and causes unnecessary memory allocations and CPU overhead.

Since the ignoreDDLTypes list is static for a given configuration, we should construct the BinlogEvent filter once in filterIgnoredDDLEvents and pass it to shouldIgnoreDDLEventByType.

func filterIgnoredDDLEvents(events []commonEvent.DDLEvent) []commonEvent.DDLEvent {
	serverConfig := config.GetGlobalServerConfig()
	ignoreDDLTypes := serverConfig.Debug.SchemaStore.IgnoreDDLTypes
	if len(ignoreDDLTypes) == 0 || len(events) == 0 {
		return events
	}

	eventFilter, err := bf.NewBinlogEvent(false, []*bf.BinlogEventRule{
		{
			SchemaPattern: "schema-store",
			TablePattern:  "ddl",
			Events:        append([]bf.EventType(nil), ignoreDDLTypes...),
			Action:        bf.Ignore,
		},
	})
	if err != nil {
		log.Warn("schema store ignore ddl type config is invalid",
			zap.Any("ignoreDDLTypes", ignoreDDLTypes),
			zap.Error(err))
		return events
	}

	filteredEvents := events[:0]
	for _, event := range events {
		if shouldIgnoreDDLEventByType(event, eventFilter) {
			log.Info("ignore ddl event by type",
				zap.Any("type", event.GetDDLType()),
				zap.Uint64("finishedTs", event.FinishedTs),
				zap.String("query", event.Query))
			continue
		}
		filteredEvents = append(filteredEvents, event)
	}
	return filteredEvents
}

func shouldIgnoreDDLEventByType(ddlEvent commonEvent.DDLEvent, eventFilter *bf.BinlogEvent) bool {
	actionType := ddlEvent.GetDDLType()
	ddlType := filter.DDLToEventType(actionType)
	if ddlType == bf.NullEvent {
		log.Warn("schema store ignore ddl type found unsupported ddl",
			zap.String("type", actionType.String()),
			zap.String("query", ddlEvent.Query))
		return false
	}

	ignored, err := matchIgnoreDDLType(eventFilter, ddlType, ddlEvent.Query)
	if err != nil {
		log.Warn("schema store ignore ddl type failed",
			zap.String("type", actionType.String()),
			zap.String("query", ddlEvent.Query),
			zap.Error(err))
		return false
	}
	if ignored {
		return true
	}

	if !filter.IsAlterTableDDL(actionType) {
		return false
	}

	ignored, err = matchIgnoreDDLType(eventFilter, bf.AlterTable, ddlEvent.Query)
	if err != nil {
		log.Warn("schema store ignore alter table ddl type failed",
			zap.String("type", actionType.String()),
			zap.String("query", ddlEvent.Query),
			zap.Error(err))
		return false
	}
	return ignored
}

Comment on lines +197 to +222
func TestIgnoreDDLEventByTypeCoversSupportedDDLTypes(t *testing.T) {
for _, actionType := range cdcfilter.SupportedDDLActionTypes() {
ddlEvent := commonEvent.DDLEvent{
Type: byte(actionType),
Query: "ddl",
}
eventType := cdcfilter.DDLToEventType(actionType)
require.NotEqual(t, bf.NullEvent, eventType, actionType.String())

require.True(t,
shouldIgnoreDDLEventByType(ddlEvent, []bf.EventType{eventType}),
actionType.String())
require.True(t,
shouldIgnoreDDLEventByType(ddlEvent, []bf.EventType{bf.AllDDL}),
actionType.String())
require.False(t,
shouldIgnoreDDLEventByType(ddlEvent, []bf.EventType{bf.NoneDDL}),
actionType.String())

if cdcfilter.IsAlterTableDDL(actionType) {
require.True(t,
shouldIgnoreDDLEventByType(ddlEvent, []bf.EventType{bf.AlterTable}),
actionType.String())
}
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Update the test to match the updated signature of shouldIgnoreDDLEventByType which now accepts *bf.BinlogEvent instead of []bf.EventType.

func TestIgnoreDDLEventByTypeCoversSupportedDDLTypes(t *testing.T) {
	for _, actionType := range cdcfilter.SupportedDDLActionTypes() {
		ddlEvent := commonEvent.DDLEvent{
			Type:  byte(actionType),
			Query: "ddl",
		}
		eventType := cdcfilter.DDLToEventType(actionType)
		require.NotEqual(t, bf.NullEvent, eventType, actionType.String())

		helper := func(types []bf.EventType) bool {
			eventFilter, err := bf.NewBinlogEvent(false, []*bf.BinlogEventRule{
				{
					SchemaPattern: "schema-store",
					TablePattern:  "ddl",
					Events:        append([]bf.EventType(nil), types...),
					Action:        bf.Ignore,
				},
			})
			require.NoError(t, err)
			return shouldIgnoreDDLEventByType(ddlEvent, eventFilter)
		}

		require.True(t,
			helper([]bf.EventType{eventType}),
			actionType.String())
		require.True(t,
			helper([]bf.EventType{bf.AllDDL}),
			actionType.String())
		require.False(t,
			helper([]bf.EventType{bf.NoneDDL}),
			actionType.String())

		if cdcfilter.IsAlterTableDDL(actionType) {
			require.True(t,
				helper([]bf.EventType{bf.AlterTable}),
				actionType.String())
		}
	}
}

Comment thread pkg/config/debug.go Outdated
Comment on lines +151 to +159
_, err := bf.NewBinlogEvent(false, []*bf.BinlogEventRule{
{
SchemaPattern: "schema-store",
TablePattern: "ddl",
Events: append([]bf.EventType(nil), c.IgnoreDDLTypes...),
Action: bf.Ignore,
},
})
return errors.Trace(err)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since ValidateAndAdjust is intended to normalize and adjust configuration values, we should pass c.IgnoreDDLTypes directly to bf.NewBinlogEvent instead of copying it. This allows bf.NewBinlogEvent to normalize the event types (e.g., converting them to lowercase) in-place within the configuration struct.

Suggested change
_, err := bf.NewBinlogEvent(false, []*bf.BinlogEventRule{
{
SchemaPattern: "schema-store",
TablePattern: "ddl",
Events: append([]bf.EventType(nil), c.IgnoreDDLTypes...),
Action: bf.Ignore,
},
})
return errors.Trace(err)
_, err := bf.NewBinlogEvent(false, []*bf.BinlogEventRule{
{
SchemaPattern: "schema-store",
TablePattern: "ddl",
Events: c.IgnoreDDLTypes,
Action: bf.Ignore,
},
})
return errors.Trace(err)

@ti-chi-bot ti-chi-bot Bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 28, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 29, 2026

[FORMAT CHECKER NOTIFICATION]

Notice: To remove the do-not-merge/needs-linked-issue label, please provide the linked issue number on one line in the PR body, for example: Issue Number: close #123 or Issue Number: ref #456.

📖 For more info, you can check the "Contribute Code" section in the development guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/needs-linked-issue do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant