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: Remove delete.topic.enable check #3089

Merged
merged 5 commits into from
Jul 18, 2019

Conversation

spena
Copy link
Member

@spena spena commented Jul 17, 2019

Description

The delete.topic.enable configuration check done during the DROP STREAM DELETE TOPIC command is unnecessary. This check is hiding the real error if a user cannot delete the topic when dropping the stream. Actually, the drop stream delete topic does not fail if the flag is set to False.

To fix the problem, I removed the delete.topic.enable check, and rely on the TopicDeletionDisableException thrown when attempting to delete the topic. For DROP STREAM DELETE TOPIC, an error will be displayed in the console about the delete.topic.enable.

For Cluster termination, the exception is ignored, and let KSQL continue with the cluster termination and cleanup of any other internal state.

Testing done

Added a few test cases to validate the changes.
Verify the DROP STREAM DELETE TOPIC works as expected with and without the delete.topic.enable configuration.

ksql> drop stream t1 delete topic;
Could not delete the corresponding kafka topic: t1
Caused by: Topic deletion is disabled. To delete the topic, you must set
	'delete.topic.enable' to true in the Kafka cluster configuration.

Reviewer checklist

  • Ensure docs are updated if necessary. (eg. if a user visible feature is being added or changed).
  • Ensure relevant issues are linked (description should include text like "Fixes #")

TopicDeletionDisabledException is used to detect if Kafka has
the delete.topic.enable config set to True. If true, then deletion
is ignored by Cluster Terminate, but an error is displayed when using
DROP STREAM DELETE TOPIC
Retrying a DROP STREAM DELETE TOPIC commands are delayed when
retrying the failed command. This is not necessary when the
TopicDeletionDisabledException is False, and even for any
other error. Users can retry the command manually if it fails.
@spena spena added this to the 5.4 milestone Jul 17, 2019
@spena spena requested a review from a team July 17, 2019 19:59
@spena spena self-assigned this Jul 17, 2019
@spena spena force-pushed the remove_delete_topic_enable branch from 008744c to 3ee5ee8 Compare July 17, 2019 21:50
Copy link
Contributor

@big-andy-coates big-andy-coates left a comment

Choose a reason for hiding this comment

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

Thanks @spena the change makes sense, but the code could be cleaner by avoiding the 'log and throw' antipattern. (See below).

If you make this change and remove the now superfluous comments, then it LGTM.

// instead of going through the rest of the topics to delete.
// It is now up to the caller to ignore this exception.
LOG.info("Cannot delete topics since '" + DELETE_TOPIC_ENABLE + "' is false. ");
throw new TopicDeletionDisabledException("Topic deletion is disabled. "
Copy link
Contributor

Choose a reason for hiding this comment

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

For me, I think the 'log and throw' is an anti-pattern. Either log, or throw, not both. This pattern just leads to the same error being logged multiple times.

The fact that this requires logic when catching this exception to know not to double log is, IMHO, a clear indication this could be simplified to just throwing here, and just logging where its caught.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

ExecutorUtil.executeWithRetries(
() -> topicClient.deleteTopics(ImmutableList.of(source.getKafkaTopicName())),
RetryBehaviour.ALWAYS);
topicClient.deleteTopics(ImmutableList.of(source.getKafkaTopicName()));
Copy link
Contributor

Choose a reason for hiding this comment

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

why have we removed the retries here? Are there not still cases where we can get retryable exceptions here, e.g. on network issues, that are retryable?

Copy link
Member Author

Choose a reason for hiding this comment

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

There was a delay when deleting the topic if the delete.topic.enable was false. I was thinking on not retrying if a TopicDeletionDisabledException was thrown, but I noticed that we weren't using this retry mechanism on the TopicCreateInjector, so thought this was just a copy/paste from the ClusterTerminator class.

However, I just noticed that this retry method is called in the KafkaTopicClientImpl instead. I will return it back, or better I will try to call it from the deleteTopics instead so we don't have to call retry anywhere else.

// An exception due to TopicDeletionDisabledException should not be logged as an error, just
// info level should be enough. However, the deleteTopics() method already logged it for us,
// so we can skip it.
if (!(e instanceof TopicDeletionDisabledException)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nasty! We can clean this up with we don't log and throw, but just throw in deleteTopics.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

// An exception due to TopicDeletionDisabledException should be ignored when a Cluster
// termination is requested. The deleteTopics already logs an INFO message. We can skip
// logging it here.
if (!(e instanceof TopicDeletionDisabledException)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, nasty - clean up by not logging in deleteTopics.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@spena spena force-pushed the remove_delete_topic_enable branch from 1dfb916 to 3fb30cb Compare July 18, 2019 03:38
@spena spena merged commit 71ec1c0 into confluentinc:master Jul 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants