You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by jtstorck <gi...@git.apache.org> on 2018/09/18 21:20:35 UTC

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

GitHub user jtstorck opened a pull request:

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

    [WIP] NIFI-5585

    Please refer to https://issues.apache.org/jira/browse/NIFI-5585 for a description of use-cases for decommissioning nodes.  This PR is based off of work that is being done via https://issues.apache.org/jira/browse/NIFI-5516.
    
    This is a work-in-progress PR.  Nodes can be decommissioned, the flowfiles on the decommissioning node get moved to other nodes that are still connected to the cluster.
    
    A node can be decommissioned by first disconnecting it using the cluster node table's "Disconnect" icon, and then clicking on the "Decommission" icon.
    
    Some things that still need to be done in this PR:
    - Unit/integration tests need to be added
    - On the decommissioned node's UI, the status should represent its state.  Currently, a node that is being decommissioned will show as "Disconnected" on the node's UI.
    - Upgrading FontAwesome from 4.6.1 to 4.7 to use an icon for the "Decommission" action other than fa-sun-o, most likely window-close-o
    - There are various TODO markers in the code, where further testing needs to be done.  Also, some follow-on JIRAs will be created based off of some of the TODOs.

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

    $ git pull https://github.com/jtstorck/nifi NIFI-5585

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

    https://github.com/apache/nifi/pull/3010.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 #3010
    
----
commit fcc0fed53df4a65ce1e7275d67865d47b61c3bc1
Author: Mark Payne <ma...@...>
Date:   2018-06-14T15:57:21Z

    Refactoring StandardFlowFileQueue to have an AbstractFlowFileQueue
    Refactored more into AbstractFlowFileQueue
    Added documentation, cleaned up code some
    Refactored FlowFileQueue so that there is SwappablePriorityQueue
    Several unit tests written
    Added REST API Endpoint to allow PUT to update connection to use load balancing or not. When enabling load balancing, though, I saw the queue size go from 9 to 18. Then was only able to process 9 FlowFiles.
    Bug fixes
    Code refactoring
    Added integration tests, bug fixes
    Refactored clients to use NIO
    Bug fixes. Appears to finally be working with NIO Client!!!!!

commit 85606cbc200c49a0590c6979aa438addc42f8266
Author: Mark Payne <ma...@...>
Date:   2018-07-27T16:40:14Z

    NIFI-5516: Refactored some code from NioAsyncLoadBalanceClient to LoadBalanceSession
    Bug fixes and allowed load balancing socket connections to be reused
    Implemented ability to compress Nothing, Attributes, or Content + Attributes when performing load-balancing
    Added flag to ConnectionDTO to indicate Load Balance Status
    Updated Diagnostics DTO for connections
    Store state about cluster topology in NodeClusterCoordinator so that the state is known upon restart
    Code cleanup
    Fixed checkstyle and unit tests

commit d5d9a8ffedf080cfdfb6d8c0c83d498fd3c25022
Author: Mark Payne <ma...@...>
Date:   2018-09-06T13:09:08Z

    NIFI-5516: Updating logic for Cluster Node Firewall so that the node's identity comes from its certificate, not from whatever it says it is.

commit d5a3286252410e8ed2085ba2521e8f0053290bc9
Author: Mark Payne <ma...@...>
Date:   2018-09-10T21:06:05Z

    NIFI-5516: FIxed missing License headers

commit 5379a7cd2fe5620faf51cf8c95c8e6d78cc7a982
Author: Jeff Storck <jt...@...>
Date:   2018-09-18T21:09:13Z

    NIFI-5585 Added capability to decommission a node that is disconnected from the cluster.

----


---

