You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by olegz <gi...@git.apache.org> on 2016/11/29 19:36:00 UTC

[GitHub] nifi pull request #1278: NIFI-2886 Fixed the lifecycle delay

GitHub user olegz opened a pull request:

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

    NIFI-2886 Fixed the lifecycle delay

    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:
    - [ ] Is there a JIRA ticket associated with this PR? Is it referenced 
         in the commit message?
    
    - [ ] 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.
    
    - [ ] Has your PR been rebased against the latest commit within the target branch (typically master)?
    
    - [ ] 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.
    
    - Fixed the intrinsic lifecycle delay on the Processor  caused by the administrativeYield wait on the re-submited OnScheduled task

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

    $ git pull https://github.com/olegz/nifi NIFI-2886

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

    https://github.com/apache/nifi/pull/1278.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 #1278
    
----
commit 706e167ea282b37008c2140bbc2c1838f382198e
Author: Oleg Zhurakousky <ol...@suitcase.io>
Date:   2016-11-29T13:42:09Z

    NIFI-2886 Fixed the lifecycle delay
    - Fixed the intrinsic lifecycle delay on the Processor  caused by the administrativeYield wait on the re-submited OnScheduled task

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi issue #1278: NIFI-2886 Fixed the lifecycle delay

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

    https://github.com/apache/nifi/pull/1278
  
    @olegz can you review/respond to Mark's feedback?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1278: NIFI-2886 Fixed the lifecycle delay

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

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


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1278: NIFI-2886 Fixed the lifecycle delay

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

    https://github.com/apache/nifi/pull/1278#discussion_r90308237
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardProcessorNode.java ---
    @@ -1385,15 +1387,32 @@ public void run() {
                     }
                 });
             } else {
    -            /*
    -             * We do compareAndSet() instead of set() to ensure that Processor
    -             * stoppage is handled consistently including a condition where
    -             * Processor never got a chance to transition to RUNNING state
    -             * before stop() was called. If that happens the stop processor
    -             * routine will be initiated in start() method, otherwise the IF
    -             * part will handle the stop processor routine.
    -             */
    -            this.scheduledState.compareAndSet(ScheduledState.STARTING, ScheduledState.STOPPING);
    +            synchronized (this) {
    +                if (onScheduleFuture != null) { // can only be null if stop was called before start
    +                    if (onScheduleFuture.cancel(false)) { // 'false' ensures we are not canceling the one in progress, only the scheduled one
    +                        /*
    +                         * We only want to transition to STOPPED stated in the
    +                         * event when stop was called by the user
    +                         * when @OnSchedule results in exception and is
    +                         * scheduled for re-try. However if @OnSchedule is
    +                         * currently executing we don't want to interrupt it,
    +                         * hence 'false' in the above 'cancel' call
    +                         */
    +                        this.scheduledState.compareAndSet(ScheduledState.STARTING, ScheduledState.STOPPED);
    +                    } else {
    +                        /*
    +                         * We do compareAndSet() instead of set() to ensure that
    +                         * Processor stoppage is handled consistently including
    +                         * a condition where Processor never got a chance to
    +                         * transition to RUNNING state before stop() was called.
    +                         * If that happens the stop processor routine will be
    +                         * initiated in start() method, otherwise the IF part
    +                         * will handle the stop processor routine.
    +                         */
    +                        this.scheduledState.compareAndSet(ScheduledState.STARTING, ScheduledState.STOPPING);
    --- End diff --
    
    I think we have a threading issue here. I will try to explain what I think can happen in chronological order, but these things are always difficult to explain. Suppose that we have two threads, T1 and T2. T1 is running in the start() method, while T2 is running in the stop() method. We could have the following series of events:
    
    T1: Line 1281, is calling @OnScheduled method of the Processor. It has set Scheduled State to STARTING.
    T2: Enters stop() method and line 1354 returns false because Scheduled State is STARTING.
    T2: At line 1391 it sees that onScheduleFuture is not null.
    T2: At line 1392, calls onScheduleFuture.cancel(false). However, T1 is still at line 1281. As a result, the call to Future.cancel() returns false because the future is currently executing and false indicates that the active task should not be canceled. So execution drops to the 'else' clause on line 1402.
    T1: Finishes invoking the @OnScheduled method and proceeds to line 1287. The call to compareAndSet returns true, changing the Scheduled State to RUNNING.
    T2: At line 1412, the call to scheduledState.compareAndSet returns false, because the Scheduled State is no longer STARTING but is now RUNNING. This means that Scheduled State remains RUNNING.
    T2: Returns from method.
    
    At this point, the Scheduled State does accurately represent the state that the Processor is operating in. However, the state is still RUNNING. This means that the call to stop() did not actually stop the Processor but in fact had no effect.
    
    Now I realize that this is very much a corner case, where the user would have to click Stop on the Processor at exactly the right time for this to occur. However, if this does happen, the stop() method will return without stopping the Processor. This is a bug.
    
    One simple solution may be to simply look at the return value on line 1412, and if the return value is false, recursively invoke the stop() method again with the same parameters (after exiting the synchronized block). Or, perhaps more cleanly, to wrap the entire outer-most if/else block in a loop that will continue if line 1412 returns false.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---