GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — KAFKA-21379: Add mirror coordinator record schemas and serde (#23979) · coderbruis/kafka@bac5858

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • build.gradle
  • checkstyle
    • import-control-mirror-coordinator.xml
  • generator/src
    • main/java/org/apache/kafka/message
      • EntityType.java
    • test/java/org/apache/kafka/message
      • EntityTypeTest.java
  • mirror-coordinator/src
    • main
      • java/org/apache/kafka/coordinator/mirror
        • MirrorCoordinatorRecordSerde.java
      • resources/common/message
        • LastMirrorEpochsKey.json
        • LastMirrorEpochsValue.json
        • MirrorPartitionStateKey.json
        • MirrorPartitionStateValue.json
    • test/java/org/apache/kafka/coordinator/mirror
      • MirrorCoordinatorRecordSerdeTest.java
  • server/src/test/java/org/apache/kafka/server/mirror
    • MirrorCoordinatorRecordSerdeIntegrationTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎build.gradle‎

Copy file name to clipboardExpand all lines: build.gradle
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,7 @@ project(':server') {
10711071
implementation log4j2Libs
10721072

10731073
testImplementation testFixtures(project(':clients'))
1074+
testImplementation project(':coordinator-common')
10741075
testImplementation libs.mockitoCore
10751076
testImplementation libs.junitJupiter
10761077
testImplementation testLog4j2Libs
@@ -1979,20 +1980,56 @@ project(':mirror-coordinator') {
19791980
archivesName = "kafka-mirror-coordinator"
19801981
}
19811982

1983+
configurations {
1984+
generator
1985+
}
1986+
19821987
dependencies {
1988+
implementation libs.jacksonDatabind
19831989
implementation project(':clients')
1990+
implementation project(':coordinator-common')
19841991

1992+
testImplementation project(':server-common')
19851993
testImplementation libs.junitJupiter
19861994
testImplementation libs.mockitoCore
19871995
testImplementation testLog4j2Libs
19881996

19891997
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+
}
19902008
}
19912009

19922010
checkstyle {
19932011
configProperties = checkstyleConfigProperties("import-control-mirror-coordinator.xml")
19942012
}
19952013

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+
19962033
javadoc {
19972034
enabled = false
19982035
}
Collapse file

‎checkstyle/import-control-mirror-coordinator.xml‎

Copy file name to clipboardExpand all lines: checkstyle/import-control-mirror-coordinator.xml
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,20 @@
3030
<!-- anyone can use public classes -->
3131
<allow pkg="org.apache.kafka.common" exact-match="true" />
3232
<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" />
3335
<allow pkg="org.apache.kafka.common.utils" />
3436

3537
<subpackage name="coordinator">
3638
<subpackage name="mirror">
39+
<allow pkg="org.apache.kafka.coordinator.common.runtime" />
3740
<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>
3847
</subpackage>
3948
</subpackage>
4049
</import-control>
Collapse file

‎generator/src/main/java/org/apache/kafka/message/EntityType.java‎

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 numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ public enum EntityType {
3636
TOPIC_NAME(FieldType.StringFieldType.INSTANCE),
3737

3838
@JsonProperty("brokerId")
39-
BROKER_ID(FieldType.Int32FieldType.INSTANCE);
39+
BROKER_ID(FieldType.Int32FieldType.INSTANCE),
40+
41+
@JsonProperty("mirrorName")
42+
MIRROR_NAME(FieldType.StringFieldType.INSTANCE);
4043

4144
private final FieldType baseType;
4245

Collapse file

‎generator/src/test/java/org/apache/kafka/message/EntityTypeTest.java‎

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 numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public void testVerifyTypeMatches() {
6060
FieldType.Int32FieldType.INSTANCE);
6161
EntityType.BROKER_ID.verifyTypeMatches("brokerIdField",
6262
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));
6367
}
6468

6569
private static void expectException(Runnable r) {
@@ -79,5 +83,7 @@ public void testVerifyTypeMismatches() {
7983
new FieldType.ArrayType(FieldType.Int64FieldType.INSTANCE)));
8084
expectException(() -> EntityType.BROKER_ID.
8185
verifyTypeMatches("brokerIdField", FieldType.Int64FieldType.INSTANCE));
86+
expectException(() -> EntityType.MIRROR_NAME.
87+
verifyTypeMatches("mirrorNameField", FieldType.Int32FieldType.INSTANCE));
8288
}
8389
}
Collapse file

‎mirror-coordinator/src/main/java/org/apache/kafka/coordinator/mirror/MirrorCoordinatorRecordSerde.java‎

Copy file name to clipboard
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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

‎mirror-coordinator/src/main/resources/common/message/LastMirrorEpochsKey.json‎

Copy file name to clipboard
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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

‎mirror-coordinator/src/main/resources/common/message/LastMirrorEpochsValue.json‎

Copy file name to clipboard
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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

‎mirror-coordinator/src/main/resources/common/message/MirrorPartitionStateKey.json‎

Copy file name to clipboard
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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

‎mirror-coordinator/src/main/resources/common/message/MirrorPartitionStateValue.json‎

Copy file name to clipboard
+36Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.