[ 
https://issues.apache.org/jira/browse/NIFI-3425?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16609578#comment-16609578
 ] 

ASF GitHub Bot commented on NIFI-3425:
--------------------------------------

Github user markap14 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2986#discussion_r216411528
  
    --- Diff: 
nifi-nar-bundles/nifi-cassandra-bundle/nifi-cassandra-processors/src/main/java/org/apache/nifi/processors/cassandra/PutCassandraQL.java
 ---
    @@ -399,11 +434,13 @@ protected void setStatementObject(final 
BoundStatement statement, final int para
         @OnUnscheduled
         public void stop() {
             super.stop();
    +        statementCache.clear();
    --- End diff --
    
    Would recommend putting this into an @OnStopped method instead of 
@OnUnscheduled. As-is, we could get into a race condition where line 225 calls 
statementCache.get(), which returns null. Then the @OnUnscheduled method clears 
the cache, and then line 228 adds the value to the cache. Then, the next time 
this processor is run, the cache is already populated. Given that we are 
calling `clear()` here I'm assuming we expect it clear when the processor 
starts.


> Cache prepared statements in PutCassandraQL
> -------------------------------------------
>
>                 Key: NIFI-3425
>                 URL: https://issues.apache.org/jira/browse/NIFI-3425
>             Project: Apache NiFi
>          Issue Type: Improvement
>            Reporter: Matt Burgess
>            Assignee: Matt Burgess
>            Priority: Minor
>         Attachments: NIFI-3425.patch
>
>
> Currently PutCassandraQL supports prepared statements (using ? parameters 
> much like JDBC SQL statements) via flow file attributes specifying the type 
> and value of the parameters.
> However, the prepared statement is created (and thus possibly re-created) for 
> each flow file, which neuters its effectiveness over literal CQL statements. 
> The driver warns of this:
> 2017-01-31 14:30:54,287 WARN [cluster1-worker-1] 
> com.datastax.driver.core.Cluster Re-preparing already prepared query insert 
> into test_table (id, timestamp, id1, timestamp1, id
> 2, timestamp2, id3, timestamp3, id4, timestamp4, id5, timestamp5, id6, 
> timestamp6) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);. Please note 
> that preparing the same query
>  more than once is generally an anti-pattern and will likely affect 
> performance. Consider preparing the statement only once.
> Prepared statements should be cached and reused where possible.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to