[
https://issues.apache.org/jira/browse/NIFI-2608?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15428549#comment-15428549
]
Oleg Zhurakousky commented on NIFI-2608:
----------------------------------------
Below is the stack trace you may get when configuring multiple concurrent
tasks in ConsumeKafka
{code}
2016-08-04 22:51:51,379 ERROR [Timer-Driven Process Thread-9]
o.a.n.p.kafka.pubsub.ConsumeKafka
ConsumeKafka[id=a2b8149c-c7b7-49d4-b65a-8fd5c174158b]
ConsumeKafka[id=a2b8149c-c7b7-49d4-b65a-8fd5c174158b] failed to process due to
java.util.ConcurrentModificationException: KafkaConsumer is not safe for
multi-threaded access; rolling back session:
java.util.ConcurrentModificationException: KafkaConsumer is not safe for
multi-threaded access
2016-08-04 22:51:51,381 ERROR [Timer-Driven Process Thread-9]
o.a.n.p.kafka.pubsub.ConsumeKafka
java.util.ConcurrentModificationException: KafkaConsumer is not safe for
multi-threaded access
at
org.apache.kafka.clients.consumer.KafkaConsumer.acquire(KafkaConsumer.java:1324)
~[kafka-clients-0.9.0.1.jar:na]
at
org.apache.kafka.clients.consumer.KafkaConsumer.poll(KafkaConsumer.java:844)
~[kafka-clients-0.9.0.1.jar:na]
at
org.apache.nifi.processors.kafka.pubsub.ConsumeKafka.rendezvousWithKafka(ConsumeKafka.java:159)
~[nifi-kafka-pubsub-processors-0.7.0.jar:0.7.0]
at
org.apache.nifi.processors.kafka.pubsub.AbstractKafkaProcessor.onTrigger(AbstractKafkaProcessor.java:192)
~[nifi-kafka-pubsub-processors-0.7.0.jar:0.7.0]
at
org.apache.nifi.controller.StandardProcessorNode.onTrigger(StandardProcessorNode.java:1054)
[nifi-framework-core-0.7.0.jar:0.7.0]
at
org.apache.nifi.controller.tasks.ContinuallyRunProcessorTask.call(ContinuallyRunProcessorTask.java:136)
[nifi-framework-core-0.7.0.jar:0.7.0]
at
org.apache.nifi.controller.tasks.ContinuallyRunProcessorTask.call(ContinuallyRunProcessorTask.java:47)
[nifi-framework-core-0.7.0.jar:0.7.0]
at
org.apache.nifi.controller.scheduling.TimerDrivenSchedulingAgent$1.run(TimerDrivenSchedulingAgent.java:127)
[nifi-framework-core-0.7.0.jar:0.7.0]
at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
[na:1.7.0_80]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
[na:1.7.0_80]
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
[na:1.7.0_80]
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
[na:1.7.0_80]
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
[na:1.7.0_80]
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
[na:1.7.0_80]
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_80]
{code}
As you can see from the stack trace the problem happens when we invoke poll(..)
on KafkaConsumer (kafka class) which has changed from being thread-safe in 0.8
to non-thread-safe in 0.9. Further reading into the API i see the following:
{code}
* <h3><a name="multithreaded">Multi-threaded Processing</a></h3>
*
* The Kafka consumer is NOT thread-safe. All network I/O happens in the thread
of the application
* making the call. It is the responsibility of the user to ensure that
multi-threaded access
* is properly synchronized. Un-synchronized access will result in {@link
ConcurrentModificationException}.
*
{code}
Basically further analysis shows that KafkaConsumer.poll() must be synchronized
where acquire(); then release(); must happen synchronously. After that you have
ConsumerRecord and you can continue with multi-threaded processing.
In the future we may consider implementing a consumer-per-thread model.
> Thread-safety issue with ConsumeKafka
> -------------------------------------
>
> Key: NIFI-2608
> URL: https://issues.apache.org/jira/browse/NIFI-2608
> Project: Apache NiFi
> Issue Type: Bug
> Reporter: Oleg Zhurakousky
> Assignee: Oleg Zhurakousky
> Fix For: 1.0.0
>
>
> KafkaConsumer went fro thread-safe in 0.8 to not-thread-safe in 0.9 which was
> overlooked while implementing new ConsumeKafka processor which relied on 0.9
> Client API.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)