public ListOffsetRequest(Struct struct, short version) { super(ApiKeys.LIST_OFFSETS, version); Set<TopicPartition> duplicatePartitions = new HashSet<>(); replicaId = struct.get(REPLICA_ID); isolationLevel = struct.hasField(ISOLATION_LEVEL) ? IsolationLevel.forId(struct.get(ISOLATION_LEVEL)) : IsolationLevel.READ_UNCOMMITTED; partitionTimestamps = new HashMap<>(); for (Object topicResponseObj : struct.get(TOPICS)) { Struct topicResponse = (Struct) topicResponseObj; String topic = topicResponse.get(TOPIC_NAME); for (Object partitionResponseObj : topicResponse.get(PARTITIONS)) { Struct partitionResponse = (Struct) partitionResponseObj; int partition = partitionResponse.get(PARTITION_ID); long timestamp = partitionResponse.get(TIMESTAMP); TopicPartition tp = new TopicPartition(topic, partition); int maxNumOffsets = partitionResponse.getOrElse(MAX_NUM_OFFSETS, 1); Optional<Integer> currentLeaderEpoch = RequestUtils.getLeaderEpoch(partitionResponse, CURRENT_LEADER_EPOCH); PartitionData partitionData = new PartitionData(timestamp, maxNumOffsets, currentLeaderEpoch); if (partitionTimestamps.put(tp, partitionData) != null) duplicatePartitions.add(tp); } } this.duplicatePartitions = duplicatePartitions; }
struct.setIfExists(ISOLATION_LEVEL, isolationLevel.id());
@Test public void testListOffsetsSendsIsolationLevel() { for (final IsolationLevel isolationLevel : IsolationLevel.values()) { Fetcher<byte[], byte[]> fetcher = createFetcher(subscriptions, new Metrics(), new ByteArrayDeserializer(), new ByteArrayDeserializer(), Integer.MAX_VALUE, isolationLevel); subscriptions.assignFromUser(singleton(tp0)); subscriptions.requestOffsetReset(tp0, OffsetResetStrategy.LATEST); client.prepareResponse(new MockClient.RequestMatcher() { @Override public boolean matches(AbstractRequest body) { ListOffsetRequest request = (ListOffsetRequest) body; return request.isolationLevel() == isolationLevel; } }, listOffsetResponse(Errors.NONE, 1L, 5L)); fetcher.resetOffsetsIfNeeded(); consumerClient.pollNoWakeup(); assertFalse(subscriptions.isOffsetResetNeeded(tp0)); assertTrue(subscriptions.isFetchable(tp0)); assertEquals(5, subscriptions.position(tp0).longValue()); } }
ConsumerMetrics metricsRegistry = new ConsumerMetrics(metricsTags.keySet(), "consumer"); ChannelBuilder channelBuilder = ClientUtils.createChannelBuilder(config, time); IsolationLevel isolationLevel = IsolationLevel.valueOf( config.getString(ConsumerConfig.ISOLATION_LEVEL_CONFIG).toUpperCase(Locale.ROOT)); Sensor throttleTimeSensor = Fetcher.throttleTimeSensor(metrics, metricsRegistry.fetcherMetrics);
consumerConfig.put(ConsumerConfig.ISOLATION_LEVEL_CONFIG, READ_COMMITTED.name().toLowerCase(Locale.ROOT)); consumerConfig.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers); stateConsumerConfig.put("internal.leave.group.on.close", false); stateConsumerConfig.put(ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG, Integer.toString(Integer.MAX_VALUE)); stateConsumerConfig.put(ConsumerConfig.ISOLATION_LEVEL_CONFIG, READ_COMMITTED.name().toLowerCase(Locale.ROOT)); stateConsumerConfig.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers); scheduledMessagesConsumerConfig.put("internal.leave.group.on.close", false); scheduledMessagesConsumerConfig.put(ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG, Integer.toString(Integer.MAX_VALUE)); scheduledMessagesConsumerConfig.put(ConsumerConfig.ISOLATION_LEVEL_CONFIG, READ_COMMITTED.name().toLowerCase(Locale.ROOT)); scheduledMessagesConsumerConfig.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers); actorSystemEventListenersConsumerConfig.put("internal.leave.group.on.close", false); actorSystemEventListenersConsumerConfig.put(ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG, Integer.toString(Integer.MAX_VALUE)); actorSystemEventListenersConsumerConfig.put(ConsumerConfig.ISOLATION_LEVEL_CONFIG, READ_COMMITTED.name().toLowerCase(Locale.ROOT)); actorSystemEventListenersConsumerConfig.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
isolationLevel = IsolationLevel.forId(struct.get(ISOLATION_LEVEL)); else isolationLevel = IsolationLevel.READ_UNCOMMITTED;
struct.set(MIN_BYTES, minBytes); struct.setIfExists(MAX_BYTES, maxBytes); struct.setIfExists(ISOLATION_LEVEL, isolationLevel.id()); struct.setIfExists(SESSION_ID, metadata.sessionId()); struct.setIfExists(SESSION_EPOCH, metadata.epoch());