Skip to content

ddl, mvservice: notify alter MV and MV log events#68776

Merged
ti-chi-bot[bot] merged 4 commits into
pingcap:feature/release-8.5-materialized-viewfrom
windtalker:cp_for_mv_1
May 29, 2026
Merged

ddl, mvservice: notify alter MV and MV log events#68776
ti-chi-bot[bot] merged 4 commits into
pingcap:feature/release-8.5-materialized-viewfrom
windtalker:cp_for_mv_1

Conversation

@windtalker
Copy link
Copy Markdown
Contributor

@windtalker windtalker commented May 29, 2026

What problem does this PR solve?

Issue Number: ref #18023

Problem Summary:

MV service needs to be notified when materialized view or materialized view log scheduling metadata is changed by ALTER, so that background refresh/purge scheduling can react asynchronously instead of waiting only for periodic polling.

What changed and how does it work?

This PR adds async DDL notifier events for materialized view and materialized view log alter operations:

  • Adds notifier event types for ALTER MATERIALIZED VIEW and ALTER MATERIALIZED VIEW LOG.
  • Emits the corresponding async notifier events when these DDL jobs are processed.
  • Lets MV service consume these events and refresh related task metadata.
  • Adds/updates tests for notifier events, MV service task handling, and MV log write behavior.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

Support async notification for materialized view and materialized view log alter events.

Summary by CodeRabbit

  • New Features

    • Added event notification support for materialized view refresh and log purge DDL operations.
  • Bug Fixes

    • Improved session handling in materialized view DDL job dispatchers.
    • Enhanced validation to properly reject online DDL operations on base table columns tracked by materialized view logs.
  • Tests

    • Expanded test coverage for materialized view event constructors and online DDL scenarios with materialized view logs.

Review Change Stack

@ti-chi-bot ti-chi-bot Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 29, 2026
@tiprow
Copy link
Copy Markdown

tiprow Bot commented May 29, 2026

Hi @windtalker. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 29, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d480489b-e0ea-42cf-a10c-5fd45125a9c7

📥 Commits

Reviewing files that changed from the base of the PR and between 74b10f2 and 1099b1d.

📒 Files selected for processing (11)
  • pkg/ddl/job_worker.go
  • pkg/ddl/notifier/BUILD.bazel
  • pkg/ddl/notifier/events.go
  • pkg/ddl/notifier/events_test.go
  • pkg/ddl/table.go
  • pkg/executor/test/writetest/BUILD.bazel
  • pkg/executor/test/writetest/mview_log_write_test.go
  • pkg/mvservice/service_helper.go
  • pkg/mvservice/task_handler_test.go
  • tests/integrationtest/r/executor/mview_log_dml.result
  • tests/integrationtest/t/executor/mview_log_dml.test

📝 Walkthrough

Walkthrough

The PR extends DDL support for materialized view refresh and log purge operations by introducing event-based notification, updating handlers to accept session context, dispatching events asynchronously, and verifying correct DML behavior after rejected ALTER operations.

Changes

Materialized View DDL Event Emission

Layer / File(s) Summary
Event constructors and contracts
pkg/ddl/notifier/events.go, pkg/ddl/notifier/events_test.go, pkg/ddl/notifier/BUILD.bazel
Introduces NewAlterMaterializedViewRefreshEvent, NewAlterMaterializedViewLogPurgeEvent and getter methods to construct and retrieve MV alter events; test verifies event type assertions and old table info preservation; notifier test shard count increased to accommodate new test.
DDL job dispatcher wiring
pkg/ddl/job_worker.go
Updates runOneJobStep switch cases to pass worker session (w.sess) to onAlterMaterializedViewRefresh and onAlterMaterializedViewLogPurge handlers, enabling session-context-dependent event emission.
Handler event emission implementation
pkg/ddl/table.go
Both MV alter handlers now accept *sess.Session parameter, clone pre-update table state, apply refresh/purge parameter changes, update version/table info, construct and dispatch schema change events via asyncNotifyEvent, then finish the job.
MV service event handling registration
pkg/mvservice/service_helper.go, pkg/mvservice/task_handler_test.go
shouldHandleMVCreateEvent now explicitly handles the two new MV action types; test coverage verifies the DDL handler correctly processes both refresh and purge schema change events.
MLog DDL and DML test coverage
pkg/executor/test/writetest/mview_log_write_test.go, pkg/executor/test/writetest/BUILD.bazel, tests/integrationtest/t/executor/mview_log_dml.test, tests/integrationtest/r/executor/mview_log_dml.result
New test for online DDL drop rejection on tracked columns; extended test verifies post-rejection DML (insert/update/delete) produces correct mlog entries and tracked column remains; integration test expectations updated to cover expanded DML sequence.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • pingcap/tidb#68649: Both PRs extend DDL handling for the same materialized-view actions (ActionAlterMaterializedViewRefresh / ActionAlterMaterializedViewLogPurge) by updating the job worker dispatch and the corresponding alter handlers for refresh/purge behavior.

