-
Notifications
You must be signed in to change notification settings - Fork 3.8k
add sequenceName and currentCheckPoint for backwards compatibility #8864
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a92bb41
add sequenceName and currentCheckPoint for backwards compatibility
cecf8de
Add serde unit test in kafka
eb9aa74
Merge branch 'master' of github.com:druid-io/druid into kafka-rolling…
7388323
fix checkstyle
025ed1f
add hashcode
37601ad
Merge branch 'master' of github.com:druid-io/druid into kafka-rolling…
10a520e
Merge branch 'master' of github.com:druid-io/druid into kafka-rolling…
2c37b34
Merge branch 'master' of github.com:druid-io/druid into kafka-rolling…
a73d8c1
update javadoc
fa6df8c
Merge branch 'master' of github.com:druid-io/druid into kafka-rolling…
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
154 changes: 154 additions & 0 deletions
154
...test/java/org/apache/druid/indexing/kafka/KafkaCheckpointDataSourceMetadataSerdeTest.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,154 @@ | ||
| /* | ||
| * 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.druid.indexing.kafka; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.google.common.collect.ImmutableMap; | ||
| import com.google.common.collect.ImmutableSet; | ||
| import org.apache.druid.indexing.common.actions.CheckPointDataSourceMetadataAction; | ||
| import org.apache.druid.indexing.seekablestream.SeekableStreamStartSequenceNumbers; | ||
| import org.apache.druid.jackson.DefaultObjectMapper; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class KafkaCheckpointDataSourceMetadataSerdeTest | ||
| { | ||
| private static final ObjectMapper MAPPER = new DefaultObjectMapper(); | ||
|
|
||
| @Test | ||
| public void testCheckPointDataSourceMetadataActionSerde() throws IOException | ||
| { | ||
| MAPPER.registerSubtypes(KafkaDataSourceMetadata.class); | ||
|
|
||
| final KafkaDataSourceMetadata kafkaDataSourceMetadata = | ||
| new KafkaDataSourceMetadata( | ||
| new SeekableStreamStartSequenceNumbers<>( | ||
| "topic", | ||
| ImmutableMap.of(0, 10L, 1, 20L, 2, 30L), | ||
| ImmutableSet.of() | ||
| ) | ||
| ); | ||
| final CheckPointDataSourceMetadataAction checkpointAction = new CheckPointDataSourceMetadataAction( | ||
| "id_1", | ||
| 1, | ||
| null, | ||
| kafkaDataSourceMetadata | ||
| ); | ||
|
|
||
| final String serialized = MAPPER.writeValueAsString(checkpointAction); | ||
| final CheckPointDataSourceMetadataAction deserialized = MAPPER.readValue( | ||
| serialized, | ||
| CheckPointDataSourceMetadataAction.class | ||
| ); | ||
| Assert.assertEquals(checkpointAction, deserialized); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCheckPointDataSourceMetadataActionOldJsonSerde() throws IOException | ||
| { | ||
| MAPPER.registerSubtypes(KafkaDataSourceMetadata.class); | ||
| final String jsonStr = "{\n" | ||
| + "\t\"type\": \"checkPointDataSourceMetadata\",\n" | ||
| + "\t\"supervisorId\": \"id_1\",\n" | ||
| + "\t\"taskGroupId\": 1,\n" | ||
| + "\t\"previousCheckPoint\": {\n" | ||
| + "\t\t\"type\": \"KafkaDataSourceMetadata\",\n" | ||
| + "\t\t\"partitions\": {\n" | ||
| + "\t\t\t\"type\": \"start\",\n" | ||
| + "\t\t\t\"stream\": \"topic\",\n" | ||
| + "\t\t\t\"topic\": \"topic\",\n" | ||
| + "\t\t\t\"partitionSequenceNumberMap\": {\n" | ||
| + "\t\t\t\t\"0\": 10,\n" | ||
| + "\t\t\t\t\"1\": 20,\n" | ||
| + "\t\t\t\t\"2\": 30\n" | ||
| + "\t\t\t},\n" | ||
| + "\t\t\t\"partitionOffsetMap\": {\n" | ||
| + "\t\t\t\t\"0\": 10,\n" | ||
| + "\t\t\t\t\"1\": 20,\n" | ||
| + "\t\t\t\t\"2\": 30\n" | ||
| + "\t\t\t},\n" | ||
| + "\t\t\t\"exclusivePartitions\": []\n" | ||
| + "\t\t}\n" | ||
| + "\t},\n" | ||
| + "\t\"checkpointMetadata\": {\n" | ||
| + "\t\t\"type\": \"KafkaDataSourceMetadata\",\n" | ||
| + "\t\t\"partitions\": {\n" | ||
| + "\t\t\t\"type\": \"start\",\n" | ||
| + "\t\t\t\"stream\": \"topic\",\n" | ||
| + "\t\t\t\"topic\": \"topic\",\n" | ||
| + "\t\t\t\"partitionSequenceNumberMap\": {\n" | ||
| + "\t\t\t\t\"0\": 10,\n" | ||
| + "\t\t\t\t\"1\": 20,\n" | ||
| + "\t\t\t\t\"2\": 30\n" | ||
| + "\t\t\t},\n" | ||
| + "\t\t\t\"partitionOffsetMap\": {\n" | ||
| + "\t\t\t\t\"0\": 10,\n" | ||
| + "\t\t\t\t\"1\": 20,\n" | ||
| + "\t\t\t\t\"2\": 30\n" | ||
| + "\t\t\t},\n" | ||
| + "\t\t\t\"exclusivePartitions\": []\n" | ||
| + "\t\t}\n" | ||
| + "\t},\n" | ||
| + "\t\"currentCheckPoint\": {\n" | ||
| + "\t\t\"type\": \"KafkaDataSourceMetadata\",\n" | ||
| + "\t\t\"partitions\": {\n" | ||
| + "\t\t\t\"type\": \"start\",\n" | ||
| + "\t\t\t\"stream\": \"topic\",\n" | ||
| + "\t\t\t\"topic\": \"topic\",\n" | ||
| + "\t\t\t\"partitionSequenceNumberMap\": {\n" | ||
| + "\t\t\t\t\"0\": 10,\n" | ||
| + "\t\t\t\t\"1\": 20,\n" | ||
| + "\t\t\t\t\"2\": 30\n" | ||
| + "\t\t\t},\n" | ||
| + "\t\t\t\"partitionOffsetMap\": {\n" | ||
| + "\t\t\t\t\"0\": 10,\n" | ||
| + "\t\t\t\t\"1\": 20,\n" | ||
| + "\t\t\t\t\"2\": 30\n" | ||
| + "\t\t\t},\n" | ||
| + "\t\t\t\"exclusivePartitions\": []\n" | ||
| + "\t\t}\n" | ||
| + "\t},\n" | ||
| + "\t\"sequenceName\": \"dummy\"\n" | ||
| + "}"; | ||
|
|
||
| final CheckPointDataSourceMetadataAction actual = MAPPER.readValue( | ||
| jsonStr, | ||
| CheckPointDataSourceMetadataAction.class | ||
| ); | ||
|
|
||
| KafkaDataSourceMetadata kafkaDataSourceMetadata = | ||
| new KafkaDataSourceMetadata( | ||
| new SeekableStreamStartSequenceNumbers<>( | ||
| "topic", | ||
| ImmutableMap.of(0, 10L, 1, 20L, 2, 30L), | ||
| ImmutableSet.of() | ||
| ) | ||
| ); | ||
| CheckPointDataSourceMetadataAction checkpointAction = new CheckPointDataSourceMetadataAction( | ||
| "id_1", | ||
| 1, | ||
| kafkaDataSourceMetadata, | ||
| kafkaDataSourceMetadata | ||
| ); | ||
| Assert.assertEquals(checkpointAction, actual); | ||
| } | ||
| } |
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 |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
| import org.apache.druid.indexing.seekablestream.SeekableStreamStartSequenceNumbers; | ||
|
|
||
| import javax.annotation.Nullable; | ||
| import java.util.Objects; | ||
|
|
||
| public class CheckPointDataSourceMetadataAction implements TaskAction<Boolean> | ||
| { | ||
|
|
@@ -68,13 +69,34 @@ public Integer getTaskGroupId() | |
| } | ||
|
|
||
| // For backwards compatibility | ||
| @Deprecated | ||
| @JsonProperty | ||
| public SeekableStreamDataSourceMetadata getPreviousCheckPoint() | ||
| private SeekableStreamDataSourceMetadata getPreviousCheckPoint() | ||
| { | ||
| return checkpointMetadata; | ||
| } | ||
|
|
||
| // For backwards compatibility | ||
| @JsonProperty | ||
| private SeekableStreamDataSourceMetadata getCurrentCheckPoint() | ||
| { | ||
| return checkpointMetadata; | ||
| } | ||
|
|
||
| /** | ||
| * This method is for backwards compatibility to add the missing property (sequenceName) in serialized JSON, | ||
| * so rolling-updates from older versions are compatible, a dummy value is returned since the value is not | ||
| * used in any production code as long as the json property is present | ||
| * | ||
| * TODO : this should be removed when we don't need rolling-update compatibility with version 0.15 or earlier anymore | ||
| * | ||
| * @return dummy value | ||
| */ | ||
| @JsonProperty("sequenceName") | ||
| private String getBaseSequenceName() | ||
| { | ||
| return "dummy"; | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public SeekableStreamDataSourceMetadata getCheckpointMetadata() | ||
| { | ||
|
|
@@ -114,4 +136,39 @@ public String toString() | |
| ", checkpointMetadata=" + checkpointMetadata + | ||
| '}'; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you have an override for FYI, the SonarLint intellij plugin will give you a warning if you don't override both. While typing this, I just noticed LGTM flagged the same issue. |
||
| { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
|
|
||
| CheckPointDataSourceMetadataAction that = (CheckPointDataSourceMetadataAction) o; | ||
| if (!supervisorId.equals(that.supervisorId)) { | ||
| return false; | ||
| } | ||
| if (taskGroupId != that.taskGroupId) { | ||
| return false; | ||
| } | ||
|
|
||
| if (!Objects.equals(checkpointMetadata, that.checkpointMetadata)) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() | ||
| { | ||
| return Objects.hash( | ||
| supervisorId, | ||
| taskGroupId, | ||
| checkpointMetadata | ||
| ); | ||
| } | ||
|
|
||
| } | ||
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.
Can add a unit test for the serialization/deserialization between old and new DTOs
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.
yeah, was trying to add a serde test for
CheckPointDataSourceMetadataAction, but wasn't easy to construct an object because of abstractSeekableStreamDataSourceMetadatain this package.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.
One option is to manually create a JSON string and then deserialize it to a different version. If you don't want to manually create the JSON, then one option is to add a class in the test file that is the old DTO.
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.
Added a serde test for kafka