-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Fix partitioned system topic check bug #10529
Fix partitioned system topic check bug #10529
Conversation
@@ -168,7 +168,10 @@ | |||
} | |||
|
|||
static boolean isSystemTopic(TopicName topicName) { | |||
return EventsTopicNames.NAMESPACE_EVENTS_LOCAL_NAME.equals(topicName.getLocalName()); | |||
String localName = topicName.getLocalName(); |
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.
what about
topicName.getLocalName().startsWith(EventsTopicNames.NAMESPACE_EVENTS_LOCAL_NAME);
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.
+1
return topicName != null && topicName.getLocalName().startsWith(EventsTopicNames.NAMESPACE_EVENTS_LOCAL_NAME);
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.
or
return EventsTopicNames.NAMESPACE_EVENTS_LOCAL_NAME.equals(topicName.getPartitionedTopicName());
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.
what about
topicName.getLocalName().startsWith(EventsTopicNames.NAMESPACE_EVENTS_LOCAL_NAME);
@linlinnn if the topic name is __change_events_v1, using startsWith, it will return true
. However it isn't system topic.
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.
or
return EventsTopicNames.NAMESPACE_EVENTS_LOCAL_NAME.equals(topicName.getPartitionedTopicName());
@315157973 topicName.getPartitionedTopicName() method will return topic name with prefix, such as, persistent://public/defualt/__change_events
, it will always return false
.
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.
TopicName.get(topicName.getPartitionedTopicName()).getLocalName()
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.
We have a method in the TopicName is isPartitioned()
. You can check as followings
if (topicName.isPartitioned()) {
return EventsTopicNames.NAMESPACE_EVENTS_LOCAL_NAME.equals(TopicName.get(topicName.getPartitionedTopicName));
} else {
return
EventsTopicNames.NAMESPACE_EVENTS_LOCAL_NAME.equals(topicName.getLocalName());
}
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.
@315157973 good job. I have update the code, PTAL.
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.
@codelipenghui I have update the code, PTAL.
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.
LGTM
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.
+1
### Motivation When checking a partitioned topic whether a system topic, it will always be `false`. The check logic is. ```Java static boolean isSystemTopic(TopicName topicName) { return EventsTopicNames.NAMESPACE_EVENTS_LOCAL_NAME.equals(topicName.getLocalName()); } ``` ```Java public static final String NAMESPACE_EVENTS_LOCAL_NAME = "__change_events"; ``` The partitioned topic name is like `__change_events-partition-0`. ### Modification 1. Trim the partition suffix for the topic local name if exists. 2. Add a test to cover this case. (cherry picked from commit 4a8d40c)
Motivation
When checking a partitioned topic whether a system topic, it will always be
false
. The check logic is.The partitioned topic name is like
__change_events-partition-0
.Modification