[GitHub] nifi issue #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010
  
    While testing the reconnection of a decommissioned node, with ~24,000 files split between the two nodes, an error occurred after reconnecting the decomissioned node and attempting to drop all the flowfiles in the queue, from both nodes:
    ```
    2018-09-20 15:25:22,594 ERROR [Drop FlowFiles for Connection cbbf2971-0165-1000-ffff-ffff94b81269] o.a.n.c.q.c.SocketLoadBalancedFlowFileQueue Failed to drop FlowFiles for org.apache.nifi.controller.queue.clustered.SocketLoadBalancedFlowFileQueue@469caf69
    java.lang.IllegalArgumentException: null
    	at org.apache.nifi.controller.queue.QueueSize.<init>(QueueSize.java:31)
    	at org.apache.nifi.controller.queue.QueueSize.add(QueueSize.java:67)
    	at org.apache.nifi.controller.queue.clustered.SocketLoadBalancedFlowFileQueue.adjustSize(SocketLoadBalancedFlowFileQueue.java:514)
    	at org.apache.nifi.controller.queue.clustered.SocketLoadBalancedFlowFileQueue.dropFlowFiles(SocketLoadBalancedFlowFileQueue.java:903)
    	at org.apache.nifi.controller.queue.AbstractFlowFileQueue$2.run(AbstractFlowFileQueue.java:285)
    	at java.lang.Thread.run(Thread.java:748)
    ```
    The decommission operation was successful, all flowfiles were moved from the decommissioned node to the other node.  After reconnecting the decommissioned node, I couldn't clear the flowfile queue. 
    
    After restarting the cluster (both nodes), the queue showed as empty.


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r219599828
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/node/NodeClusterCoordinator.java ---
    @@ -821,7 +878,9 @@ void notifyOthersOfNodeStatusChange(final NodeConnectionStatus updatedStatus, fi
             // Otherwise, get the active coordinator (or wait for one to become active) and then notify the coordinator.
             final Set<NodeIdentifier> nodesToNotify;
             if (notifyAllNodes) {
    -            nodesToNotify = getNodeIdentifiers(NodeConnectionState.CONNECTED, NodeConnectionState.CONNECTING);
    +            // TODO notify all nodes
    --- End diff --
    
    Done.


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r220008088
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/queue/clustered/partition/NonLocalPartitionPartitioner.java ---
    @@ -0,0 +1,59 @@
    +/*
    + * 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.nifi.controller.queue.clustered.partition;
    +
    +import org.apache.nifi.controller.repository.FlowFileRecord;
    +
    +import java.util.concurrent.atomic.AtomicLong;
    +
    +/**
    + * PReturns remote partitions when queried for a partition; never returns the {@link LocalQueuePartition}.
    + */
    +public class NonLocalPartitionPartitioner implements FlowFilePartitioner {
    +    private final AtomicLong counter = new AtomicLong(0L);
    +
    +    @Override
    +    public QueuePartition getPartition(final FlowFileRecord flowFile, final QueuePartition[] partitions, final QueuePartition localPartition) {
    +        QueuePartition remotePartition = null;
    +        for (int i = 0, numPartitions = partitions.length; i < numPartitions; i++) {
    +            final long count = counter.getAndIncrement();
    --- End diff --
    
    Very good catch!  I've updated the partitioner to use a startIndex rather than the result of counter.getAndIncrement() each iteration.


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r219297604
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/queue/clustered/partition/NonLocalPartitionPartitioner.java ---
    @@ -0,0 +1,59 @@
    +/*
    + * 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.nifi.controller.queue.clustered.partition;
    +
    +import org.apache.nifi.controller.repository.FlowFileRecord;
    +
    +import java.util.concurrent.atomic.AtomicLong;
    +
    +/**
    + * PReturns remote partitions when queried for a partition; never returns the {@link LocalQueuePartition}.
    + */
    +public class NonLocalPartitionPartitioner implements FlowFilePartitioner {
    +    private final AtomicLong counter = new AtomicLong(0L);
    +
    +    @Override
    +    public QueuePartition getPartition(final FlowFileRecord flowFile, final QueuePartition[] partitions, final QueuePartition localPartition) {
    +        QueuePartition remotePartition = null;
    +        for (int i = 0, numPartitions = partitions.length; i < numPartitions; i++) {
    +            final long count = counter.getAndIncrement();
    --- End diff --
    
    I think the logic here is just a bit off, because if we have say 5 partitions but many threads, it could be the case that the first iteration gets count = 3 and that's the local partition. The next iteration could get count = 8 so index = 3, which is the local partition. The next iteration gets count = 13 so index = 3, then count = 18, then count = 23. At this point we'd have pointed to the local partition 5 times in a row and thrown IllegalStateException.
    
    Instead, I think we should do something like:
    {code}
    final long startIndex = counter.getAndIncrement();
    for (int i=0; i < partitions.length; i++) {
      final int index = (int) (startIndex + i) % partitions.length;
      final QueuePartition partition = partitions[index];
      ...
    }
    {code}
    
    This way, we still get the round-robin-ing effect but ensure that we try all partitions before throwing an IllegalStateException.


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r219296392
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/queue/clustered/SocketLoadBalancedFlowFileQueue.java ---
    @@ -534,6 +549,11 @@ public void setNodeIdentifiers(final Set<NodeIdentifier> updatedNodeIdentifiers,
                     return;
                 }
     
    +            // TODO check if queue is already decommissioned
    --- End diff --
    
    Can get rid of the TODO


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r222397907
  
    --- Diff: nifi-docs/src/main/asciidoc/administration-guide.adoc ---
    @@ -3929,6 +3929,13 @@ from the remote node before considering the communication with the node a failur
     to the cluster. It provides an additional layer of security. This value is blank by default, meaning that no firewall file is to be used.
     |`nifi.cluster.flow.election.max.wait.time`|Specifies the amount of time to wait before electing a Flow as the "correct" Flow. If the number of Nodes that have voted is equal to the number specified by the `nifi.cluster.flow.election.max.candidates` property, the cluster will not wait this long. The default value is `5 mins`. Note that the time starts as soon as the first vote is cast.
     |`nifi.cluster.flow.election.max.candidates`|Specifies the number of Nodes required in the cluster to cause early election of Flows. This allows the Nodes in the cluster to avoid having to wait a long time before starting processing if we reach at least this number of nodes in the cluster.
    +|`nifi.cluster.flow.election.max.wait.time`|Specifies the amount of time to wait before electing a Flow as the "correct" Flow. If the number of Nodes that have voted is equal to the number specified
    + by the `nifi.cluster.flow.election.max.candidates` property, the cluster will not wait this long. The default value is `5 mins`. Note that the time starts as soon as the first vote is cast.
    +|`nifi.cluster.flow.election.max.candidates`|Specifies the number of Nodes required in the cluster to cause early election of Flows. This allows the Nodes in the cluster to avoid having to wait a
    +long time before starting processing if we reach at least this number of nodes in the cluster.
    +|`nifi.cluster.load.balance.port`|Specifies the port to listen on for incoming connections for load balancing data across the cluster. The default value is `6342`.|
    +|`nifi.cluster.load.balance.host`|Specifies the hostname to listen on for incoming connections for load balancing data across the cluster. If not specified, will default to the value used by the `nifi
    --- End diff --
    
    The formatting in the table is off because the "|" at the end of line 3936 is not needed.


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r219599165
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/node/NodeClusterCoordinator.java ---
    @@ -494,6 +539,14 @@ public void requestNodeDisconnect(final NodeIdentifier nodeId, final Disconnecti
             disconnectAsynchronously(request, 10, 5);
         }
     
    +//    @Override
    --- End diff --
    
    Done.


---

[GitHub] nifi issue #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010
  
    While testing the reconnecting of a decommissioned node to the cluster, the issue detailed in [NIFI-5619](https://issues.apache.org/jira/browse/NIFI-5619) was encountered.


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r219607209
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/http/replication/ThreadPoolRequestReplicator.java ---
    @@ -180,6 +181,15 @@ public AsyncClusterResponse replicate(NiFiUser user, String method, URI uri, Obj
                     }
                 }
     
    +            final List<NodeIdentifier> decommissioning = stateMap.get(NodeConnectionState.DECOMMISSIONING);
    --- End diff --
    
    I agree.  If requests were replicated to nodes other than decommissioned nodes, then the decommissioned node would be out of sync with the rest of the cluster and would not be able to rejoin the cluster.  I added a check for the decommissioned state.


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r219601868
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/node/NodeClusterCoordinator.java ---
    @@ -841,6 +900,34 @@ void notifyOthersOfNodeStatusChange(final NodeConnectionStatus updatedStatus, fi
             senderListener.notifyNodeStatusChange(nodesToNotify, message);
         }
     
    +    private void decommissionAsynchronously(final DecommissionMessage request, final int attempts, final int retrySeconds) {
    +        final Thread decommissionThread = new Thread(new Runnable() {
    +            @Override
    +            public void run() {
    +                final NodeIdentifier nodeId = request.getNodeId();
    +
    +                for (int i = 0; i < attempts; i++) {
    +                    try {
    +                        senderListener.decommission(request);
    +                        reportEvent(nodeId, Severity.INFO, "Node was decommissioned due to " + request.getExplanation());
    +                        return;
    +                    } catch (final Exception e) {
    +                        logger.error("Failed to notify {} that it has been decommissioned from the cluster due to {}", request.getNodeId(), request.getExplanation());
    --- End diff --
    
    Done.


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r219599484
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/node/NodeClusterCoordinator.java ---
    @@ -526,6 +579,10 @@ public void removeNode(final NodeIdentifier nodeId, final String userDn) {
             storeState();
         }
     
    +    private void onNodeDecommissioned(final NodeIdentifier nodeId) {
    +        eventListeners.stream().forEach(listener -> listener.onNodeDecommissioned(nodeId));
    --- End diff --
    
    Done.


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r219294246
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/node/NodeClusterCoordinator.java ---
    @@ -841,6 +900,34 @@ void notifyOthersOfNodeStatusChange(final NodeConnectionStatus updatedStatus, fi
             senderListener.notifyNodeStatusChange(nodesToNotify, message);
         }
     
    +    private void decommissionAsynchronously(final DecommissionMessage request, final int attempts, final int retrySeconds) {
    +        final Thread decommissionThread = new Thread(new Runnable() {
    +            @Override
    +            public void run() {
    +                final NodeIdentifier nodeId = request.getNodeId();
    +
    +                for (int i = 0; i < attempts; i++) {
    +                    try {
    +                        senderListener.decommission(request);
    +                        reportEvent(nodeId, Severity.INFO, "Node was decommissioned due to " + request.getExplanation());
    +                        return;
    +                    } catch (final Exception e) {
    +                        logger.error("Failed to notify {} that it has been decommissioned from the cluster due to {}", request.getNodeId(), request.getExplanation());
    --- End diff --
    
    We should probably log the stack trace here as well.


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r219293820
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/node/NodeClusterCoordinator.java ---
    @@ -526,6 +579,10 @@ public void removeNode(final NodeIdentifier nodeId, final String userDn) {
             storeState();
         }
     
    +    private void onNodeDecommissioned(final NodeIdentifier nodeId) {
    +        eventListeners.stream().forEach(listener -> listener.onNodeDecommissioned(nodeId));
    +    }
    +
         private void onNodeRemoved(final NodeIdentifier nodeId) {
             eventListeners.stream().forEach(listener -> listener.onNodeRemoved(nodeId));
    --- End diff --
    
    Even though you didn't add this line, I see that it can also have the call to stream() removed :)


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r219293091
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/http/replication/ThreadPoolRequestReplicator.java ---
    @@ -180,6 +181,15 @@ public AsyncClusterResponse replicate(NiFiUser user, String method, URI uri, Obj
                     }
                 }
     
    +            final List<NodeIdentifier> decommissioning = stateMap.get(NodeConnectionState.DECOMMISSIONING);
    --- End diff --
    
    I think we need to also check for any nodes that are decommissioned as well. At first i thought maybe we should just allow it if a node is decommissioned. But then it's a little weird because the UI still will show 3/4 nodes connected (for example). And in all other cases, we would reject the request because the cluster is not at 100% connected. So I think we need to disallow even for decommissioned nodes.


---

[GitHub] nifi issue #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010
  
    @jtstorck I did just run into an issue that we will need to address. If we decommission 2 nodes at the same time (say Node 2 and Node 3) then we can end up in a state where Node 2 is trying to send to Node 3 (or vice versa) but the node is not connected. As a result, it ends up leaving the data in the queue.


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r219293350
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/node/NodeClusterCoordinator.java ---
    @@ -494,6 +539,14 @@ public void requestNodeDisconnect(final NodeIdentifier nodeId, final Disconnecti
             disconnectAsynchronously(request, 10, 5);
         }
     
    +//    @Override
    --- End diff --
    
    We can remove this.


---

[GitHub] nifi pull request #3010: NIFI-5585 Support Offloading a NiFi Node

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

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


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r220000525
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowService.java ---
    @@ -662,6 +682,39 @@ private void handleReconnectionRequest(final ReconnectionRequestMessage request)
             }
         }
     
    +    private void handleDecommissionRequest(final DecommissionMessage request) throws InterruptedException {
    +        logger.info("Received decommission request message from manager with explanation: " + request.getExplanation());
    +        decommission(request.getExplanation());
    +    }
    +
    +    private void decommission(final String explanation) throws InterruptedException {
    +        writeLock.lock();
    +        try {
    +
    +            logger.info("Decommissioning node due to " + explanation);
    +
    +            // mark node as decommissioning
    +            controller.setConnectionStatus(new NodeConnectionStatus(nodeId, NodeConnectionState.DECOMMISSIONING, DecommissionCode.DECOMMISSIONED, explanation));
    +            // request to stop all processors on node
    +            controller.stopAllProcessors();
    --- End diff --
    
    Done.  Also, all RPGs will have stopTransmitting() called on them.


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r219602056
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/heartbeat/TestAbstractHeartbeatMonitor.java ---
    @@ -244,11 +245,26 @@ public synchronized void finishNodeConnection(NodeIdentifier nodeId) {
                 statuses.put(nodeId, new NodeConnectionStatus(nodeId, NodeConnectionState.CONNECTED));
             }
     
    +        @Override
    +        public synchronized void finishNodeDecommission(NodeIdentifier nodeId) {
    +            statuses.put(nodeId, new NodeConnectionStatus(nodeId, NodeConnectionState.DECOMMISSIONED));
    +        }
    +
    +        @Override
    +        public synchronized void requestNodeDecommission(NodeIdentifier nodeId, DecommissionCode decommissionCode, String explanation) {
    +            statuses.put(nodeId, new NodeConnectionStatus(nodeId, NodeConnectionState.DECOMMISSIONED));
    +        }
    +
             @Override
             public synchronized void requestNodeDisconnect(NodeIdentifier nodeId, DisconnectionCode disconnectionCode, String explanation) {
                 statuses.put(nodeId, new NodeConnectionStatus(nodeId, NodeConnectionState.DISCONNECTED));
             }
     
    +//        @Override
    --- End diff --
    
    Done.


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r219294892
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowService.java ---
    @@ -662,6 +682,39 @@ private void handleReconnectionRequest(final ReconnectionRequestMessage request)
             }
         }
     
    +    private void handleDecommissionRequest(final DecommissionMessage request) throws InterruptedException {
    +        logger.info("Received decommission request message from manager with explanation: " + request.getExplanation());
    --- End diff --
    
    I think this should say "from cluster coordinator" rather than "from manager"


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r219271614
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/ClusterCoordinator.java ---
    @@ -72,6 +91,16 @@
          */
         void requestNodeDisconnect(NodeIdentifier nodeId, DisconnectionCode disconnectionCode, String explanation);
     
    +//    /**
    --- End diff --
    
    We can get rid of this code that's commented out.


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r219296344
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/queue/clustered/SocketLoadBalancedFlowFileQueue.java ---
    @@ -204,6 +206,19 @@ public synchronized void setLoadBalanceStrategy(final LoadBalanceStrategy strate
             setFlowFilePartitioner(partitioner);
         }
     
    +    @Override
    +    public void decommissionQueue() {
    +        if (clusterCoordinator == null) {
    +            // Not clustered, so don't change partitions
    +            return;
    +        }
    +
    +        // TODO set decommissioned boolean
    --- End diff --
    
    I think the TODO can go


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r219612683
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowService.java ---
    @@ -662,6 +682,39 @@ private void handleReconnectionRequest(final ReconnectionRequestMessage request)
             }
         }
     
    +    private void handleDecommissionRequest(final DecommissionMessage request) throws InterruptedException {
    +        logger.info("Received decommission request message from manager with explanation: " + request.getExplanation());
    --- End diff --
    
    I replaced all occurrences of "from manager" with "from cluster coordinator".


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r219598024
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/ClusterCoordinator.java ---
    @@ -72,6 +91,16 @@
          */
         void requestNodeDisconnect(NodeIdentifier nodeId, DisconnectionCode disconnectionCode, String explanation);
     
    +//    /**
    --- End diff --
    
    Done.


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r219296555
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/queue/clustered/partition/NonLocalPartitionPartitioner.java ---
    @@ -0,0 +1,59 @@
    +/*
    + * 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.nifi.controller.queue.clustered.partition;
    +
    +import org.apache.nifi.controller.repository.FlowFileRecord;
    +
    +import java.util.concurrent.atomic.AtomicLong;
    +
    +/**
    + * PReturns remote partitions when queried for a partition; never returns the {@link LocalQueuePartition}.
    --- End diff --
    
    Typo: "PReturns"


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r220000790
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/queue/clustered/partition/NonLocalPartitionPartitioner.java ---
    @@ -0,0 +1,59 @@
    +/*
    + * 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.nifi.controller.queue.clustered.partition;
    +
    +import org.apache.nifi.controller.repository.FlowFileRecord;
    +
    +import java.util.concurrent.atomic.AtomicLong;
    +
    +/**
    + * PReturns remote partitions when queried for a partition; never returns the {@link LocalQueuePartition}.
    --- End diff --
    
    Fixed.


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r220000647
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/queue/clustered/SocketLoadBalancedFlowFileQueue.java ---
    @@ -204,6 +206,19 @@ public synchronized void setLoadBalanceStrategy(final LoadBalanceStrategy strate
             setFlowFilePartitioner(partitioner);
         }
     
    +    @Override
    +    public void decommissionQueue() {
    +        if (clusterCoordinator == null) {
    +            // Not clustered, so don't change partitions
    +            return;
    +        }
    +
    +        // TODO set decommissioned boolean
    --- End diff --
    
    It can!


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r219599522
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/node/NodeClusterCoordinator.java ---
    @@ -526,6 +579,10 @@ public void removeNode(final NodeIdentifier nodeId, final String userDn) {
             storeState();
         }
     
    +    private void onNodeDecommissioned(final NodeIdentifier nodeId) {
    +        eventListeners.stream().forEach(listener -> listener.onNodeDecommissioned(nodeId));
    +    }
    +
         private void onNodeRemoved(final NodeIdentifier nodeId) {
             eventListeners.stream().forEach(listener -> listener.onNodeRemoved(nodeId));
    --- End diff --
    
    Done.


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r219295502
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowService.java ---
    @@ -662,6 +682,39 @@ private void handleReconnectionRequest(final ReconnectionRequestMessage request)
             }
         }
     
    +    private void handleDecommissionRequest(final DecommissionMessage request) throws InterruptedException {
    +        logger.info("Received decommission request message from manager with explanation: " + request.getExplanation());
    +        decommission(request.getExplanation());
    +    }
    +
    +    private void decommission(final String explanation) throws InterruptedException {
    +        writeLock.lock();
    +        try {
    +
    +            logger.info("Decommissioning node due to " + explanation);
    +
    +            // mark node as decommissioning
    +            controller.setConnectionStatus(new NodeConnectionStatus(nodeId, NodeConnectionState.DECOMMISSIONING, DecommissionCode.DECOMMISSIONED, explanation));
    +            // request to stop all processors on node
    +            controller.stopAllProcessors();
    --- End diff --
    
    In addition to calling stopAllProcessors() I think we should be terminating all active processors as well. We can do this by getting the Root Process Group from the FlowController, then from that getting all Processors and for each one if processor.getScheduledState() == ScheduledState.STOPPED (do this in case a processor is disabled), call ProcessGroup.terminateProcessor(ProcessorNode) and then recursing through all groups.
    
    This will ensure that even if a Processor has hold of a FlowFile and makes no progress we can still push the FlowFiles out to other nodes in the cluster in order to decommission.


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r219294399
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/heartbeat/TestAbstractHeartbeatMonitor.java ---
    @@ -244,11 +245,26 @@ public synchronized void finishNodeConnection(NodeIdentifier nodeId) {
                 statuses.put(nodeId, new NodeConnectionStatus(nodeId, NodeConnectionState.CONNECTED));
             }
     
    +        @Override
    +        public synchronized void finishNodeDecommission(NodeIdentifier nodeId) {
    +            statuses.put(nodeId, new NodeConnectionStatus(nodeId, NodeConnectionState.DECOMMISSIONED));
    +        }
    +
    +        @Override
    +        public synchronized void requestNodeDecommission(NodeIdentifier nodeId, DecommissionCode decommissionCode, String explanation) {
    +            statuses.put(nodeId, new NodeConnectionStatus(nodeId, NodeConnectionState.DECOMMISSIONED));
    +        }
    +
             @Override
             public synchronized void requestNodeDisconnect(NodeIdentifier nodeId, DisconnectionCode disconnectionCode, String explanation) {
                 statuses.put(nodeId, new NodeConnectionStatus(nodeId, NodeConnectionState.DISCONNECTED));
             }
     
    +//        @Override
    --- End diff --
    
    Can remove.


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r219293897
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/node/NodeClusterCoordinator.java ---
    @@ -821,7 +878,9 @@ void notifyOthersOfNodeStatusChange(final NodeConnectionStatus updatedStatus, fi
             // Otherwise, get the active coordinator (or wait for one to become active) and then notify the coordinator.
             final Set<NodeIdentifier> nodesToNotify;
             if (notifyAllNodes) {
    -            nodesToNotify = getNodeIdentifiers(NodeConnectionState.CONNECTED, NodeConnectionState.CONNECTING);
    +            // TODO notify all nodes
    --- End diff --
    
    I think we can remove this TODO and the line below it.


---

[GitHub] nifi pull request #3010: [WIP] NIFI-5585

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

    https://github.com/apache/nifi/pull/3010#discussion_r219293725
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/node/NodeClusterCoordinator.java ---
    @@ -526,6 +579,10 @@ public void removeNode(final NodeIdentifier nodeId, final String userDn) {
             storeState();
         }
     
    +    private void onNodeDecommissioned(final NodeIdentifier nodeId) {
    +        eventListeners.stream().forEach(listener -> listener.onNodeDecommissioned(nodeId));
    --- End diff --
    
    Can get rid of the call to stream() here and just call forEach() on eventListeners.


---

[GitHub] nifi issue #3010: NIFI-5585 Support Offloading a NiFi Node

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

    https://github.com/apache/nifi/pull/3010
  
    @jtstorck I've reviewed this PR and offloading scenarios, too. Successfully offloaded multiple nodes at the same time, and confirmed I can offload nodes from UI or NiFi CLI. Thanks for this improvement, I'm +1!


---