Skip to content

Commit 6bcc9ee

Browse files
committed
fix: min-insync-replicas must be at least 1
1 parent 9c8703a commit 6bcc9ee

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/main/java/io/spoud/KafkaSynthClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ public void start(@Observes @Priority(Interceptor.Priority.APPLICATION - 1) St
6060
replicationFactor = (short) nodes.size();
6161
}
6262
short finalReplicationFactor = replicationFactor;
63+
int minInSyncReplicas = Math.max(finalReplicationFactor -1, 1);
6364
this.adminClient.listTopics().names().whenComplete((topics, throwable) -> {
6465
if (throwable != null) {
6566
throw new RuntimeException("Failed to list topics", throwable);
6667
}
6768
if (!topics.contains(config.topic())) {
6869

69-
int minInSyncReplicas = finalReplicationFactor -1;
7070
this.adminClient.createTopics(List.of(new NewTopic(config.topic(), nodes.size(), finalReplicationFactor).configs(
7171
Map.of(TopicConfig.RETENTION_MS_CONFIG, "3600000", TopicConfig.MIN_IN_SYNC_REPLICAS_CONFIG, String.valueOf(minInSyncReplicas))
7272
))).all().whenComplete((v, t1) -> {
@@ -104,8 +104,8 @@ public void start(@Observes @Priority(Interceptor.Priority.APPLICATION - 1) St
104104
throw new RuntimeException("Failed to get topic config", t1);
105105
}
106106
var minInSyncReplicasConfig = configEntries.get(cr).get(TopicConfig.MIN_IN_SYNC_REPLICAS_CONFIG);
107-
if(minInSyncReplicasConfig == null || Integer.parseInt(minInSyncReplicasConfig.value()) != finalReplicationFactor -1) {
108-
Log.errorf("Min in sync replicas for topic %s is %s, expected %s", config.topic(), minInSyncReplicasConfig, finalReplicationFactor -1);
107+
if(minInSyncReplicasConfig == null || Integer.parseInt(minInSyncReplicasConfig.value()) != minInSyncReplicas) {
108+
Log.errorf("Min in sync replicas for topic %s is %s, expected %s", config.topic(), minInSyncReplicasConfig, minInSyncReplicas);
109109
}
110110
});
111111

0 commit comments

Comments
 (0)