Suggested labels

size/XL, lgtm

Suggested reviewers

  • gengliqi
  • wshwsh12

Poem

🐰 A hop through the logs, event by event,
Refresh and purge now properly sent,
With sessions in hand and tables in sight,
The MV DDL flows just right!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly summarizes the main change: adding async notification for ALTER MV and MV LOG events.
Description check ✅ Passed The PR description follows the template with issue number, problem summary, what changed, completed checklist items, and release notes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions
The command is terminated due to an error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions


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.

Copy link
Copy Markdown
Contributor

@solotzg solotzg left a comment

Choose a reason for hiding this comment

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

lgtm

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 29, 2026

@solotzg: adding LGTM is restricted to approvers and reviewers in OWNERS files.

Details

In response to this:

lgtm

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ti-chi-bot ti-chi-bot Bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label May 29, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

❌ Patch coverage is 85.00000% with 6 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (feature/release-8.5-materialized-view@edbfd51). Learn more about missing BASE report.

Additional details and impacted files
@@                            Coverage Diff                             @@
##             feature/release-8.5-materialized-view     #68776   +/-   ##
==========================================================================
  Coverage                                         ?   57.7579%           
==========================================================================
  Files                                            ?       1811           
  Lines                                            ?     653823           
  Branches                                         ?          0           
==========================================================================
  Hits                                             ?     377635           
  Misses                                           ?     250109           
  Partials                                         ?      26079           
Flag Coverage Δ
integration 37.8207% <0.0000%> (?)
unit 72.1477% <85.0000%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.9278% <0.0000%> (?)
parser ∅ <0.0000%> (?)
br 63.4931% <0.0000%> (?)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 29, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: gengliqi, solotzg, wshwsh12
Once this PR has been reviewed and has the lgtm label, please assign d3hunter 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

@ti-chi-bot ti-chi-bot Bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels May 29, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 29, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-05-29 12:17:28.573547788 +0000 UTC m=+21588.948357464: ☑️ agreed by wshwsh12.
  • 2026-05-29 12:26:29.727019005 +0000 UTC m=+22130.101828691: ☑️ agreed by gengliqi.

@windtalker
Copy link
Copy Markdown
Contributor Author

/test pull-br-integration-test

@tiprow
Copy link
Copy Markdown

tiprow Bot commented May 29, 2026

@windtalker: PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test.

Details

In response to this:

/test pull-br-integration-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@windtalker
Copy link
Copy Markdown
Contributor Author

/test unit-test

@tiprow
Copy link
Copy Markdown

tiprow Bot commented May 29, 2026

@windtalker: PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test.

Details

In response to this:

/test unit-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@windtalker
Copy link
Copy Markdown
Contributor Author

/test pull-br-integration-test

@tiprow
Copy link
Copy Markdown

tiprow Bot commented May 29, 2026

@windtalker: PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test.

Details

In response to this:

/test pull-br-integration-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@windtalker
Copy link
Copy Markdown
Contributor Author

/test pull-br-integration-test

@tiprow
Copy link
Copy Markdown

tiprow Bot commented May 29, 2026

@windtalker: PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test.

Details

In response to this:

/test pull-br-integration-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@windtalker
Copy link
Copy Markdown
Contributor Author

/test mysql-test

@tiprow
Copy link
Copy Markdown

tiprow Bot commented May 29, 2026

@windtalker: PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test.

Details

In response to this:

/test mysql-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ti-chi-bot ti-chi-bot Bot merged commit 5f3246d into pingcap:feature/release-8.5-materialized-view May 29, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants