-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Introduce TopicPartitionId composite key for LLC segment partition id #18913
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
Open
rseetham
wants to merge
1
commit into
apache:master
Choose a base branch
from
rseetham:multi-topic-segment-name
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
pinot-common/src/main/java/org/apache/pinot/common/utils/TopicPartitionId.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you 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, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.pinot.common.utils; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
|
|
||
| /** | ||
| * Identifies a partition within a (possibly multi-topic) real-time table. | ||
| * | ||
| * <p>For single-topic tables, {@code topicId} is 0 and {@code partitionId} is the stream partition number. | ||
| * For multi-topic tables, {@code topicId} distinguishes the topic and {@code partitionId} is the stream partition | ||
| * number within that topic. | ||
| * | ||
| * <p>Thread-safe: instances are immutable. | ||
| */ | ||
| public final class TopicPartitionId implements Comparable<TopicPartitionId> { | ||
| private final int _topicId; | ||
| private final int _partitionId; | ||
|
|
||
| public TopicPartitionId(int topicId, int partitionId) { | ||
| _topicId = topicId; | ||
| _partitionId = partitionId; | ||
| } | ||
|
|
||
| public TopicPartitionId(int partitionId) { | ||
| this(0, partitionId); | ||
| } | ||
|
|
||
| public int getTopicId() { | ||
| return _topicId; | ||
| } | ||
|
|
||
| public int getPartitionId() { | ||
| return _partitionId; | ||
| } | ||
|
|
||
| @Override | ||
| public int compareTo(TopicPartitionId other) { | ||
| int cmp = Integer.compare(_topicId, other._topicId); | ||
| return cmp != 0 ? cmp : Integer.compare(_partitionId, other._partitionId); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (!(o instanceof TopicPartitionId)) { | ||
| return false; | ||
| } | ||
| TopicPartitionId that = (TopicPartitionId) o; | ||
| return _topicId == that._topicId && _partitionId == that._partitionId; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(_topicId, _partitionId); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return _topicId + ":" + _partitionId; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
pinot-common/src/test/java/org/apache/pinot/common/utils/TopicPartitionIdTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you 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, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.pinot.common.utils; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import static org.testng.Assert.assertEquals; | ||
| import static org.testng.Assert.assertFalse; | ||
| import static org.testng.Assert.assertNotEquals; | ||
| import static org.testng.Assert.assertTrue; | ||
|
|
||
|
|
||
| public class TopicPartitionIdTest { | ||
|
|
||
| @Test | ||
| public void testSingleArgConstructor() { | ||
| TopicPartitionId id = new TopicPartitionId(5); | ||
| assertEquals(id.getTopicId(), 0); | ||
| assertEquals(id.getPartitionId(), 5); | ||
| } | ||
|
|
||
| @Test | ||
| public void testTwoArgConstructor() { | ||
| TopicPartitionId id = new TopicPartitionId(2, 7); | ||
| assertEquals(id.getTopicId(), 2); | ||
| assertEquals(id.getPartitionId(), 7); | ||
| } | ||
|
|
||
| @Test | ||
| public void testEquality() { | ||
| TopicPartitionId id1 = new TopicPartitionId(1, 3); | ||
| TopicPartitionId id2 = new TopicPartitionId(1, 3); | ||
| TopicPartitionId id3 = new TopicPartitionId(1, 4); | ||
| TopicPartitionId id4 = new TopicPartitionId(2, 3); | ||
|
|
||
| assertEquals(id1, id2); | ||
| assertEquals(id1.hashCode(), id2.hashCode()); | ||
| assertNotEquals(id1, id3); | ||
| assertNotEquals(id1, id4); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSingleArgEqualsZeroTopic() { | ||
| TopicPartitionId id1 = new TopicPartitionId(5); | ||
| TopicPartitionId id2 = new TopicPartitionId(0, 5); | ||
| assertEquals(id1, id2); | ||
| assertEquals(id1.hashCode(), id2.hashCode()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCompareTo() { | ||
| TopicPartitionId a = new TopicPartitionId(0, 1); | ||
| TopicPartitionId b = new TopicPartitionId(0, 2); | ||
| TopicPartitionId c = new TopicPartitionId(1, 0); | ||
| TopicPartitionId d = new TopicPartitionId(1, 1); | ||
|
|
||
| assertTrue(a.compareTo(b) < 0); | ||
| assertTrue(b.compareTo(a) > 0); | ||
| assertTrue(a.compareTo(c) < 0); | ||
| assertTrue(c.compareTo(d) < 0); | ||
| assertEquals(a.compareTo(new TopicPartitionId(0, 1)), 0); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAsMapKey() { | ||
| Map<TopicPartitionId, String> map = new HashMap<>(); | ||
| TopicPartitionId id1 = new TopicPartitionId(1, 3); | ||
| map.put(id1, "value1"); | ||
|
|
||
| TopicPartitionId id2 = new TopicPartitionId(1, 3); | ||
| assertEquals(map.get(id2), "value1"); | ||
|
|
||
| assertFalse(map.containsKey(new TopicPartitionId(1, 4))); | ||
| assertFalse(map.containsKey(new TopicPartitionId(2, 3))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testToString() { | ||
| TopicPartitionId id = new TopicPartitionId(2, 7); | ||
| assertEquals(id.toString(), "2:7"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Suggest directly adding
int _topicIdinstead of wrapping it in a separate wrapper. I don't see much value added in this wrapperThe core logic is to parse the segment name with and without topic id