Skip to content

Commit

Permalink
Avoid race conditions while create the same topic multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
faderskd committed Apr 6, 2023
1 parent f11cc0f commit f0c338e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ public void execute(DatacenterBoundRepositoryHolder<TopicRepository> holder) {

@Override
public void rollback(DatacenterBoundRepositoryHolder<TopicRepository> holder) {
holder.getRepository().removeTopic(topic.getName());
/*
We don't want to do a rollback due to possible race conditions with creating a topic on Kafka.
It increases the possibility of discrepancies between Kafka and Zookeeper: topic exists in Kafka,
but not in the Zookeeper and vice versa.
*/
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package pl.allegro.tech.hermes.management.domain.topic.commands;

import pl.allegro.tech.hermes.api.Topic;
import pl.allegro.tech.hermes.api.TopicName;
import pl.allegro.tech.hermes.domain.topic.TopicRepository;
import pl.allegro.tech.hermes.management.domain.dc.DatacenterBoundRepositoryHolder;
Expand All @@ -10,16 +9,12 @@ public class RemoveTopicRepositoryCommand extends RepositoryCommand<TopicReposit

private final TopicName topicName;

private Topic backup;

public RemoveTopicRepositoryCommand(TopicName topicName) {
this.topicName = topicName;
}

@Override
public void backup(DatacenterBoundRepositoryHolder<TopicRepository> holder) {
backup = holder.getRepository().getTopicDetails(topicName);
}
public void backup(DatacenterBoundRepositoryHolder<TopicRepository> holder) {}

@Override
public void execute(DatacenterBoundRepositoryHolder<TopicRepository> holder) {
Expand All @@ -28,7 +23,11 @@ public void execute(DatacenterBoundRepositoryHolder<TopicRepository> holder) {

@Override
public void rollback(DatacenterBoundRepositoryHolder<TopicRepository> holder) {
holder.getRepository().createTopic(backup);
/*
We don't want to do a rollback due to possible race conditions with creating a topic on Kafka.
It increases the possibility of discrepancies between Kafka and Zookeeper: topic exists in Kafka,
but not in the Zookeeper and vice versa.
*/
}

@Override
Expand Down

0 comments on commit f0c338e

Please sign in to comment.