kishoreg commented on a change in pull request #7026: URL: https://github.com/apache/incubator-pinot/pull/7026#discussion_r646094623
########## File path: pinot-plugins/pinot-stream-ingestion/pinot-pulsar/src/main/java/org/apache/pinot/plugin/stream/pulsar/PulsarPartitionLevelConsumer.java ########## @@ -0,0 +1,106 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pinot.plugin.stream.pulsar; + +import com.google.common.collect.Iterables; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import org.apache.pinot.spi.stream.MessageBatch; +import org.apache.pinot.spi.stream.PartitionLevelConsumer; +import org.apache.pinot.spi.stream.StreamConfig; +import org.apache.pinot.spi.stream.StreamPartitionMsgOffset; +import org.apache.pulsar.client.api.Message; +import org.apache.pulsar.client.api.MessageId; +import org.apache.pulsar.client.api.PulsarClientException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class PulsarPartitionLevelConsumer extends PulsarPartitionLevelConnectionHandler implements PartitionLevelConsumer { + private static final Logger LOGGER = LoggerFactory.getLogger(PulsarPartitionLevelConsumer.class); + private final ExecutorService _executorService; + + public PulsarPartitionLevelConsumer(String clientId, StreamConfig streamConfig, int partition) { + super(clientId, streamConfig, partition); + _executorService = Executors.newSingleThreadExecutor(); + } + + @Override + public MessageBatch fetchMessages(StreamPartitionMsgOffset startMsgOffset, StreamPartitionMsgOffset endMsgOffset, + int timeoutMillis) { + final MessageId startMessageId = ((MessageIdStreamOffset) startMsgOffset).getMessageId(); + final MessageId endMessageId = + endMsgOffset == null ? MessageId.latest : ((MessageIdStreamOffset) endMsgOffset).getMessageId(); + + List<Message<byte[]>> messagesList = new ArrayList<>(); + Future<PulsarMessageBatch> pulsarResultFuture = + _executorService.submit(() -> fetchMessages(startMessageId, endMessageId, messagesList)); + + try { + return pulsarResultFuture.get(timeoutMillis, TimeUnit.MILLISECONDS); + } catch (Exception e) { + return new PulsarMessageBatch(buildOffsetFilteringIterable(messagesList, startMessageId, endMessageId)); Review comment: log exception? ########## File path: pinot-plugins/pinot-stream-ingestion/pinot-pulsar/src/main/java/org/apache/pinot/plugin/stream/pulsar/PulsarPartitionLevelConsumer.java ########## @@ -0,0 +1,106 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pinot.plugin.stream.pulsar; + +import com.google.common.collect.Iterables; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import org.apache.pinot.spi.stream.MessageBatch; +import org.apache.pinot.spi.stream.PartitionLevelConsumer; +import org.apache.pinot.spi.stream.StreamConfig; +import org.apache.pinot.spi.stream.StreamPartitionMsgOffset; +import org.apache.pulsar.client.api.Message; +import org.apache.pulsar.client.api.MessageId; +import org.apache.pulsar.client.api.PulsarClientException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class PulsarPartitionLevelConsumer extends PulsarPartitionLevelConnectionHandler implements PartitionLevelConsumer { + private static final Logger LOGGER = LoggerFactory.getLogger(PulsarPartitionLevelConsumer.class); + private final ExecutorService _executorService; + + public PulsarPartitionLevelConsumer(String clientId, StreamConfig streamConfig, int partition) { + super(clientId, streamConfig, partition); + _executorService = Executors.newSingleThreadExecutor(); + } + + @Override + public MessageBatch fetchMessages(StreamPartitionMsgOffset startMsgOffset, StreamPartitionMsgOffset endMsgOffset, + int timeoutMillis) { + final MessageId startMessageId = ((MessageIdStreamOffset) startMsgOffset).getMessageId(); + final MessageId endMessageId = + endMsgOffset == null ? MessageId.latest : ((MessageIdStreamOffset) endMsgOffset).getMessageId(); + + List<Message<byte[]>> messagesList = new ArrayList<>(); + Future<PulsarMessageBatch> pulsarResultFuture = + _executorService.submit(() -> fetchMessages(startMessageId, endMessageId, messagesList)); + + try { + return pulsarResultFuture.get(timeoutMillis, TimeUnit.MILLISECONDS); + } catch (Exception e) { + return new PulsarMessageBatch(buildOffsetFilteringIterable(messagesList, startMessageId, endMessageId)); Review comment: what are we doing here? add comments please ########## File path: pinot-plugins/pinot-stream-ingestion/pinot-pulsar/src/main/java/org/apache/pinot/plugin/stream/pulsar/PulsarConfig.java ########## @@ -0,0 +1,103 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pinot.plugin.stream.pulsar; + +import com.google.common.base.Preconditions; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import org.apache.pinot.spi.stream.StreamConfig; +import org.apache.pinot.spi.stream.StreamConfigProperties; +import org.apache.pulsar.client.api.MessageId; + +//TODO: Add properties for batch receive - maxNumMessages, maxNumBytes, timeout. +public class PulsarConfig { Review comment: what docs on what does this represent ########## File path: pinot-plugins/pinot-stream-ingestion/pinot-pulsar/src/main/java/org/apache/pinot/plugin/stream/pulsar/PulsarPartitionLevelConnectionHandler.java ########## @@ -0,0 +1,78 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pinot.plugin.stream.pulsar; + +import com.google.common.annotations.VisibleForTesting; +import java.io.IOException; +import org.apache.pinot.spi.stream.StreamConfig; +import org.apache.pulsar.client.api.PulsarClient; +import org.apache.pulsar.client.api.PulsarClientException; +import org.apache.pulsar.client.api.Reader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class PulsarPartitionLevelConnectionHandler { + private static final Logger LOGGER = LoggerFactory.getLogger(PulsarPartitionLevelConnectionHandler.class); + + public static final String SEPERATOR = "-"; + public static final String TOPIC_PARTITION_NAME_SUFFIX = "partition"; + protected final PulsarConfig _config; + protected final String _clientId; + protected final int _partition; + protected final String _topic; + protected PulsarClient _pulsarClient = null; + protected Reader<byte[]> _reader = null; + + public PulsarPartitionLevelConnectionHandler(String clientId, StreamConfig streamConfig, int partition) { + _config = new PulsarConfig(streamConfig, clientId); + _clientId = clientId; + _partition = partition; + _topic = _config.getPulsarTopicName(); + + try { + _pulsarClient = PulsarClient.builder().serviceUrl(_config.getBootstrapServers()).build(); + + _reader = + _pulsarClient.newReader().topic(getPartitionedTopicName(partition)) + .startMessageId(_config.getInitialMessageId()).create(); + + LOGGER.info("Created consumer with id {} for topic {}", _reader, + _config.getPulsarTopicName()); + + } catch (PulsarClientException e) { + LOGGER.error("Could not create pulsar consumer", e); + } + + } + + private String getPartitionedTopicName(int partition) { Review comment: what is this logic coming from? is this Pulsar convention -- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org