|
16 | 16 | */ |
17 | 17 | package org.apache.kafka.coordinator.mirror; |
18 | 18 |
|
| 19 | +import org.apache.kafka.common.config.AbstractConfig; |
19 | 20 | import org.apache.kafka.common.config.ConfigDef; |
20 | 21 |
|
| 22 | +import java.util.Properties; |
| 23 | + |
21 | 24 | import static org.apache.kafka.common.config.ConfigDef.Importance.HIGH; |
22 | 25 | import static org.apache.kafka.common.config.ConfigDef.Importance.LOW; |
23 | 26 | import static org.apache.kafka.common.config.ConfigDef.Importance.MEDIUM; |
|
28 | 31 | import static org.apache.kafka.common.config.ConfigDef.Type.SHORT; |
29 | 32 |
|
30 | 33 | /** |
31 | | - * This class provides proper validation, defaults, and documentation |
32 | | - * for all configurations supported by the Cluster Mirroring feature. |
| 34 | + * Broker-level configuration for Cluster Mirroring feature. |
| 35 | + * These configurations are set when starting/rebooting the broker |
| 36 | + * and stored in server.properties or dynamic broker config. |
33 | 37 | */ |
34 | | -public class ClusterMirrorConfigs { |
35 | | - // --------------------------------------------------------------- |
36 | | - // Broker level configs. Set when starting/rebooting the broker. Stored in server.properties or dynamic broker config. |
37 | | - // --------------------------------------------------------------- |
38 | | - |
| 38 | +public final class ClusterMirrorBrokerConfig extends AbstractConfig { |
39 | 39 | public static final String MIRROR_COORDINATOR_THREADS_CONFIG = "mirror.coordinator.threads"; |
40 | | - private static final int MIRROR_COORDINATOR_THREADS_DEFAULT = 1; |
41 | 40 | private static final String MIRROR_COORDINATOR_THREADS_DOC = "The number of threads used to process coordinator events for cluster mirroring."; |
| 41 | + private static final int MIRROR_COORDINATOR_THREADS_DEFAULT = 1; |
42 | 42 |
|
43 | 43 | public static final String MIRROR_COORDINATOR_WRITE_TIMEOUT_MS_CONFIG = "mirror.coordinator.write.timeout.ms"; |
44 | | - private static final long MIRROR_COORDINATOR_WRITE_TIMEOUT_MS_DEFAULT = 5000L; |
45 | 44 | private static final String MIRROR_COORDINATOR_WRITE_TIMEOUT_MS_DOC = "The timeout in milliseconds for write operations on the mirror state coordinator."; |
| 45 | + private static final long MIRROR_COORDINATOR_WRITE_TIMEOUT_MS_DEFAULT = 5000L; |
46 | 46 |
|
47 | 47 | public static final String MIRROR_COORDINATOR_APPEND_LINGER_MS_CONFIG = "mirror.coordinator.append.linger.ms"; |
48 | | - private static final int MIRROR_COORDINATOR_APPEND_LINGER_MS_DEFAULT = 10; |
49 | 48 | private static final String MIRROR_COORDINATOR_APPEND_LINGER_MS_DOC = "The linger time in milliseconds for batching records before flushing to the mirror state topic."; |
| 49 | + private static final int MIRROR_COORDINATOR_APPEND_LINGER_MS_DEFAULT = 10; |
50 | 50 |
|
51 | 51 | public static final String MIRROR_COORDINATOR_LOAD_BUFFER_SIZE_CONFIG = "mirror.coordinator.load.buffer.size"; |
52 | | - private static final int MIRROR_COORDINATOR_LOAD_BUFFER_SIZE_DEFAULT = 5 * 1024 * 1024; |
53 | 52 | private static final String MIRROR_COORDINATOR_LOAD_BUFFER_SIZE_DOC = "The buffer size in bytes for loading mirror state records during coordinator startup."; |
| 53 | + private static final int MIRROR_COORDINATOR_LOAD_BUFFER_SIZE_DEFAULT = 5 * 1024 * 1024; |
54 | 54 |
|
55 | 55 | public static final String MIRROR_STATE_TOPIC_NUM_PARTITIONS_CONFIG = "mirror.state.topic.num.partitions"; |
56 | | - private static final int MIRROR_STATE_TOPIC_NUM_PARTITIONS_DEFAULT = 50; |
57 | 56 | private static final String MIRROR_STATE_TOPIC_NUM_PARTITIONS_DOC = "The number of partitions for the internal topic (should not change after deployment)."; |
| 57 | + private static final int MIRROR_STATE_TOPIC_NUM_PARTITIONS_DEFAULT = 50; |
58 | 58 |
|
59 | 59 | public static final String MIRROR_STATE_TOPIC_REPLICATION_FACTOR_CONFIG = "mirror.state.topic.replication.factor"; |
60 | | - private static final short MIRROR_STATE_TOPIC_REPLICATION_FACTOR_DEFAULT = 3; |
61 | 60 | private static final String MIRROR_STATE_TOPIC_REPLICATION_FACTOR_DOC = "The replication factor for the internal topic. " + |
62 | 61 | "Topic creation will fail until the cluster size meets this replication factor requirement."; |
| 62 | + private static final short MIRROR_STATE_TOPIC_REPLICATION_FACTOR_DEFAULT = 3; |
| 63 | + |
| 64 | + public static final String MIRROR_STATE_TOPIC_MIN_ISR_CONFIG = "mirror.state.topic.min.isr"; |
| 65 | + private static final String MIRROR_STATE_TOPIC_MIN_ISR_DOC = "The minimum number of replicas that must acknowledge a write to mirror state topic in order to be considered successful."; |
| 66 | + private static final int MIRROR_STATE_TOPIC_MIN_ISR_DEFAULT = 2; |
| 67 | + |
| 68 | + public static final String MIRROR_STATE_TOPIC_SEGMENT_BYTES_CONFIG = "mirror.state.topic.segment.bytes"; |
| 69 | + private static final String MIRROR_STATE_TOPIC_SEGMENT_BYTES_DOC = "The mirror state topic segment bytes should be kept relatively small in order to facilitate faster log compaction and cache loads."; |
| 70 | + private static final int MIRROR_STATE_TOPIC_SEGMENT_BYTES_DEFAULT = 100 * 1024 * 1024; |
63 | 71 |
|
64 | 72 | public static final String MIRROR_NUM_REPLICA_FETCHERS_CONFIG = "mirror.num.replica.fetchers"; |
65 | 73 | private static final int MIRROR_NUM_REPLICA_FETCHERS_DEFAULT = 1; |
@@ -68,43 +76,93 @@ public class ClusterMirrorConfigs { |
68 | 76 | "A higher value increases I/O parallelism for cross cluster replication at the cost of higher CPU and memory utilization."; |
69 | 77 |
|
70 | 78 | public static final String MIRROR_METADATA_REFRESH_INTERVAL_MS_CONFIG = "mirror.metadata.refresh.interval.ms"; |
71 | | - private static final long MIRROR_METADATA_REFRESH_INTERVAL_MS_DEFAULT = 60000L; |
72 | 79 | private static final String MIRROR_METADATA_REFRESH_INTERVAL_MS_DOC = "The interval in milliseconds at which the coordinator refreshes metadata from source clusters. " + |
73 | 80 | "This controls how frequently the coordinator polls source clusters to detect new topics and metadata changes."; |
| 81 | + private static final long MIRROR_METADATA_REFRESH_INTERVAL_MS_DEFAULT = 60000L; |
74 | 82 |
|
75 | 83 | public static final String MIRROR_FAILED_RETRY_INITIAL_BACKOFF_MS_CONFIG = "mirror.failed.retry.initial.backoff.ms"; |
76 | | - private static final long MIRROR_FAILED_RETRY_INITIAL_BACKOFF_MS_DEFAULT = 100L; |
77 | 84 | private static final String MIRROR_FAILED_RETRY_INITIAL_BACKOFF_MS_DOC = "The initial backoff time in milliseconds before retrying a mirror partition " + |
78 | 85 | "in FAILED state. The actual delay uses full jitter: a uniform random value in [0, backoff]."; |
| 86 | + private static final long MIRROR_FAILED_RETRY_INITIAL_BACKOFF_MS_DEFAULT = 100L; |
79 | 87 |
|
80 | 88 | public static final String MIRROR_FAILED_RETRY_MAX_BACKOFF_MS_CONFIG = "mirror.failed.retry.max.backoff.ms"; |
81 | | - private static final long MIRROR_FAILED_RETRY_MAX_BACKOFF_MS_DEFAULT = 300000L; |
82 | 89 | private static final String MIRROR_FAILED_RETRY_MAX_BACKOFF_MS_DOC = "The maximum backoff time in milliseconds for retrying a mirror partition in FAILED state."; |
| 90 | + private static final long MIRROR_FAILED_RETRY_MAX_BACKOFF_MS_DEFAULT = 300000L; |
83 | 91 |
|
84 | 92 | public static final String MIRROR_FAILED_RETRY_MAX_ATTEMPTS_CONFIG = "mirror.failed.retry.max.attempts"; |
85 | | - private static final int MIRROR_FAILED_RETRY_MAX_ATTEMPTS_DEFAULT = 20; |
86 | 93 | private static final String MIRROR_FAILED_RETRY_MAX_ATTEMPTS_DOC = "The maximum number of automatic retry attempts for a mirror partition in FAILED state. " + |
87 | 94 | "After this limit is reached, manual intervention is required via the start-mirror-topics command. " + |
88 | 95 | "Set to 0 to disable automatic retries."; |
| 96 | + private static final int MIRROR_FAILED_RETRY_MAX_ATTEMPTS_DEFAULT = 20; |
89 | 97 |
|
90 | | - private static final ConfigDef BROKER_CONFIG_DEF = new ConfigDef() |
| 98 | + public static final ConfigDef CONFIG_DEF = new ConfigDef() |
91 | 99 | .defineInternal(MIRROR_COORDINATOR_THREADS_CONFIG, INT, MIRROR_COORDINATOR_THREADS_DEFAULT, atLeast(1), LOW, MIRROR_COORDINATOR_THREADS_DOC) |
92 | 100 | .defineInternal(MIRROR_COORDINATOR_WRITE_TIMEOUT_MS_CONFIG, LONG, MIRROR_COORDINATOR_WRITE_TIMEOUT_MS_DEFAULT, atLeast(1L), LOW, MIRROR_COORDINATOR_WRITE_TIMEOUT_MS_DOC) |
93 | 101 | .defineInternal(MIRROR_COORDINATOR_APPEND_LINGER_MS_CONFIG, INT, MIRROR_COORDINATOR_APPEND_LINGER_MS_DEFAULT, atLeast(0), LOW, MIRROR_COORDINATOR_APPEND_LINGER_MS_DOC) |
94 | 102 | .defineInternal(MIRROR_COORDINATOR_LOAD_BUFFER_SIZE_CONFIG, INT, MIRROR_COORDINATOR_LOAD_BUFFER_SIZE_DEFAULT, atLeast(1), LOW, MIRROR_COORDINATOR_LOAD_BUFFER_SIZE_DOC) |
95 | 103 | .defineInternal(MIRROR_STATE_TOPIC_NUM_PARTITIONS_CONFIG, INT, MIRROR_STATE_TOPIC_NUM_PARTITIONS_DEFAULT, atLeast(1), HIGH, MIRROR_STATE_TOPIC_NUM_PARTITIONS_DOC) |
96 | 104 | .defineInternal(MIRROR_STATE_TOPIC_REPLICATION_FACTOR_CONFIG, SHORT, MIRROR_STATE_TOPIC_REPLICATION_FACTOR_DEFAULT, atLeast(1), HIGH, MIRROR_STATE_TOPIC_REPLICATION_FACTOR_DOC) |
| 105 | + .defineInternal(MIRROR_STATE_TOPIC_MIN_ISR_CONFIG, INT, MIRROR_STATE_TOPIC_MIN_ISR_DEFAULT, atLeast(1), HIGH, MIRROR_STATE_TOPIC_MIN_ISR_DOC) |
| 106 | + .defineInternal(MIRROR_STATE_TOPIC_SEGMENT_BYTES_CONFIG, INT, MIRROR_STATE_TOPIC_SEGMENT_BYTES_DEFAULT, atLeast(1), HIGH, MIRROR_STATE_TOPIC_SEGMENT_BYTES_DOC) |
97 | 107 | .defineInternal(MIRROR_NUM_REPLICA_FETCHERS_CONFIG, INT, MIRROR_NUM_REPLICA_FETCHERS_DEFAULT, atLeast(1), HIGH, MIRROR_NUM_REPLICA_FETCHERS_DOC) |
98 | 108 | .defineInternal(MIRROR_METADATA_REFRESH_INTERVAL_MS_CONFIG, LONG, MIRROR_METADATA_REFRESH_INTERVAL_MS_DEFAULT, atLeast(0L), MEDIUM, MIRROR_METADATA_REFRESH_INTERVAL_MS_DOC) |
99 | 109 | .defineInternal(MIRROR_FAILED_RETRY_INITIAL_BACKOFF_MS_CONFIG, LONG, MIRROR_FAILED_RETRY_INITIAL_BACKOFF_MS_DEFAULT, atLeast(1L), MEDIUM, MIRROR_FAILED_RETRY_INITIAL_BACKOFF_MS_DOC) |
100 | 110 | .defineInternal(MIRROR_FAILED_RETRY_MAX_BACKOFF_MS_CONFIG, LONG, MIRROR_FAILED_RETRY_MAX_BACKOFF_MS_DEFAULT, atLeast(1L), MEDIUM, MIRROR_FAILED_RETRY_MAX_BACKOFF_MS_DOC) |
101 | 111 | .defineInternal(MIRROR_FAILED_RETRY_MAX_ATTEMPTS_CONFIG, INT, MIRROR_FAILED_RETRY_MAX_ATTEMPTS_DEFAULT, between(0, Short.MAX_VALUE), MEDIUM, MIRROR_FAILED_RETRY_MAX_ATTEMPTS_DOC); |
102 | 112 |
|
103 | | - /** |
104 | | - * Broker-level mirror configurations. |
105 | | - * This is merged into AbstractKafkaConfig for validation. |
106 | | - */ |
107 | | - public static ConfigDef brokerConfigDef() { |
108 | | - return new ConfigDef(BROKER_CONFIG_DEF); |
| 113 | + public ClusterMirrorBrokerConfig(Properties properties) { |
| 114 | + super(CONFIG_DEF, properties, false); |
| 115 | + } |
| 116 | + |
| 117 | + public int coordinatorNumThreads() { |
| 118 | + return getInt(MIRROR_COORDINATOR_THREADS_CONFIG); |
| 119 | + } |
| 120 | + |
| 121 | + public long coordinatorWriteTimeoutMs() { |
| 122 | + return getLong(MIRROR_COORDINATOR_WRITE_TIMEOUT_MS_CONFIG); |
| 123 | + } |
| 124 | + |
| 125 | + public int coordinatorAppendLingerMs() { |
| 126 | + return getInt(MIRROR_COORDINATOR_APPEND_LINGER_MS_CONFIG); |
| 127 | + } |
| 128 | + |
| 129 | + public int coordinatorLoadBufferSize() { |
| 130 | + return getInt(MIRROR_COORDINATOR_LOAD_BUFFER_SIZE_CONFIG); |
| 131 | + } |
| 132 | + |
| 133 | + public int stateTopicNumPartitions() { |
| 134 | + return getInt(MIRROR_STATE_TOPIC_NUM_PARTITIONS_CONFIG); |
| 135 | + } |
| 136 | + |
| 137 | + public short stateTopicReplicationFactor() { |
| 138 | + return getShort(MIRROR_STATE_TOPIC_REPLICATION_FACTOR_CONFIG); |
| 139 | + } |
| 140 | + |
| 141 | + public int stateTopicMinISR() { |
| 142 | + return getInt(MIRROR_STATE_TOPIC_MIN_ISR_CONFIG); |
| 143 | + } |
| 144 | + |
| 145 | + public int stateTopicSegmentBytes() { |
| 146 | + return getInt(MIRROR_STATE_TOPIC_SEGMENT_BYTES_CONFIG); |
| 147 | + } |
| 148 | + |
| 149 | + public int numReplicaFetchers() { |
| 150 | + return getInt(MIRROR_NUM_REPLICA_FETCHERS_CONFIG); |
| 151 | + } |
| 152 | + |
| 153 | + public long metadataRefreshIntervalMs() { |
| 154 | + return getLong(MIRROR_METADATA_REFRESH_INTERVAL_MS_CONFIG); |
| 155 | + } |
| 156 | + |
| 157 | + public long failedRetryInitialBackoffMs() { |
| 158 | + return getLong(MIRROR_FAILED_RETRY_INITIAL_BACKOFF_MS_CONFIG); |
| 159 | + } |
| 160 | + |
| 161 | + public long failedRetryMaxBackoffMs() { |
| 162 | + return getLong(MIRROR_FAILED_RETRY_MAX_BACKOFF_MS_CONFIG); |
| 163 | + } |
| 164 | + |
| 165 | + public int failedRetryMaxAttempts() { |
| 166 | + return getInt(MIRROR_FAILED_RETRY_MAX_ATTEMPTS_CONFIG); |
109 | 167 | } |
110 | 168 | } |