|
17 | 17 |
|
18 | 18 | package org.apache.kafka.controller;
|
19 | 19 |
|
| 20 | +import org.apache.kafka.common.config.TopicConfig; |
20 | 21 | import org.apache.kafka.common.metadata.AbortTransactionRecord;
|
21 | 22 | import org.apache.kafka.common.metadata.BeginTransactionRecord;
|
| 23 | +import org.apache.kafka.common.metadata.ConfigRecord; |
22 | 24 | import org.apache.kafka.common.metadata.EndTransactionRecord;
|
23 | 25 | import org.apache.kafka.metadata.bootstrap.BootstrapMetadata;
|
24 | 26 | import org.apache.kafka.server.common.ApiMessageAndVersion;
|
| 27 | +import org.apache.kafka.server.common.EligibleLeaderReplicasVersion; |
25 | 28 | import org.apache.kafka.server.common.MetadataVersion;
|
26 | 29 |
|
27 | 30 | import java.util.ArrayList;
|
28 | 31 | import java.util.List;
|
29 | 32 | import java.util.function.Consumer;
|
30 | 33 |
|
| 34 | +import static org.apache.kafka.common.config.ConfigResource.Type.BROKER; |
| 35 | + |
31 | 36 |
|
32 | 37 | public class ActivationRecordsGenerator {
|
33 | 38 |
|
34 | 39 | static ControllerResult<Void> recordsForEmptyLog(
|
35 | 40 | Consumer<String> activationMessageConsumer,
|
36 | 41 | long transactionStartOffset,
|
37 | 42 | BootstrapMetadata bootstrapMetadata,
|
38 |
| - MetadataVersion metadataVersion |
| 43 | + MetadataVersion metadataVersion, |
| 44 | + int defaultMinInSyncReplicas |
39 | 45 | ) {
|
40 | 46 | StringBuilder logMessageBuilder = new StringBuilder("Performing controller activation. ");
|
41 | 47 | List<ApiMessageAndVersion> records = new ArrayList<>();
|
@@ -87,6 +93,15 @@ static ControllerResult<Void> recordsForEmptyLog(
|
87 | 93 | // initialization, etc.
|
88 | 94 | records.addAll(bootstrapMetadata.records());
|
89 | 95 |
|
| 96 | + // If ELR is enabled, we need to set a cluster-level min.insync.replicas. |
| 97 | + if (bootstrapMetadata.featureLevel(EligibleLeaderReplicasVersion.FEATURE_NAME) > 0) { |
| 98 | + records.add(new ApiMessageAndVersion(new ConfigRecord(). |
| 99 | + setResourceType(BROKER.id()). |
| 100 | + setResourceName(""). |
| 101 | + setName(TopicConfig.MIN_IN_SYNC_REPLICAS_CONFIG). |
| 102 | + setValue(Integer.toString(defaultMinInSyncReplicas)), (short) 0)); |
| 103 | + } |
| 104 | + |
90 | 105 | activationMessageConsumer.accept(logMessageBuilder.toString().trim());
|
91 | 106 | if (metadataVersion.isMetadataTransactionSupported()) {
|
92 | 107 | records.add(new ApiMessageAndVersion(new EndTransactionRecord(), (short) 0));
|
@@ -148,13 +163,19 @@ static ControllerResult<Void> generate(
|
148 | 163 | boolean isEmpty,
|
149 | 164 | long transactionStartOffset,
|
150 | 165 | BootstrapMetadata bootstrapMetadata,
|
151 |
| - MetadataVersion curMetadataVersion |
| 166 | + MetadataVersion curMetadataVersion, |
| 167 | + int defaultMinInSyncReplicas |
152 | 168 | ) {
|
153 | 169 | if (isEmpty) {
|
154 |
| - return recordsForEmptyLog(activationMessageConsumer, transactionStartOffset, |
155 |
| - bootstrapMetadata, bootstrapMetadata.metadataVersion()); |
| 170 | + return recordsForEmptyLog(activationMessageConsumer, |
| 171 | + transactionStartOffset, |
| 172 | + bootstrapMetadata, |
| 173 | + bootstrapMetadata.metadataVersion(), |
| 174 | + defaultMinInSyncReplicas); |
156 | 175 | } else {
|
157 |
| - return recordsForNonEmptyLog(activationMessageConsumer, transactionStartOffset, curMetadataVersion); |
| 176 | + return recordsForNonEmptyLog(activationMessageConsumer, |
| 177 | + transactionStartOffset, |
| 178 | + curMetadataVersion); |
158 | 179 | }
|
159 | 180 | }
|
160 | 181 | }
|
0 commit comments