You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by ijokarumawak <gi...@git.apache.org> on 2018/04/13 02:20:45 UTC

[GitHub] nifi pull request #2634: NIFI-5075: Do not execute Funnels with no outgoing ...

GitHub user ijokarumawak opened a pull request:

    https://github.com/apache/nifi/pull/2634

    NIFI-5075: Do not execute Funnels with no outgoing connections

    Thank you for submitting a contribution to Apache NiFi.
    
    In order to streamline the review of the contribution we ask you
    to ensure the following steps have been taken:
    
    ### For all changes:
    - [x] Is there a JIRA ticket associated with this PR? Is it referenced 
         in the commit message?
    
    - [x] Does your PR title start with NIFI-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
    
    - [x] Has your PR been rebased against the latest commit within the target branch (typically master)?
    
    - [x] Is your initial contribution a single, squashed commit?
    
    ### For code changes:
    - [ ] Have you ensured that the full suite of tests is executed via mvn -Pcontrib-check clean install at the root nifi folder?
    - [ ] Have you written or updated unit tests to verify your changes?
    - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)? 
    - [ ] If applicable, have you updated the LICENSE file, including the main LICENSE file under nifi-assembly?
    - [ ] If applicable, have you updated the NOTICE file, including the main NOTICE file found under nifi-assembly?
    - [ ] If adding new Properties, have you added .displayName in addition to .name (programmatic access) for each of the new properties?
    
    ### For documentation related changes:
    - [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
    
    ### Note:
    Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/ijokarumawak/nifi nifi-5075

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/nifi/pull/2634.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #2634
    
----
commit c60e294432e154eb6b5b3339c40138b13c246ae5
Author: Koji Kawamura <ij...@...>
Date:   2018-04-13T02:18:24Z

    NIFI-5075: Do not execute Funnels with no outgoing connections

----


---

[GitHub] nifi pull request #2634: NIFI-5075: Do not execute Funnels with no outgoing ...

Posted by markobean <gi...@git.apache.org>.
Github user markobean commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2634#discussion_r181735366
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/tasks/ConnectableTask.java ---
    @@ -103,8 +104,24 @@ private boolean isYielded() {
             return connectable.getYieldExpiration() > System.currentTimeMillis();
         }
     
    +    /**
    +     * Make sure processor has work to do. This means that it meets one of these criteria:
    +     * <ol>
    +     * <li>It is annotated with @TriggerWhenEmpty</li>
    +     * <li>It has no incoming connections</li>
    +     * <li>All incoming connections are self-loops</li>
    +     * <li>It has data in an incoming Connection
    +     *     AND It is not a Funnel without outgoing connections
    +     * </li>
    +     * </ol>
    +     * @return true if there is work to do, otherwise false
    +     */
         private boolean isWorkToDo() {
    -        return connectable.isTriggerWhenEmpty() || !connectable.hasIncomingConnection() || !hasNonLoopConnection || Connectables.flowFilesQueued(connectable);
    +        return connectable.isTriggerWhenEmpty()
    +                || !connectable.hasIncomingConnection()
    --- End diff --
    
    This logic seems inverted unnecessarily. Why is 'connectable.hasIncomingConnection()' negated? This leads to the method returning true when there are no incoming connections. Similarly, is it the intent to indicate no work to do if the only incoming connections are looped connections?


---

[GitHub] nifi issue #2634: NIFI-5075: Do not execute Funnels with no outgoing connect...

Posted by ijokarumawak <gi...@git.apache.org>.
Github user ijokarumawak commented on the issue:

    https://github.com/apache/nifi/pull/2634
  
    @ottobackwards Thanks for mentioning about tests. I've added tests for Funnels.
    @markap14 I've removed caching `hasNonLoopConnection` because it can be left unchanged when connections are added while a component is running.
    @markobean I grouped some conditions to clearly express that a component is treated as a 'source' component, I hope it becomes more understandable now.
    
    Thank you all for giving your comments. I've tested adding brand-new funnels and other components as well as loading existing components by restarting NiFi. It looks work as expected. Hope it is ready to be merged.


---

[GitHub] nifi pull request #2634: NIFI-5075: Do not execute Funnels with no outgoing ...

Posted by markap14 <gi...@git.apache.org>.
Github user markap14 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2634#discussion_r181775911
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/tasks/ConnectableTask.java ---
    @@ -103,8 +104,24 @@ private boolean isYielded() {
             return connectable.getYieldExpiration() > System.currentTimeMillis();
         }
     
    +    /**
    +     * Make sure processor has work to do. This means that it meets one of these criteria:
    +     * <ol>
    +     * <li>It is annotated with @TriggerWhenEmpty</li>
    +     * <li>It has no incoming connections</li>
    +     * <li>All incoming connections are self-loops</li>
    +     * <li>It has data in an incoming Connection
    +     *     AND It is not a Funnel without outgoing connections
    +     * </li>
    +     * </ol>
    +     * @return true if there is work to do, otherwise false
    +     */
         private boolean isWorkToDo() {
    -        return connectable.isTriggerWhenEmpty() || !connectable.hasIncomingConnection() || !hasNonLoopConnection || Connectables.flowFilesQueued(connectable);
    +        return connectable.isTriggerWhenEmpty()
    +                || !connectable.hasIncomingConnection()
    --- End diff --
    
    If connectable.hasIncomingConnection() is false, then that indicates that the component is a 'source' component, and doesn't depend on incoming data to be triggered, so it is said to have work to do. Similarly, if all incoming connections are self-looping connections, then it is a source component and is said to have work to do.


---

[GitHub] nifi pull request #2634: NIFI-5075: Do not execute Funnels with no outgoing ...

Posted by markap14 <gi...@git.apache.org>.
Github user markap14 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2634#discussion_r181792251
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/tasks/ConnectableTask.java ---
    @@ -103,8 +104,24 @@ private boolean isYielded() {
             return connectable.getYieldExpiration() > System.currentTimeMillis();
         }
     
    +    /**
    +     * Make sure processor has work to do. This means that it meets one of these criteria:
    +     * <ol>
    +     * <li>It is annotated with @TriggerWhenEmpty</li>
    +     * <li>It has no incoming connections</li>
    +     * <li>All incoming connections are self-loops</li>
    +     * <li>It has data in an incoming Connection
    +     *     AND It is not a Funnel without outgoing connections
    +     * </li>
    +     * </ol>
    +     * @return true if there is work to do, otherwise false
    +     */
         private boolean isWorkToDo() {
    -        return connectable.isTriggerWhenEmpty() || !connectable.hasIncomingConnection() || !hasNonLoopConnection || Connectables.flowFilesQueued(connectable);
    +        return connectable.isTriggerWhenEmpty()
    +                || !connectable.hasIncomingConnection()
    +                || !hasNonLoopConnection
    +                || (Connectables.flowFilesQueued(connectable)
    --- End diff --
    
    @ijokarumawak unfortunately, this doesn't appear to fully address the issue. It appears that the clause above this one, "!hasNonLoopConnection" is evaluating to true in my case (simple GenerateFlowFile -> Funnel).
    
    I think I would actually recommend just adding a block of code to the beginning of this method like:
    ```
    if (connectable.getConnectableType() == ConnectableType.FUNNEL) {
      return !connectable.getConnections().isEmpty() && connectable.hasIncomingConnection() && hasNonLoopConnection;
    } else {
      // do what we already do
    }
    ```
    
    I recommend this because Funnels are a special case, since they are really intended to be 'notional' and never stopped or started. They are always running. And for Funnels, in particular, it only really makes sense to run if there is in fact an incoming connection (rather than processors where we want to run even if there isn't an incoming connection), AND If there is at least one outgoing connection (funnels don't support auto-terminating relationships).


---

[GitHub] nifi issue #2634: NIFI-5075: Do not execute Funnels with no outgoing connect...

Posted by ijokarumawak <gi...@git.apache.org>.
Github user ijokarumawak commented on the issue:

    https://github.com/apache/nifi/pull/2634
  
    Thank you, @markap14, you are right, I thought I pushed it but didn't. Just pushed updated commit.


---

[GitHub] nifi issue #2634: NIFI-5075: Do not execute Funnels with no outgoing connect...

Posted by markap14 <gi...@git.apache.org>.
Github user markap14 commented on the issue:

    https://github.com/apache/nifi/pull/2634
  
    @ijokarumawak thanks for the update! I feel the code is far more understandable now and appears to work great! +1 merged to master


---

[GitHub] nifi pull request #2634: NIFI-5075: Do not execute Funnels with no outgoing ...

Posted by ijokarumawak <gi...@git.apache.org>.
Github user ijokarumawak commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2634#discussion_r181951840
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/tasks/ConnectableTask.java ---
    @@ -103,8 +104,24 @@ private boolean isYielded() {
             return connectable.getYieldExpiration() > System.currentTimeMillis();
         }
     
    +    /**
    +     * Make sure processor has work to do. This means that it meets one of these criteria:
    +     * <ol>
    +     * <li>It is annotated with @TriggerWhenEmpty</li>
    +     * <li>It has no incoming connections</li>
    +     * <li>All incoming connections are self-loops</li>
    +     * <li>It has data in an incoming Connection
    +     *     AND It is not a Funnel without outgoing connections
    +     * </li>
    +     * </ol>
    +     * @return true if there is work to do, otherwise false
    +     */
         private boolean isWorkToDo() {
    -        return connectable.isTriggerWhenEmpty() || !connectable.hasIncomingConnection() || !hasNonLoopConnection || Connectables.flowFilesQueued(connectable);
    +        return connectable.isTriggerWhenEmpty()
    +                || !connectable.hasIncomingConnection()
    +                || !hasNonLoopConnection
    +                || (Connectables.flowFilesQueued(connectable)
    --- End diff --
    
    @markap14 Thank you for testing.
    
    I understand what went wrong. I tested with an existing flow including Funnel which had an incoming connection from GenerateFlowFile already. Since Funnels are not stopped/scheduled, the `hasNonLoopConnection` field only gets populated when the Funnel is added. 
    `hasNonLoopConnection` becomes `false` for a newly created Funnels, and stays false even incoming connections are added later. ConnectableTasks for other components than Funnel can be recreated when the component is re-scheduled, however, those components should also NOT cache `hasNonLoopConnection` because NiFi allows new connections to be added while a component is running, without requiring stop/start.
    
    I will update the PR.


---

[GitHub] nifi pull request #2634: NIFI-5075: Do not execute Funnels with no outgoing ...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/nifi/pull/2634


---

[GitHub] nifi issue #2634: NIFI-5075: Do not execute Funnels with no outgoing connect...

Posted by markap14 <gi...@git.apache.org>.
Github user markap14 commented on the issue:

    https://github.com/apache/nifi/pull/2634
  
    @ijokarumawak that's great. Did you intend to push a new commit? The only commit that I see is from April 12th.


---

[GitHub] nifi issue #2634: NIFI-5075: Do not execute Funnels with no outgoing connect...

Posted by ottobackwards <gi...@git.apache.org>.
Github user ottobackwards commented on the issue:

    https://github.com/apache/nifi/pull/2634
  
    Is there a test to go along with this?


---