Skip to content

Conversation

@hangc0276
Copy link
Contributor

Motivation

When checking a partitioned topic whether a system topic, it will always be false. The check logic is.

static boolean isSystemTopic(TopicName topicName) {
        return EventsTopicNames.NAMESPACE_EVENTS_LOCAL_NAME.equals(topicName.getLocalName());
    }
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.


static boolean isSystemTopic(TopicName topicName) {
return EventsTopicNames.NAMESPACE_EVENTS_LOCAL_NAME.equals(topicName.getLocalName());
String localName = topicName.getLocalName();
Copy link
Contributor

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);

Copy link
Contributor

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);

Copy link
Contributor

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());

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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()

Copy link
Contributor

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());
}

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@codelipenghui codelipenghui added type/bug The PR fixed a bug or issue reported a bug release/2.7.3 labels May 11, 2021
@codelipenghui codelipenghui added this to the 2.8.0 milestone May 11, 2021
Copy link
Contributor

@315157973 315157973 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@dockerzhang dockerzhang left a comment

Choose a reason for hiding this comment

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

+1

@codelipenghui codelipenghui merged commit 4a8d40c into apache:master May 15, 2021
codelipenghui pushed a commit that referenced this pull request Jun 26, 2021
### 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)
@codelipenghui codelipenghui added the cherry-picked/branch-2.7 Archived: 2.7 is end of life label Jun 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-picked/branch-2.7 Archived: 2.7 is end of life release/2.7.3 type/bug The PR fixed a bug or issue reported a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants