Source:
<code>void commit(final boolean startNewTransaction, final Map<TopicPartition, Long> partitionTimes) { final long startNs = time.nanoseconds(); log.debug("Committing"); flushState(); if (!eosEnabled) { stateMgr.checkpoint(activeTaskCheckpointableOffsets()); } final Map<TopicPartition, OffsetAndMetadata> consumedOffsetsAndMetadata = new HashMap<>(consumedOffsets.size()); for (final Map.Entry<TopicPartition, Long> entry : consumedOffsets.entrySet()) { final TopicPartition partition = entry.getKey(); Long offset = partitionGroup.headRecordOffset(partition); if (offset == null) { <START> offset = consumer.position(partition); <END> } final long partitionTime = partitionTimes.get(partition); consumedOffsetsAndMetadata.put(partition, new OffsetAndMetadata(offset, encodeTimestamp(partitionTime))); } try { if (eosEnabled) { producer.sendOffsetsToTransaction(consumedOffsetsAndMetadata, applicationId); producer.commitTransaction(); transactionInFlight = false; if (startNewTransaction) { producer.beginTransaction(); transactionInFlight = true; } } else { consumer.commitSync(consumedOffsetsAndMetadata); } } catch (final CommitFailedException | ProducerFencedException | UnknownProducerIdException error) { throw new TaskMigratedException(this, error); } catch (final RebalanceInProgressException error) { log.info("Committing failed with a non-fatal error: {}, " + "we can ignore this since commit may succeed still", error.toString()); } commitNeeded = false; commitRequested = false; commitSensor.record(time.nanoseconds() - startNs); }</code><technical_language>need consider handling exceptions consumer.position throw: KafkaException -> a fatal one; TimeoutException -> in this case commit, treat fatal.</technical_language>

Target:
void commit(final boolean startNewTransaction, final Map<TopicPartition, Long> partitionTimes) { final long startNs = time.nanoseconds(); log.debug("Committing"); flushState(); if (!eosEnabled) { stateMgr.checkpoint(activeTaskCheckpointableOffsets()); } final Map<TopicPartition, OffsetAndMetadata> consumedOffsetsAndMetadata = new HashMap<>(consumedOffsets.size()); for (final Map.Entry<TopicPartition, Long> entry : consumedOffsets.entrySet()) { final TopicPartition partition = entry.getKey(); Long offset = partitionGroup.headRecordOffset(partition); if (offset == null) { try { offset = consumer.position(partition); } catch (final TimeoutException error) { throw new IllegalStateException(error); } catch (final KafkaException fatal) { throw new StreamsException(fatal); } } final long partitionTime = partitionTimes.get(partition); consumedOffsetsAndMetadata.put(partition, new OffsetAndMetadata(offset, encodeTimestamp(partitionTime))); } try { if (eosEnabled) { producer.sendOffsetsToTransaction(consumedOffsetsAndMetadata, applicationId); producer.commitTransaction(); transactionInFlight = false; if (startNewTransaction) { producer.beginTransaction(); transactionInFlight = true; } } else { consumer.commitSync(consumedOffsetsAndMetadata); } } catch (final CommitFailedException | ProducerFencedException | UnknownProducerIdException error) { throw new TaskMigratedException(this, error); } catch (final RebalanceInProgressException error) { log.info("Committing failed with a non-fatal error: {}, " + "we can ignore this since commit may succeed still", error.toString()); } commitNeeded = false; commitRequested = false; commitSensor.record(time.nanoseconds() - startNs); }