Skip to content

Commit a265328

Browse files
authored
KAFKA-18837: Ensure controller quorum timeouts and backoffs are at least 0 (apache#18998)
Add validators to the QuorumConfig's configuration definitions. Reviewers: Mickael Maison <[email protected]>, Ken Huang <[email protected]>, TengYao Chi <[email protected]>
1 parent f0f7382 commit a265328

File tree

2 files changed

+62
-6
lines changed

2 files changed

+62
-6
lines changed

raft/src/main/java/org/apache/kafka/raft/QuorumConfig.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import static org.apache.kafka.common.config.ConfigDef.Importance.HIGH;
3636
import static org.apache.kafka.common.config.ConfigDef.Importance.LOW;
3737
import static org.apache.kafka.common.config.ConfigDef.Importance.MEDIUM;
38+
import static org.apache.kafka.common.config.ConfigDef.Range.atLeast;
3839
import static org.apache.kafka.common.config.ConfigDef.Type.INT;
3940
import static org.apache.kafka.common.config.ConfigDef.Type.LIST;
4041

@@ -102,12 +103,12 @@ public class QuorumConfig {
102103
public static final ConfigDef CONFIG_DEF = new ConfigDef()
103104
.define(QUORUM_VOTERS_CONFIG, LIST, DEFAULT_QUORUM_VOTERS, new ControllerQuorumVotersValidator(), HIGH, QUORUM_VOTERS_DOC)
104105
.define(QUORUM_BOOTSTRAP_SERVERS_CONFIG, LIST, DEFAULT_QUORUM_BOOTSTRAP_SERVERS, new ControllerQuorumBootstrapServersValidator(), HIGH, QUORUM_BOOTSTRAP_SERVERS_DOC)
105-
.define(QUORUM_ELECTION_TIMEOUT_MS_CONFIG, INT, DEFAULT_QUORUM_ELECTION_TIMEOUT_MS, null, HIGH, QUORUM_ELECTION_TIMEOUT_MS_DOC)
106-
.define(QUORUM_FETCH_TIMEOUT_MS_CONFIG, INT, DEFAULT_QUORUM_FETCH_TIMEOUT_MS, null, HIGH, QUORUM_FETCH_TIMEOUT_MS_DOC)
107-
.define(QUORUM_ELECTION_BACKOFF_MAX_MS_CONFIG, INT, DEFAULT_QUORUM_ELECTION_BACKOFF_MAX_MS, null, HIGH, QUORUM_ELECTION_BACKOFF_MAX_MS_DOC)
108-
.define(QUORUM_LINGER_MS_CONFIG, INT, DEFAULT_QUORUM_LINGER_MS, null, MEDIUM, QUORUM_LINGER_MS_DOC)
109-
.define(QUORUM_REQUEST_TIMEOUT_MS_CONFIG, INT, DEFAULT_QUORUM_REQUEST_TIMEOUT_MS, null, MEDIUM, QUORUM_REQUEST_TIMEOUT_MS_DOC)
110-
.define(QUORUM_RETRY_BACKOFF_MS_CONFIG, INT, DEFAULT_QUORUM_RETRY_BACKOFF_MS, null, LOW, QUORUM_RETRY_BACKOFF_MS_DOC);
106+
.define(QUORUM_ELECTION_TIMEOUT_MS_CONFIG, INT, DEFAULT_QUORUM_ELECTION_TIMEOUT_MS, atLeast(0), HIGH, QUORUM_ELECTION_TIMEOUT_MS_DOC)
107+
.define(QUORUM_FETCH_TIMEOUT_MS_CONFIG, INT, DEFAULT_QUORUM_FETCH_TIMEOUT_MS, atLeast(0), HIGH, QUORUM_FETCH_TIMEOUT_MS_DOC)
108+
.define(QUORUM_ELECTION_BACKOFF_MAX_MS_CONFIG, INT, DEFAULT_QUORUM_ELECTION_BACKOFF_MAX_MS, atLeast(0), HIGH, QUORUM_ELECTION_BACKOFF_MAX_MS_DOC)
109+
.define(QUORUM_LINGER_MS_CONFIG, INT, DEFAULT_QUORUM_LINGER_MS, atLeast(0), MEDIUM, QUORUM_LINGER_MS_DOC)
110+
.define(QUORUM_REQUEST_TIMEOUT_MS_CONFIG, INT, DEFAULT_QUORUM_REQUEST_TIMEOUT_MS, atLeast(0), MEDIUM, QUORUM_REQUEST_TIMEOUT_MS_DOC)
111+
.define(QUORUM_RETRY_BACKOFF_MS_CONFIG, INT, DEFAULT_QUORUM_RETRY_BACKOFF_MS, atLeast(0), LOW, QUORUM_RETRY_BACKOFF_MS_DOC);
111112

112113
private final List<String> voters;
113114
private final List<String> bootstrapServers;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
package org.apache.kafka.raft;
18+
19+
import org.apache.kafka.common.config.ConfigException;
20+
21+
import org.junit.jupiter.api.Test;
22+
23+
import java.util.HashMap;
24+
import java.util.Map;
25+
26+
import static org.junit.jupiter.api.Assertions.assertThrows;
27+
28+
public class QuorumConfigTest {
29+
@Test
30+
public void testIllegalConfig() {
31+
assertInvalidConfig(Map.of(QuorumConfig.QUORUM_ELECTION_TIMEOUT_MS_CONFIG, "-1"));
32+
assertInvalidConfig(Map.of(QuorumConfig.QUORUM_FETCH_TIMEOUT_MS_CONFIG, "-1"));
33+
assertInvalidConfig(Map.of(QuorumConfig.QUORUM_ELECTION_BACKOFF_MAX_MS_CONFIG, "-1"));
34+
assertInvalidConfig(Map.of(QuorumConfig.QUORUM_LINGER_MS_CONFIG, "-1"));
35+
assertInvalidConfig(Map.of(QuorumConfig.QUORUM_REQUEST_TIMEOUT_MS_CONFIG, "-1"));
36+
assertInvalidConfig(Map.of(QuorumConfig.QUORUM_RETRY_BACKOFF_MS_CONFIG, "-1"));
37+
}
38+
39+
private void assertInvalidConfig(Map<String, Object> overrideConfig) {
40+
Map<String, Object> props = new HashMap<>();
41+
props.put(QuorumConfig.QUORUM_VOTERS_CONFIG, "1@localhost:9092");
42+
props.put(QuorumConfig.QUORUM_BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
43+
props.put(QuorumConfig.QUORUM_ELECTION_TIMEOUT_MS_CONFIG, "10");
44+
props.put(QuorumConfig.QUORUM_FETCH_TIMEOUT_MS_CONFIG, "10");
45+
props.put(QuorumConfig.QUORUM_ELECTION_BACKOFF_MAX_MS_CONFIG, "10");
46+
props.put(QuorumConfig.QUORUM_LINGER_MS_CONFIG, "10");
47+
props.put(QuorumConfig.QUORUM_REQUEST_TIMEOUT_MS_CONFIG, "10");
48+
props.put(QuorumConfig.QUORUM_RETRY_BACKOFF_MS_CONFIG, "10");
49+
50+
props.putAll(overrideConfig);
51+
52+
assertThrows(ConfigException.class, () -> QuorumConfig.CONFIG_DEF.parse(props));
53+
}
54+
55+
}

0 commit comments

Comments
 (0)