[ 
https://issues.apache.org/jira/browse/NIFI-16383?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Pierre Villard updated NIFI-16383:
----------------------------------
    Status: Patch Available  (was: Open)

> Make FlowController node connection state access lock-free
> ----------------------------------------------------------
>
>                 Key: NIFI-16383
>                 URL: https://issues.apache.org/jira/browse/NIFI-16383
>             Project: Apache NiFi
>          Issue Type: Improvement
>            Reporter: Pierre Villard
>            Assignee: Pierre Villard
>            Priority: Major
>
> *FlowController#getNodeConnectionState()* currently acquires the 
> FlowController read lock before reading the local node connection status.
> This can cause a circular wait during startup flow synchronization:
>  # FlowController#synchronize() holds the write lock while loading the flow.
>  # Controller Services are enabled on lifecycle threads, while the 
> synchronization thread waits for enablement.
>  # A Controller Service can call NodeTypeProvider#getNodeConnectionState() 
> from customValidate().
>  # FlowController#getNodeConnectionState() then waits for the read lock, 
> which cannot be acquired while synchronization holds the write lock.
>  # Synchronization waits for validation, and validation waits for 
> synchronization to release the lock.
> This reproduces the same class of 30-second Controller Service enablement 
> stall addressed for isClustered() by NIFI-16153.
> The lock is not required for memory visibility:
>  * configuredForClustering is final.
>  * connectionStatus is volatile.
>  * NodeConnectionStatus is immutable.
> Update FlowController#getNodeConnectionState() to read these fields without 
> acquiring the FlowController read lock. Preserve the existing return 
> semantics:
>  * Return STANDALONE when clustering is not configured.
>  * Return DISCONNECTED when clustering is configured but no local status is 
> available.
>  * Otherwise map the local framework connection state to the API 
> NodeConnectionState.
> Add focused coverage proving that the accessor:
>  * Returns the correct state without taking the FlowController read lock.
>  * Can be called from Controller Service validation while flow 
> synchronization holds the write lock.
>  * Does not block Controller Service enablement or cause the synchronization 
> timeout.
> This change allows components to use 
> NodeTypeProvider#getNodeConnectionState() during startup validation to defer 
> decisions while the node is CONNECTING, without reintroducing the 
> flow-synchronization lock inversion.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to