bryanck commented on code in PR #12372:
URL: https://github.com/apache/iceberg/pull/12372#discussion_r1985409093
##########
kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/channel/CommitterImpl.java:
##########
@@ -56,51 +74,57 @@ public int compare(TopicPartition o1, TopicPartition o2) {
}
}
- @Override
- public void start(Catalog catalog, IcebergSinkConfig config, SinkTaskContext
context) {
- KafkaClientFactory clientFactory = new
KafkaClientFactory(config.kafkaProps());
+ public boolean hasLeaderPartitions(Collection<TopicPartition>
currentAssignedPartitions) {
ConsumerGroupDescription groupDesc;
try (Admin admin = clientFactory.createAdmin()) {
groupDesc = KafkaUtils.consumerGroupDescription(config.connectGroupId(),
admin);
}
-
- if (groupDesc.state() == ConsumerGroupState.STABLE) {
+ if (groupDesc.state() == ConsumerGroupState.STABLE) {
Collection<MemberDescription> members = groupDesc.members();
- Set<TopicPartition> partitions = context.assignment();
- if (isLeader(members, partitions)) {
- LOG.info("Task elected leader, starting commit coordinator");
- Coordinator coordinator = new Coordinator(catalog, config, members,
clientFactory, context);
- coordinatorThread = new CoordinatorThread(coordinator);
- coordinatorThread.start();
+ if (isLeader(members, currentAssignedPartitions)) {
+ membersWhenWorkerIsCoordinator = members;
+ return true;
}
}
+ return false;
+ }
- LOG.info("Starting commit worker");
- SinkWriter sinkWriter = new SinkWriter(catalog, config);
- worker = new Worker(config, clientFactory, sinkWriter, context);
- worker.start();
+ @Override
+ public void start(Catalog catalog, IcebergSinkConfig config, SinkTaskContext
context) {
+ // No-Op
}
@Override
- public void save(Collection<SinkRecord> sinkRecords) {
- if (sinkRecords != null && !sinkRecords.isEmpty()) {
- worker.save(sinkRecords);
+ public void start(Catalog catalog, IcebergSinkConfig config, SinkTaskContext
context, Collection<TopicPartition> addedPartitions) {
+ if (hasLeaderPartitions(addedPartitions)) {
+ LOG.info("Committer received leader partition. Starting Coordinator.");
+ startCoordinator();
}
- processControlEvents();
}
@Override
public void stop() {
- if (worker != null) {
- worker.stop();
- worker = null;
+ // No-Op
Review Comment:
We should throw `UnsupportedOperationException` here, also in `start()`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]