@ -19,6 +19,7 @@ package kafka.server
@@ -19,6 +19,7 @@ package kafka.server
import java.util
import java.util. { Collections , Properties }
import java.util.concurrent.CopyOnWriteArrayList
import java.util.concurrent.locks.ReentrantReadWriteLock
import kafka.cluster.EndPoint
import kafka.log. { LogCleaner , LogConfig , LogManager }
@ -201,8 +202,11 @@ class DynamicBrokerConfig(private val kafkaConfig: KafkaConfig) extends Logging
@@ -201,8 +202,11 @@ class DynamicBrokerConfig(private val kafkaConfig: KafkaConfig) extends Logging
private [ server ] val staticDefaultConfigs = ConfigDef . convertToStringMapWithPasswordValues ( KafkaConfig . defaultValues . asJava ) . asScala
private val dynamicBrokerConfigs = mutable . Map [ String , String ] ( )
private val dynamicDefaultConfigs = mutable . Map [ String , String ] ( )
private val reconfigurables = mutable . Buffer [ Reconfigurable ] ( )
private val brokerReconfigurables = mutable . Buffer [ BrokerReconfigurable ] ( )
// Use COWArrayList to prevent concurrent modification exception when an item is added by one thread to these
// collections , while another thread is iterating over them .
private val reconfigurables = new CopyOnWriteArrayList [ Reconfigurable ] ( )
private val brokerReconfigurables = new CopyOnWriteArrayList [ BrokerReconfigurable ] ( )
private val lock = new ReentrantReadWriteLock
private var currentConfig : KafkaConfig = null
private val dynamicConfigPasswordEncoder = maybeCreatePasswordEncoder ( kafkaConfig . passwordEncoderSecret )
@ -259,16 +263,16 @@ class DynamicBrokerConfig(private val kafkaConfig: KafkaConfig) extends Logging
@@ -259,16 +263,16 @@ class DynamicBrokerConfig(private val kafkaConfig: KafkaConfig) extends Logging
def addReconfigurable ( reconfigurable : Reconfigurable ) : Unit = CoreUtils . inWriteLock ( lock ) {
verifyReconfigurableConfigs ( reconfigurable . reconfigurableConfigs . asScala )
reconfigurables += reconfigurable
reconfigurables . add ( reconfigurable )
}
def addBrokerReconfigurable ( reconfigurable : BrokerReconfigurable ) : Unit = CoreUtils . inWriteLock ( lock ) {
verifyReconfigurableConfigs ( reconfigurable . reconfigurableConfigs )
brokerReconfigurables += reconfigurable
brokerReconfigurables . add ( reconfigurable )
}
def removeReconfigurable ( reconfigurable : Reconfigurable ) : Unit = CoreUtils . inWriteLock ( lock ) {
reconfigurables -= reconfigurable
reconfigurables . remove ( reconfigurable )
}
private def verifyReconfigurableConfigs ( configNames : Set [ String ] ) : Unit = CoreUtils . inWriteLock ( lock ) {
@ -320,7 +324,7 @@ class DynamicBrokerConfig(private val kafkaConfig: KafkaConfig) extends Logging
@@ -320,7 +324,7 @@ class DynamicBrokerConfig(private val kafkaConfig: KafkaConfig) extends Logging
* changes are processed . At the moment , only listener configs are considered for reloading .
*/
private [ server ] def reloadUpdatedFilesWithoutConfigChange ( newProps : Properties ) : Unit = CoreUtils . inWriteLock ( lock ) {
reconfigurables
reconfigurables . asScala
. filter ( reconfigurable => ReloadableFileConfigs . exists ( reconfigurable . reconfigurableConfigs . contains ) )
. foreach {
case reconfigurable : ListenerReconfigurable =>
@ -535,8 +539,8 @@ class DynamicBrokerConfig(private val kafkaConfig: KafkaConfig) extends Logging
@@ -535,8 +539,8 @@ class DynamicBrokerConfig(private val kafkaConfig: KafkaConfig) extends Logging
if ( changeMap . nonEmpty || deletedKeySet . nonEmpty ) {
try {
val customConfigs = new util . HashMap [ String , Object ] ( newConfig . originalsFromThisConfig ) // non - Kafka configs
newConfig . valuesFromThisConfig . keySet . forEach ( customConfigs . remove ( _ ) )
reconfigurables . fore ach {
newConfig . valuesFromThisConfig . keySet . forEach ( k => customConfigs . remove ( k ) )
reconfigurables . forE ach {
case listenerReconfigurable : ListenerReconfigurable =>
processListenerReconfigurable ( listenerReconfigurable , newConfig , customConfigs , validateOnly , reloadOnly = false )
case reconfigurable =>
@ -546,7 +550,7 @@ class DynamicBrokerConfig(private val kafkaConfig: KafkaConfig) extends Logging
@@ -546,7 +550,7 @@ class DynamicBrokerConfig(private val kafkaConfig: KafkaConfig) extends Logging
// BrokerReconfigurable updates are processed after config is updated . Only do the validation here .
val brokerReconfigurablesToUpdate = mutable . Buffer [ BrokerReconfigurable ] ( )
brokerReconfigurables . fore ach { reconfigurable =>
brokerReconfigurables . forE ach { reconfigurable =>
if ( needsReconfiguration ( reconfigurable . reconfigurableConfigs . asJava , changeMap . keySet , deletedKeySet ) ) {
reconfigurable . validateReconfiguration ( newConfig )
if ( ! validateOnly )