GeezerVison is showing github.com — KAFKA-21379: Add mirror coordinator record schemas and serde (#23979) · coderbruis/kafka@bac5858
File treeExpand file treeCollapse file tree Open diff view settings main/java/org/apache/kafka/message test/java/org/apache/kafka/message
java/org/apache/kafka/coordinator/mirror
test/java/org/apache/kafka/coordinator/mirror
server/src/test/java/org/apache/kafka/server/mirror
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: build.gradle +37Lines changed: 37 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1071,6 +1071,7 @@ project(':server') { | 1071 | 1071 | implementation log4j2Libs | 1072 | 1072 |
| 1073 | 1073 | testImplementation testFixtures(project(':clients')) | | 1074 | + testImplementation project(':coordinator-common') | 1074 | 1075 | testImplementation libs.mockitoCore | 1075 | 1076 | testImplementation libs.junitJupiter | 1076 | 1077 | testImplementation testLog4j2Libs | @@ -1979,20 +1980,56 @@ project(':mirror-coordinator') { | 1979 | 1980 | archivesName = "kafka-mirror-coordinator" | 1980 | 1981 | } | 1981 | 1982 |
| | 1983 | + configurations { | | 1984 | + generator | | 1985 | + } | | 1986 | + | 1982 | 1987 | dependencies { | | 1988 | + implementation libs.jacksonDatabind | 1983 | 1989 | implementation project(':clients') | | 1990 | + implementation project(':coordinator-common') | 1984 | 1991 |
| | 1992 | + testImplementation project(':server-common') | 1985 | 1993 | testImplementation libs.junitJupiter | 1986 | 1994 | testImplementation libs.mockitoCore | 1987 | 1995 | testImplementation testLog4j2Libs | 1988 | 1996 |
| 1989 | 1997 | testRuntimeOnly runtimeTestLibs | | 1998 | + | | 1999 | + generator project(':generator') | | 2000 | + } | | 2001 | + | | 2002 | + sourceSets { | | 2003 | + main { | | 2004 | + java { | | 2005 | + srcDirs = ["src/main/java", "${projectDir}/build/generated/main/java"] | | 2006 | + } | | 2007 | + } | 1990 | 2008 | } | 1991 | 2009 |
| 1992 | 2010 | checkstyle { | 1993 | 2011 | configProperties = checkstyleConfigProperties("import-control-mirror-coordinator.xml") | 1994 | 2012 | } | 1995 | 2013 |
| | 2014 | + tasks.register('processMessages', JavaExec) { | | 2015 | + mainClass = "org.apache.kafka.message.MessageGenerator" | | 2016 | + classpath = configurations.generator | | 2017 | + args = [ "-p", "org.apache.kafka.coordinator.mirror.generated", | | 2018 | + "-o", "${projectDir}/build/generated/main/java/org/apache/kafka/coordinator/mirror/generated", | | 2019 | + "-i", "src/main/resources/common/message", | | 2020 | + "-m", "MessageDataGenerator", "JsonConverterGenerator", | | 2021 | + "-t", "CoordinatorRecordTypeGenerator", "CoordinatorRecordJsonConvertersGenerator" | | 2022 | + ] | | 2023 | + inputs.dir("src/main/resources/common/message") | | 2024 | + .withPropertyName("messages") | | 2025 | + .withPathSensitivity(PathSensitivity.RELATIVE) | | 2026 | + outputs.cacheIf { true } | | 2027 | + outputs.dir("${projectDir}/build/generated/main/java/org/apache/kafka/coordinator/mirror/generated") | | 2028 | + } | | 2029 | + | | 2030 | + compileJava.dependsOn 'processMessages' | | 2031 | + srcJar.dependsOn 'processMessages' | | 2032 | + | 1996 | 2033 | javadoc { | 1997 | 2034 | enabled = false | 1998 | 2035 | } | |
Collapse file Copy file name to clipboardExpand all lines: checkstyle/import-control-mirror-coordinator.xml +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 30 | 30 | <!-- anyone can use public classes --> | 31 | 31 | <allow pkg="org.apache.kafka.common" exact-match="true" /> | 32 | 32 | <allow pkg="org.apache.kafka.common.config" /> | | 33 | + <allow pkg="org.apache.kafka.common.errors" exact-match="true" /> | | 34 | + <allow pkg="org.apache.kafka.common.protocol" /> | 33 | 35 | <allow pkg="org.apache.kafka.common.utils" /> | 34 | 36 |
| 35 | 37 | <subpackage name="coordinator"> | 36 | 38 | <subpackage name="mirror"> | | 39 | + <allow pkg="org.apache.kafka.coordinator.common.runtime" /> | 37 | 40 | <allow pkg="org.apache.kafka.coordinator.mirror" /> | | 41 | + <allow pkg="org.apache.kafka.server.common" /> | | 42 | + <allow pkg="org.junit.jupiter.api" /> | | 43 | + <allow pkg="org.junit.jupiter.params" /> | | 44 | + <subpackage name="generated"> | | 45 | + <allow pkg="com.fasterxml.jackson" /> | | 46 | + </subpackage> | 38 | 47 | </subpackage> | 39 | 48 | </subpackage> | 40 | 49 | </import-control> |
Collapse file Copy file name to clipboardExpand all lines: generator/src/main/java/org/apache/kafka/message/EntityType.java +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -36,7 +36,10 @@ public enum EntityType { | 36 | 36 | TOPIC_NAME(FieldType.StringFieldType.INSTANCE), | 37 | 37 |
| 38 | 38 | @JsonProperty("brokerId") | 39 | | - BROKER_ID(FieldType.Int32FieldType.INSTANCE); | | 39 | + BROKER_ID(FieldType.Int32FieldType.INSTANCE), | | 40 | + | | 41 | + @JsonProperty("mirrorName") | | 42 | + MIRROR_NAME(FieldType.StringFieldType.INSTANCE); | 40 | 43 |
| 41 | 44 | private final FieldType baseType; | 42 | 45 |
| |
Collapse file Copy file name to clipboardExpand all lines: generator/src/test/java/org/apache/kafka/message/EntityTypeTest.java +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -60,6 +60,10 @@ public void testVerifyTypeMatches() { | 60 | 60 | FieldType.Int32FieldType.INSTANCE); | 61 | 61 | EntityType.BROKER_ID.verifyTypeMatches("brokerIdField", | 62 | 62 | new FieldType.ArrayType(FieldType.Int32FieldType.INSTANCE)); | | 63 | + EntityType.MIRROR_NAME.verifyTypeMatches("mirrorNameField", | | 64 | + FieldType.StringFieldType.INSTANCE); | | 65 | + EntityType.MIRROR_NAME.verifyTypeMatches("mirrorNameField", | | 66 | + new FieldType.ArrayType(FieldType.StringFieldType.INSTANCE)); | 63 | 67 | } | 64 | 68 |
| 65 | 69 | private static void expectException(Runnable r) { | @@ -79,5 +83,7 @@ public void testVerifyTypeMismatches() { | 79 | 83 | new FieldType.ArrayType(FieldType.Int64FieldType.INSTANCE))); | 80 | 84 | expectException(() -> EntityType.BROKER_ID. | 81 | 85 | verifyTypeMatches("brokerIdField", FieldType.Int64FieldType.INSTANCE)); | | 86 | + expectException(() -> EntityType.MIRROR_NAME. | | 87 | + verifyTypeMatches("mirrorNameField", FieldType.Int32FieldType.INSTANCE)); | 82 | 88 | } | 83 | 89 | } |
Collapse file Copy file name to clipboard +46Lines changed: 46 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +/* | | 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more | | 3 | + * contributor license agreements. See the NOTICE file distributed with | | 4 | + * this work for additional information regarding copyright ownership. | | 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 | | 6 | + * (the "License"); you may not use this file except in compliance with | | 7 | + * the License. You may obtain a copy of the License at | | 8 | + * | | 9 | + * http://www.apache.org/licenses/LICENSE-2.0 | | 10 | + * | | 11 | + * Unless required by applicable law or agreed to in writing, software | | 12 | + * distributed under the License is distributed on an "AS IS" BASIS, | | 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 14 | + * See the License for the specific language governing permissions and | | 15 | + * limitations under the License. | | 16 | + */ | | 17 | + | | 18 | +package org.apache.kafka.coordinator.mirror; | | 19 | + | | 20 | +import org.apache.kafka.common.errors.UnsupportedVersionException; | | 21 | +import org.apache.kafka.common.protocol.ApiMessage; | | 22 | +import org.apache.kafka.coordinator.common.runtime.CoordinatorRecordSerde; | | 23 | +import org.apache.kafka.coordinator.mirror.generated.CoordinatorRecordType; | | 24 | + | | 25 | +/** | | 26 | + * Serializer/deserializer for records stored in the {@code __mirror_state} topic. | | 27 | + */ | | 28 | +public class MirrorCoordinatorRecordSerde extends CoordinatorRecordSerde { | | 29 | + @Override | | 30 | + protected ApiMessage apiMessageKeyFor(short recordType) { | | 31 | + try { | | 32 | + return CoordinatorRecordType.fromId(recordType).newRecordKey(); | | 33 | + } catch (UnsupportedVersionException ex) { | | 34 | + throw new UnknownRecordTypeException(recordType); | | 35 | + } | | 36 | + } | | 37 | + | | 38 | + @Override | | 39 | + protected ApiMessage apiMessageValueFor(short recordType) { | | 40 | + try { | | 41 | + return CoordinatorRecordType.fromId(recordType).newRecordValue(); | | 42 | + } catch (UnsupportedVersionException ex) { | | 43 | + throw new UnknownRecordTypeException(recordType); | | 44 | + } | | 45 | + } | | 46 | +} |
Collapse file Copy file name to clipboard +30Lines changed: 30 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// Licensed to the Apache Software Foundation (ASF) under one or more | | 2 | +// contributor license agreements. See the NOTICE file distributed with | | 3 | +// this work for additional information regarding copyright ownership. | | 4 | +// The ASF licenses this file to You under the Apache License, Version 2.0 | | 5 | +// (the "License"); you may not use this file except in compliance with | | 6 | +// the License. You may obtain a copy of the License at | | 7 | +// | | 8 | +// http://www.apache.org/licenses/LICENSE-2.0 | | 9 | +// | | 10 | +// Unless required by applicable law or agreed to in writing, software | | 11 | +// distributed under the License is distributed on an "AS IS" BASIS, | | 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 13 | +// See the License for the specific language governing permissions and | | 14 | +// limitations under the License. | | 15 | + | | 16 | +{ | | 17 | + "apiKey": 1, | | 18 | + "type": "coordinator-key", | | 19 | + "name": "LastMirrorEpochsKey", | | 20 | + "validVersions": "0", | | 21 | + "flexibleVersions": "none", | | 22 | + "fields": [ | | 23 | + { "name": "MirrorName", "type": "string", "versions": "0+", "entityType": "mirrorName", | | 24 | + "about": "The cluster mirror name." }, | | 25 | + { "name": "TopicId", "type": "uuid", "versions": "0+", | | 26 | + "about": "The topic ID." }, | | 27 | + { "name": "Partition", "type": "int32", "versions": "0+", | | 28 | + "about": "The partition index." } | | 29 | + ] | | 30 | +} |
Collapse file Copy file name to clipboard +28Lines changed: 28 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// Licensed to the Apache Software Foundation (ASF) under one or more | | 2 | +// contributor license agreements. See the NOTICE file distributed with | | 3 | +// this work for additional information regarding copyright ownership. | | 4 | +// The ASF licenses this file to You under the Apache License, Version 2.0 | | 5 | +// (the "License"); you may not use this file except in compliance with | | 6 | +// the License. You may obtain a copy of the License at | | 7 | +// | | 8 | +// http://www.apache.org/licenses/LICENSE-2.0 | | 9 | +// | | 10 | +// Unless required by applicable law or agreed to in writing, software | | 11 | +// distributed under the License is distributed on an "AS IS" BASIS, | | 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 13 | +// See the License for the specific language governing permissions and | | 14 | +// limitations under the License. | | 15 | + | | 16 | +{ | | 17 | + "apiKey": 1, | | 18 | + "type": "coordinator-value", | | 19 | + "name": "LastMirrorEpochsValue", | | 20 | + "validVersions": "0", | | 21 | + "flexibleVersions": "0+", | | 22 | + "fields": [ | | 23 | + { "name": "LastMirrorEpoch", "type": "int32", "versions": "0+", "default": "-1", | | 24 | + "about": "The last mirror leader epoch for this partition." }, | | 25 | + { "name": "LastMirrorOffset", "type": "int64", "versions": "0+", "default": "-1", | | 26 | + "about": "The last mirror offset for this partition." } | | 27 | + ] | | 28 | +} |
Collapse file Copy file name to clipboard +30Lines changed: 30 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// Licensed to the Apache Software Foundation (ASF) under one or more | | 2 | +// contributor license agreements. See the NOTICE file distributed with | | 3 | +// this work for additional information regarding copyright ownership. | | 4 | +// The ASF licenses this file to You under the Apache License, Version 2.0 | | 5 | +// (the "License"); you may not use this file except in compliance with | | 6 | +// the License. You may obtain a copy of the License at | | 7 | +// | | 8 | +// http://www.apache.org/licenses/LICENSE-2.0 | | 9 | +// | | 10 | +// Unless required by applicable law or agreed to in writing, software | | 11 | +// distributed under the License is distributed on an "AS IS" BASIS, | | 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 13 | +// See the License for the specific language governing permissions and | | 14 | +// limitations under the License. | | 15 | + | | 16 | +{ | | 17 | + "apiKey": 0, | | 18 | + "type": "coordinator-key", | | 19 | + "name": "MirrorPartitionStateKey", | | 20 | + "validVersions": "0", | | 21 | + "flexibleVersions": "none", | | 22 | + "fields": [ | | 23 | + { "name": "MirrorName", "type": "string", "versions": "0+", "entityType": "mirrorName", | | 24 | + "about": "The cluster mirror name." }, | | 25 | + { "name": "TopicId", "type": "uuid", "versions": "0+", | | 26 | + "about": "The topic ID." }, | | 27 | + { "name": "Partition", "type": "int32", "versions": "0+", | | 28 | + "about": "The partition index." } | | 29 | + ] | | 30 | +} |
Collapse file Copy file name to clipboard +36Lines changed: 36 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// Licensed to the Apache Software Foundation (ASF) under one or more | | 2 | +// contributor license agreements. See the NOTICE file distributed with | | 3 | +// this work for additional information regarding copyright ownership. | | 4 | +// The ASF licenses this file to You under the Apache License, Version 2.0 | | 5 | +// (the "License"); you may not use this file except in compliance with | | 6 | +// the License. You may obtain a copy of the License at | | 7 | +// | | 8 | +// http://www.apache.org/licenses/LICENSE-2.0 | | 9 | +// | | 10 | +// Unless required by applicable law or agreed to in writing, software | | 11 | +// distributed under the License is distributed on an "AS IS" BASIS, | | 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 13 | +// See the License for the specific language governing permissions and | | 14 | +// limitations under the License. | | 15 | + | | 16 | +{ | | 17 | + "apiKey": 0, | | 18 | + "type": "coordinator-value", | | 19 | + "name": "MirrorPartitionStateValue", | | 20 | + "validVersions": "0", | | 21 | + "flexibleVersions": "0+", | | 22 | + "fields": [ | | 23 | + { "name": "State", "type": "int8", "versions": "0+", | | 24 | + "about": "The mirror partition state." }, | | 25 | + { "name": "LeaderEpoch", "type": "int32", "versions": "0+", "default": "-1", | | 26 | + "about": "The highest leader epoch seen for the partition, or -1 if not available." }, | | 27 | + { "name": "StateEpoch", "type": "int32", "versions": "0+", "default": "0", | | 28 | + "about": "Monotonically increasing epoch incremented on every state transition." }, | | 29 | + { "name": "ErrorMessage", "type": "string", "versions": "0+", "nullableVersions": "0+", "default": "null", | | 30 | + "about": "The error message when in FAILED state, or null if not applicable." }, | | 31 | + { "name": "RetryAttempt", "type": "int16", "versions": "0+", "default": "0", | | 32 | + "about": "The number of automatic retry attempts while in FAILED state, or -1 for non-retryable failure." }, | | 33 | + { "name": "PreviousState", "type": "int8", "versions": "0+", "default": "-1", | | 34 | + "about": "The mirror partition state before this transition; UNKNOWN if not recorded." } | | 35 | + ] | | 36 | +} |
|