[
https://issues.apache.org/jira/browse/NIFI-16629?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Pierre Villard updated NIFI-16629:
----------------------------------
Fix Version/s: 2.14.0
Resolution: Fixed
Status: Resolved (was: Patch Available)
> Cluster Coordinator does not synchronize assets when its local flow loses the
> flow election
> -------------------------------------------------------------------------------------------
>
> Key: NIFI-16629
> URL: https://issues.apache.org/jira/browse/NIFI-16629
> Project: Apache NiFi
> Issue Type: Bug
> Affects Versions: 2.12.0
> Reporter: Bryan Bende
> Assignee: Bryan Bende
> Priority: Major
> Fix For: 2.14.0
>
> Time Spent: 1.5h
> Remaining Estimate: 0h
>
> Asset synchronization assumes the Cluster Coordinator holds every asset the
> cluster flow references. That isn't guaranteed: coordinator election and flow
> election are independent. A node can become coordinator while its own flow
> loses the flow election, for example when it starts with empty repositories.
> It then inherits a flow that references assets it has never stored, and
> nothing ever fetches them.
> {{StandardAssetSynchronizer.synchronize()}} and
> {{StandardConnectorAssetSynchronizer.synchronize()}} both return early on the
> coordinator:
> {{if (clusterCoordinator.isActiveClusterCoordinator()) \{
> logger.info("Current node is the cluster coordinator: Asset
> synchronization disabled");
> return;
> }}}
> All other nodes pull assets only from the coordinator. When the coordinator
> didn't contribute the elected flow, the cluster has no path to repair its
> missing assets. Sync runs only from
> {{{}StandardFlowService.loadFromConnectionResponse(){}}}, so the condition
> persists until the coordinator restarts and loses the coordinator role.
> Steps to reproduce:
> # Run a 1-node cluster with Kubernetes leader election,
> {{{}nifi.cluster.flow.election.max.candidates=2{}}}, and a parameter context
> whose parameter references an asset, such as a JDBC driver JAR used by a
> DBCPConnectionPool.
> # Scale to 2 nodes. The new node 2 starts with empty repositories and no
> {{{}flow.json.gz{}}}.
> # Restart node 1 so that both nodes start together, for example by
> triggering an OutOfMemoryError on node 1 at the same time as the scale-up.
> # Node 2 acquires the coordinator lease first. Both nodes vote. Node 1's
> non-empty flow wins the flow election, as {{PopularVoteFlowElection}} intends.
> The reproduction doesn't depend on Kubernetes. Any coordinator election in
> which a node with an empty flow can win the coordinator role while another
> node's flow wins the flow election will do.
> Actual behavior:
> * Node 2, the coordinator, loads node 1's flow.
> {{VersionedFlowSynchronizer}} creates placeholder assets with no file on disk
> for every referenced asset.
> * Node 2 logs {{{}Current node is the cluster coordinator: Asset
> synchronization disabled{}}}.
> * Components that reference the assets on node 2 stay invalid. In this case
> the DBCPConnectionPool services couldn't find the driver files.
> * When node 1 connects, it lists assets from node 2. The listing returns
> {{missingContent=true}} and {{{}digest=null{}}}. Node 1 still has the file
> locally, so it takes the digest-comparison branch and hits a
> NullPointerException on
> {{{}coordinatorAssetDigest.equals(matchingAssetDigest){}}}. The exception is
> caught for each asset, so node 1 keeps its files, but every asset logs an
> error.
> * The cluster never recovers on its own. Restarting node 2 eventually fixes
> it, once node 2 is no longer coordinator and re-syncs as it reconnects.
> Expected behavior:
> The coordinator should get any missing asset content from the nodes whose
> flow was elected. Nodes that already have an asset should never treat a
> coordinator with missing content as a source of truth.
> Proposed fix:
> # Add a method to {{FlowElection}} that returns the nodes that voted for the
> elected flow, such as {{{}Set<NodeIdentifier>
> getElectedFlowNodeIdentifiers(){}}}. {{PopularVoteFlowElection}} already
> tracks these in {{{}FlowCandidate.getNodes(){}}}, so it only needs to keep
> the winning candidate in {{{}performElection(){}}}. Expose the same method on
> {{{}ClusterCoordinator{}}}, with a default that returns an empty set, and
> have {{NodeClusterCoordinator}} pass it through to the election.
> # In the asset synchronizers, replace the coordinator early-return with a
> coordinator path:
> ** Find the local assets that have no file on disk.
> ** If there are none, return without making any REST calls. This preserves
> current behavior in the normal case.
> ** Otherwise, query the elected-flow nodes through the existing
> {{{}AssetsRestApiClient{}}}. Skip any node that reports
> {{{}missingContent{}}}, fetch the file from the first node that has it, and
> restart the components that reference those assets.
> This works during startup. Clustered nodes start Jetty before
> {{{}FlowService.load(){}}}, asset managers read existing assets from disk at
> startup, and the asset GET endpoints let cluster-node requests skip
> parameter-context authorization. So a voting node can serve its assets while
> it's still connecting.
> # In the non-coordinator digest comparison, when the coordinator's asset has
> {{missingContent=true}} and the local file exists, keep the local file and
> log a warning instead of comparing digests. This removes the
> NullPointerException and prevents replacing valid content with missing
> content.
> For connector assets, {{StandardConnectorAssetManager.createMissingAsset()}}
> creates a random ID rather than a deterministic one. The connector path
> therefore needs to match assets on the IDs stored in the flow, not on IDs the
> coordinator generated locally.
> Related:
> {{StandardNarManager.syncWithClusterCoordinator()}} skips sync on the
> coordinator in the same way. If a NAR has been uploaded only to the node
> whose flow wins the election, an empty coordinator will load that flow with
> those components ghosted. The same approach could apply there, either in this
> issue or a follow-up.
>
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)