Skip to content
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

KAFKA-16540: enforce min.insync.replicas config invariants for ELR (#… #18745

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
<suppress checks="(ParameterNumber|ClassDataAbstractionCoupling)"
files="(QuorumController).java"/>
<suppress checks="(CyclomaticComplexity|NPathComplexity)"
files="(PartitionRegistration|PartitionChangeBuilder|ScramParser).java"/>
files="(ConfigurationControlManager|PartitionRegistration|PartitionChangeBuilder|ScramParser).java"/>
<suppress checks="CyclomaticComplexity"
files="(ClientQuotasImage|KafkaEventQueue|MetadataDelta|QuorumController|ReplicationControlManager|KRaftMigrationDriver|ClusterControlManager|MetaPropertiesEnsemble).java"/>
<suppress checks="NPathComplexity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,31 @@

package org.apache.kafka.controller;

import org.apache.kafka.common.config.TopicConfig;
import org.apache.kafka.common.metadata.AbortTransactionRecord;
import org.apache.kafka.common.metadata.BeginTransactionRecord;
import org.apache.kafka.common.metadata.ConfigRecord;
import org.apache.kafka.common.metadata.EndTransactionRecord;
import org.apache.kafka.metadata.bootstrap.BootstrapMetadata;
import org.apache.kafka.server.common.ApiMessageAndVersion;
import org.apache.kafka.server.common.EligibleLeaderReplicasVersion;
import org.apache.kafka.server.common.MetadataVersion;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

import static org.apache.kafka.common.config.ConfigResource.Type.BROKER;


public class ActivationRecordsGenerator {

static ControllerResult<Void> recordsForEmptyLog(
Consumer<String> activationMessageConsumer,
long transactionStartOffset,
BootstrapMetadata bootstrapMetadata,
MetadataVersion metadataVersion
MetadataVersion metadataVersion,
int defaultMinInSyncReplicas
) {
StringBuilder logMessageBuilder = new StringBuilder("Performing controller activation. ");
List<ApiMessageAndVersion> records = new ArrayList<>();
Expand Down Expand Up @@ -87,6 +93,15 @@ static ControllerResult<Void> recordsForEmptyLog(
// initialization, etc.
records.addAll(bootstrapMetadata.records());

// If ELR is enabled, we need to set a cluster-level min.insync.replicas.
if (bootstrapMetadata.featureLevel(EligibleLeaderReplicasVersion.FEATURE_NAME) > 0) {
records.add(new ApiMessageAndVersion(new ConfigRecord().
setResourceType(BROKER.id()).
setResourceName("").
setName(TopicConfig.MIN_IN_SYNC_REPLICAS_CONFIG).
setValue(Integer.toString(defaultMinInSyncReplicas)), (short) 0));
}

activationMessageConsumer.accept(logMessageBuilder.toString().trim());
if (metadataVersion.isMetadataTransactionSupported()) {
records.add(new ApiMessageAndVersion(new EndTransactionRecord(), (short) 0));
Expand Down Expand Up @@ -148,13 +163,19 @@ static ControllerResult<Void> generate(
boolean isEmpty,
long transactionStartOffset,
BootstrapMetadata bootstrapMetadata,
MetadataVersion curMetadataVersion
MetadataVersion curMetadataVersion,
int defaultMinInSyncReplicas
) {
if (isEmpty) {
return recordsForEmptyLog(activationMessageConsumer, transactionStartOffset,
bootstrapMetadata, bootstrapMetadata.metadataVersion());
return recordsForEmptyLog(activationMessageConsumer,
transactionStartOffset,
bootstrapMetadata,
bootstrapMetadata.metadataVersion(),
defaultMinInSyncReplicas);
} else {
return recordsForNonEmptyLog(activationMessageConsumer, transactionStartOffset, curMetadataVersion);
return recordsForNonEmptyLog(activationMessageConsumer,
transactionStartOffset,
curMetadataVersion);
}
}
}
Loading