-
Notifications
You must be signed in to change notification settings - Fork 38
common: accept legacy namespace in changefeed ID JSON #4080
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?
common: accept legacy namespace in changefeed ID JSON #4080
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Summary of ChangesHello @wlwilliamx, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical compatibility issue in TiCDC's changefeed metadata handling. It ensures seamless operation during mixed-version upgrades or rollbacks by making the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
📝 WalkthroughWalkthroughAdds JSON marshaling and unmarshaling support to ChangeFeedDisplayName to handle backward and forward compatibility. MarshalJSON outputs both "keyspace" and "namespace" fields; UnmarshalJSON accepts either or both, with "keyspace" taking precedence. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
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.
Code Review
This pull request introduces a compatibility layer for ChangeFeedDisplayName to handle both the new keyspace field and the legacy namespace field during JSON serialization and deserialization. This is a solid approach to ensure smooth upgrades and rollbacks between different TiCDC versions. The implementation using custom MarshalJSON and UnmarshalJSON methods is clean, and the accompanying unit tests are thorough, covering all relevant scenarios. I have one minor suggestion to improve code conciseness.
| if decoded.Keyspace != "" { | ||
| r.Keyspace = decoded.Keyspace | ||
| return nil | ||
| } | ||
| r.Keyspace = decoded.Namespace |
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.
The logic for setting r.Keyspace can be made more concise and arguably more readable by removing the conditional early return.
| if decoded.Keyspace != "" { | |
| r.Keyspace = decoded.Keyspace | |
| return nil | |
| } | |
| r.Keyspace = decoded.Namespace | |
| r.Keyspace = decoded.Keyspace | |
| if decoded.Keyspace == "" { | |
| r.Keyspace = decoded.Namespace | |
| } |
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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@pkg/common/types_test.go`:
- Around line 1-8: Add the project's standard copyright header to the top of the
file before the package common declaration; insert the exact header used across
the repo (including year and copyright owner and license notice) above the line
"package common" in types_test.go so the check-copyright CI passes.
| package common | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) |
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.
Add the required copyright header to fix CI.
The pipeline reports check-copyright failure for this file. Please add the standard header at the top.
🛠️ Proposed fix
+// Copyright 2025 PingCAP, Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
package common📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| package common | |
| import ( | |
| "encoding/json" | |
| "testing" | |
| "github.com/stretchr/testify/require" | |
| ) | |
| // Copyright 2025 PingCAP, Inc. | |
| // | |
| // Licensed under the Apache License, Version 2.0 (the "License"); | |
| // you may not use this file except in compliance with the License. | |
| // You may obtain a copy of the License at | |
| // | |
| // http://www.apache.org/licenses/LICENSE-2.0 | |
| // | |
| // Unless required by applicable law or agreed to in writing, software | |
| // distributed under the License is distributed on an "AS IS" BASIS, | |
| // See the License for the specific language governing permissions and | |
| // limitations under the License. | |
| package common | |
| import ( | |
| "encoding/json" | |
| "testing" | |
| "github.com/stretchr/testify/require" | |
| ) |
🧰 Tools
🪛 GitHub Actions: PR Build and Unit Test
[error] 1-1: check-copyright: The copyright information of following files is incorrect: ./pkg/common/types_test.go
🤖 Prompt for AI Agents
In `@pkg/common/types_test.go` around lines 1 - 8, Add the project's standard
copyright header to the top of the file before the package common declaration;
insert the exact header used across the repo (including year and copyright owner
and license notice) above the line "package common" in types_test.go so the
check-copyright CI passes.
| // not make changefeeds "disappear" (e.g., keyspace becomes empty and gets filtered out) | ||
| // or become un-recreatable due to occupied meta keys. To keep metadata compatible across | ||
| // versions, we accept both field names on unmarshal and emit both on marshal. | ||
| type changeFeedDisplayNameJSON struct { |
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.
Rewriting the UnmarshalJSON method is significantly better than defining a new struct.
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.
I already rewrited UnmarshalJSON on ChangeFeedDisplayName. We keep the unexported changeFeedDisplayNameJSON shim only to share the JSON tags between MarshalJSON/UnmarshalJSON (to keep them symmetric and avoid duplication/drift) and to avoid unmarshalling twice.
What problem does this PR solve?
Issue Number: close #4079
What is changed and how it works?
namespacefield when unmarshallingChangeFeedDisplayNameJSON (treat it as an alias ofkeyspace).ChangeFeedDisplayNamewith bothkeyspaceand legacynamespaceto keep metadata readable across versions.Check List
Tests
Manual test: N/A
Questions
Will it cause performance regression or break compatibility?
No. This only changes JSON encoding/decoding for changefeed display name metadata and improves cross-version compatibility.
Do you need to update user documentation, design documentation or monitoring documentation?
No.
Release note
Summary by CodeRabbit
Improvements
Tests
✏️ Tip: You can customize this high-level summary in your review settings.