HDDS-5249. Race Condition between Full and Incremental Container Reports #2268
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
During testing we came across an issue with ICR and FCR handing.
The following log shows the issue:
In the above log, SCM is processing both an ICR and FCR for the same Datanode at the same time. The FCR does not container container #1001.
The FCR starts first, and it takes a snapshot of the containers on the node via NodeManager.
Then it starts processing the containers one by one.
The ICR then starts, and it added #1001 to the ContainerManager and to the NodeManager.
When the FCR completes, it replaces the list of containers in NodeManager with those in the FCR.
At this point, container #1001 is in the ContainerManager, but it is not listed against the node in NodeManager.
This would get fixed by the next FCR, but then the node goes dead. The dead node handler runs and uses the list of containers in NodeManager to remove all containers for the node. As #1001 is not listed, it is not removed by the DeadNodeManager. This means the container will never been seen as under replicated, as 3 copies will exist forever in the ContainerManager.
This issue is quite tricky to fully fix. There are two issues:
Parallel processing of ICR and FCR can lead to data inconsistency between the ComtainerManager and NodeManager. This is what caused the bug above.
A FCR wiping out a reference to a container recently sent in an ICR, but which is not included in the FCR.
The second issue is less serious, as the next FCR will fix the problem, as the FCRs are produced approximately every 60 seconds by default.
We can fix problem 1 quite easily by synchronising on the datanode when processing FCRs and ICRs, that will ensure the data inconsistency will not happen.
This PR is for issue 1, and we should probably create a followup issue for 2.
What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-5249
How was this patch tested?
Added a new test to reproduce the race condition and verified it passes after the code change.