@@ -588,12 +588,10 @@ public ProcessContinuation processElement(
588588 topicPartition , Optional .ofNullable (watermarkEstimator .currentWatermark ()));
589589 }
590590
591- long startOffset = tracker .currentRestriction ().getFrom ();
592- long expectedOffset = startOffset ;
591+ long expectedOffset = tracker .currentRestriction ().getFrom ();
593592 consumer .resume (Collections .singleton (topicPartition ));
594- consumer .seek (topicPartition , startOffset );
595- long skippedRecords = 0L ;
596- final Stopwatch sw = Stopwatch .createStarted ();
593+ consumer .seek (topicPartition , expectedOffset );
594+ final Stopwatch pollTimer = Stopwatch .createUnstarted ();
597595
598596 final KafkaMetrics kafkaMetrics = KafkaSinkMetrics .kafkaMetrics ();
599597 try {
@@ -602,7 +600,7 @@ public ProcessContinuation processElement(
602600 // A consumer will often have prefetches waiting to be returned immediately in which case
603601 // this timer may contribute more latency than it measures.
604602 // See https://shipilev.net/blog/2014/nanotrusting-nanotime/ for more information.
605- final Stopwatch pollTimer = Stopwatch . createStarted ();
603+ pollTimer . reset (). start ();
606604 // Fetch the next records.
607605 final ConsumerRecords <byte [], byte []> rawRecords =
608606 consumer .poll (this .consumerPollingTimeout );
@@ -627,37 +625,6 @@ public ProcessContinuation processElement(
627625 // Visible progress within the consumer polling timeout.
628626 // Partially or fully claim and process records in this batch.
629627 for (ConsumerRecord <byte [], byte []> rawRecord : rawRecords ) {
630- // If the Kafka consumer returns a record with an offset that is already processed
631- // the record can be safely skipped. This is needed because there is a possibility
632- // that the seek() above fails to move the offset to the desired position. In which
633- // case poll() would return records that are already cnsumed.
634- if (rawRecord .offset () < startOffset ) {
635- // If the start offset is not reached even after skipping the records for 10 seconds
636- // then the processing is stopped with a backoff to give the Kakfa server some time
637- // catch up.
638- if (sw .elapsed ().getSeconds () > 10L ) {
639- LOG .error (
640- "The expected offset ({}) was not reached even after"
641- + " skipping consumed records for 10 seconds. The offset we could"
642- + " reach was {}. The processing of this bundle will be attempted"
643- + " at a later time." ,
644- expectedOffset ,
645- rawRecord .offset ());
646- consumer .pause (Collections .singleton (topicPartition ));
647- return ProcessContinuation .resume ()
648- .withResumeDelay (org .joda .time .Duration .standardSeconds (10L ));
649- }
650- skippedRecords ++;
651- continue ;
652- }
653- if (skippedRecords > 0L ) {
654- LOG .warn (
655- "{} records were skipped due to seek returning an"
656- + " earlier position than requested position of {}" ,
657- skippedRecords ,
658- expectedOffset );
659- skippedRecords = 0L ;
660- }
661628 if (!tracker .tryClaim (rawRecord .offset ())) {
662629 consumer .seek (topicPartition , rawRecord .offset ());
663630 consumer .pause (Collections .singleton (topicPartition ));
0 commit comments