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

Validate offset topic #20

Merged
merged 7 commits into from
Feb 16, 2024
Merged
Changes from 3 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
16 changes: 13 additions & 3 deletions src/main/java/com/bakdata/kafka/KafkaConnectorSourceResetter.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@
* }</pre>
*
* Kafka Connect stores offsets for source connectors in a dedicated topic. The key of such an offset consists of the
* connector name and a connector specific partition name, e.g., {@code ["connector-name", { some-source-specific
* -data... }] }. This tool finds all partitions belonging to the connector that should be reset and deletes the
* corresponding offsets.
* connector name and a connector specific partition name, e.g.,
* {@code ["connector-name", { some-source-specific -data... }] }. This tool finds all partitions belonging to the
* connector that should be reset and deletes the corresponding offsets.
*/

@Slf4j
Expand Down Expand Up @@ -124,6 +124,9 @@ private static Converter createConverter(final Map<String, Object> kafkaConfig)

@Override
public void run() {
if (this.offsetTopic.isBlank()) {
throw new IllegalArgumentException("--offset-topic should be set and cannot be blank.");
raminqaf marked this conversation as resolved.
Show resolved Hide resolved
}
final String id = this.createId();
final Map<String, Object> kafkaConfig = this.sharedOptions.createKafkaConfig();
kafkaConfig.put(ConsumerConfig.CLIENT_ID_CONFIG, id);
Expand Down Expand Up @@ -180,6 +183,13 @@ private Consumer<byte[], byte[]> createConsumer(final Map<String, Object> kafkaC
final Consumer<byte[], byte[]> consumer =
new KafkaConsumer<>(kafkaConfig, byteArrayDeserializer, byteArrayDeserializer);
final List<PartitionInfo> partitions = consumer.partitionsFor(this.offsetTopic);
if (partitions.isEmpty()) {
final String message = String.format(
"Could not fetch partitions from the offset topic '%s'. Check if the offset topic name is set "
+ "correctly.",
this.offsetTopic);
throw new IllegalArgumentException(message);
}
final List<TopicPartition> topicPartitions = partitions.stream()
.map(KafkaConnectorSourceResetter::toTopicPartition)
.collect(Collectors.toList());
Expand Down
Loading