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

fix: fail when trying to disable remote storage on an enabled topic #44

Closed
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
9 changes: 9 additions & 0 deletions core/src/main/scala/kafka/server/ConfigHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,19 @@ class TopicConfigHandler(private val replicaManager: ReplicaManager,
val logs = logManager.logsByTopic(topic)
val wasRemoteLogEnabledBeforeUpdate = logs.exists(_.remoteLogEnabled())

maybeFailIfDisablingRemoteStorage(props, wasRemoteLogEnabledBeforeUpdate)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though this exception is triggered, for some reason the config is still updated; so I decided to trigger the exception earlier in the process on AdminZkClient

logManager.updateTopicConfig(topic, props, kafkaConfig.isRemoteLogStorageSystemEnabled)
maybeBootstrapRemoteLogComponents(topic, logs, wasRemoteLogEnabledBeforeUpdate)
}

private[server] def maybeFailIfDisablingRemoteStorage(props: Properties,
wasRemoteLogEnabledBeforeUpdate: Boolean): Unit = {
val isRemoteLogToBeEnabled = props.getProperty(TopicConfig.REMOTE_LOG_STORAGE_ENABLE_CONFIG, String.valueOf(wasRemoteLogEnabledBeforeUpdate))
if (wasRemoteLogEnabledBeforeUpdate && !java.lang.Boolean.parseBoolean(isRemoteLogToBeEnabled)) {
throw new IllegalArgumentException(s"Disabling remote log on the topic is not supported.")
}
}

private[server] def maybeBootstrapRemoteLogComponents(topic: String,
logs: Seq[UnifiedLog],
wasRemoteLogEnabledBeforeUpdate: Boolean): Unit = {
Expand Down
9 changes: 9 additions & 0 deletions core/src/main/scala/kafka/zk/AdminZkClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import kafka.server.{ConfigEntityName, ConfigType, DynamicConfig, KafkaConfig}
import kafka.utils._
import kafka.utils.Implicits._
import org.apache.kafka.admin.{AdminUtils, BrokerMetadata}
import org.apache.kafka.common.config.TopicConfig
import org.apache.kafka.common.{TopicPartition, Uuid}
import org.apache.kafka.common.errors._
import org.apache.kafka.common.internals.Topic
Expand Down Expand Up @@ -477,6 +478,14 @@ class AdminZkClient(zkClient: KafkaZkClient,
Topic.validate(topic)
if (!zkClient.topicExists(topic))
throw new UnknownTopicOrPartitionException(s"Topic '$topic' does not exist.")

// fix: workaround to fail when trying to disable tiered storage instead of silently update value while logging warning
val currentRemoteStorageEnable = zkClient.getEntityConfigs(ConfigType.Topic, topic).getProperty(TopicConfig.REMOTE_LOG_STORAGE_ENABLE_CONFIG, "false")
val newRemoteStorageEnable = configs.getProperty(TopicConfig.REMOTE_LOG_STORAGE_ENABLE_CONFIG, currentRemoteStorageEnable)
if (java.lang.Boolean.parseBoolean(currentRemoteStorageEnable) && !java.lang.Boolean.parseBoolean(newRemoteStorageEnable)) {
throw new InvalidConfigurationException(s"Disabling remote log on the topic is not supported.")
}

// remove the topic overrides
LogConfig.validate(configs,
kafkaConfig.map(_.extractLogConfigMap).getOrElse(Collections.emptyMap()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,4 +599,18 @@ class DynamicConfigChangeUnitTest {
configHandler.maybeBootstrapRemoteLogComponents(topic, Seq(log0), isRemoteLogEnabledBeforeUpdate)
verify(rlm, never()).onLeadershipChange(any(), any(), any())
}

@Test
def testDisableRemoteLogStorageOnTopicOnAlreadyEnabledTopic(): Unit = {
val rlm: RemoteLogManager = mock(classOf[RemoteLogManager])
val replicaManager: ReplicaManager = mock(classOf[ReplicaManager])
when(replicaManager.remoteLogManager).thenReturn(Some(rlm))

val isRemoteLogEnabledBeforeUpdate = true
val configHandler: TopicConfigHandler = new TopicConfigHandler(replicaManager, null, null, None)
val newProps = new Properties()
newProps.put(TopicConfig.REMOTE_LOG_STORAGE_ENABLE_CONFIG, "false")
assertThrows(classOf[IllegalArgumentException], () => configHandler.maybeFailIfDisablingRemoteStorage(newProps, isRemoteLogEnabledBeforeUpdate))
verify(rlm, never()).onLeadershipChange(any(), any(), any())
}
}