Search in sources :

Example 6 with PushOffsetVector

use of io.confluent.ksql.util.PushOffsetVector in project ksql by confluentinc.

the class ScalablePushConsumer method run.

public void run() {
    if (started) {
        LOG.error("Already ran consumer");
        throw new IllegalStateException("Already ran consumer");
    }
    started = true;
    try {
        initialize();
        subscribeOrAssign();
        while (!closed) {
            final ConsumerRecords<?, GenericRow> records = consumer.poll(POLL_TIMEOUT);
            // No assignment yet
            if (this.topicPartitions.get() == null) {
                continue;
            }
            if (newAssignment) {
                newAssignment = false;
                onNewAssignment();
            }
            final PushOffsetVector startOffsetVector = getOffsetVector(currentPositions.get(), topicName, partitions);
            if (records.isEmpty()) {
                updateCurrentPositions();
                computeProgressToken(Optional.of(startOffsetVector));
                onEmptyRecords();
                continue;
            }
            for (ConsumerRecord<?, GenericRow> rec : records) {
                handleRow(rec.key(), rec.value(), rec.timestamp());
            }
            updateCurrentPositions();
            computeProgressToken(Optional.of(startOffsetVector));
            try {
                consumer.commitSync();
            } catch (CommitFailedException e) {
                LOG.warn("Failed to commit, likely due to rebalance.  Will wait for new assignment", e);
            }
            afterBatchProcessed();
        }
    } catch (WakeupException e) {
    // This is expected when we get closed.
    }
}
Also used : GenericRow(io.confluent.ksql.GenericRow) PushOffsetVector(io.confluent.ksql.util.PushOffsetVector) CommitFailedException(org.apache.kafka.clients.consumer.CommitFailedException) WakeupException(org.apache.kafka.common.errors.WakeupException)

Example 7 with PushOffsetVector

use of io.confluent.ksql.util.PushOffsetVector in project ksql by confluentinc.

the class CatchupConsumerTest method shouldRunConsumer_timeoutWaitingForAssignment.

@Test
public void shouldRunConsumer_timeoutWaitingForAssignment() {
    // Given:
    PushOffsetRange offsetRange = new PushOffsetRange(Optional.empty(), new PushOffsetVector(ImmutableList.of(1L, 2L)));
    when(latestConsumer.getAssignment()).thenReturn(null);
    when(clock.millis()).thenReturn(CURRENT_TIME_MS, CURRENT_TIME_MS + WAIT_FOR_ASSIGNMENT_MS - 1, CURRENT_TIME_MS + WAIT_FOR_ASSIGNMENT_MS + 1);
    try (CatchupConsumer consumer = new CatchupConsumer(TOPIC, false, SCHEMA, kafkaConsumer, () -> latestConsumer, catchupCoordinator, offsetRange, clock, sleepFn, waitFn, 0, pq -> caughtUp = true)) {
        // When:
        consumer.register(queue);
        final Exception e = assertThrows(KsqlException.class, consumer::run);
        // Then:
        assertThat(e.getMessage(), containsString("Timed out waiting for assignment from Latest"));
    }
}
Also used : PushOffsetVector(io.confluent.ksql.util.PushOffsetVector) KsqlException(io.confluent.ksql.util.KsqlException) PushOffsetRange(io.confluent.ksql.util.PushOffsetRange) Test(org.junit.Test)

Aggregations

PushOffsetVector (io.confluent.ksql.util.PushOffsetVector)7 PushOffsetRange (io.confluent.ksql.util.PushOffsetRange)4 Test (org.junit.Test)4 ImmutableList (com.google.common.collect.ImmutableList)2 GenericRow (io.confluent.ksql.GenericRow)2 KsqlException (io.confluent.ksql.util.KsqlException)2 ArrayList (java.util.ArrayList)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 IntegrationTest (io.confluent.common.utils.IntegrationTest)1 ProcessingQueue (io.confluent.ksql.physical.scalablepush.ProcessingQueue)1 WAIT_FOR_ASSIGNMENT_MS (io.confluent.ksql.physical.scalablepush.consumer.CatchupConsumer.WAIT_FOR_ASSIGNMENT_MS)1 EMPTY_RECORDS (io.confluent.ksql.physical.scalablepush.consumer.CommonTestUtil.EMPTY_RECORDS)1 QR0_1 (io.confluent.ksql.physical.scalablepush.consumer.CommonTestUtil.QR0_1)1 QR0_2 (io.confluent.ksql.physical.scalablepush.consumer.CommonTestUtil.QR0_2)1 QR1_2 (io.confluent.ksql.physical.scalablepush.consumer.CommonTestUtil.QR1_2)1 QR1_3 (io.confluent.ksql.physical.scalablepush.consumer.CommonTestUtil.QR1_3)1 RECORD0_1 (io.confluent.ksql.physical.scalablepush.consumer.CommonTestUtil.RECORD0_1)1 RECORD0_2 (io.confluent.ksql.physical.scalablepush.consumer.CommonTestUtil.RECORD0_2)1 RECORD1_2 (io.confluent.ksql.physical.scalablepush.consumer.CommonTestUtil.RECORD1_2)1