Repository navigation
HDDS-16798. Stale or Dead Datanodes whose software is not upgraded may still communicate with a finalized SCM #11692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a1fd827
HDDS-16798. Stale or Dead Datanodes whose software is not upgraded ma…
93b618f
Copilot review comments
09d2d00
Remove test added for copilot
d16f7c6
Change mock to return a healthy node
bbeaa96
Parameterize tests and add a test for healthy node not fenced
846cd55
Update jdoc
300d86e
Avoid processing command report and double calling sendFinalizeToData…
d54b3b7
Ensure the debug log gets called
1d028a4
Remove hasDatanodeVersion() check from isUnhealthyWithIncompatibleVer…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,12 +25,14 @@ | |
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.mockito.Mockito.any; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.never; | ||
| import static org.mockito.Mockito.times; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import java.util.stream.Stream; | ||
| import org.apache.hadoop.hdds.protocol.DatanodeDetails; | ||
| import org.apache.hadoop.hdds.protocol.DatanodeID; | ||
| import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.CommandStatusReportsProto; | ||
|
|
@@ -39,21 +41,25 @@ | |
| import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.NodeReportProto; | ||
| import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMHeartbeatRequestProto; | ||
| import org.apache.hadoop.hdds.scm.node.NodeManager; | ||
| import org.apache.hadoop.hdds.scm.node.NodeStatus; | ||
| import org.apache.hadoop.hdds.scm.node.states.NodeNotFoundException; | ||
| import org.apache.hadoop.hdds.scm.server.SCMDatanodeHeartbeatDispatcher.CommandStatusReportFromDatanode; | ||
| import org.apache.hadoop.hdds.scm.server.SCMDatanodeHeartbeatDispatcher.ContainerReportFromDatanode; | ||
| import org.apache.hadoop.hdds.scm.server.SCMDatanodeHeartbeatDispatcher.NodeReportFromDatanode; | ||
| import org.apache.hadoop.hdds.server.events.Event; | ||
| import org.apache.hadoop.hdds.server.events.EventPublisher; | ||
| import org.apache.hadoop.ozone.protocol.commands.ReregisterCommand; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
|
|
||
| /** | ||
| * This class tests the behavior of SCMDatanodeHeartbeatDispatcher. | ||
| */ | ||
| public class TestSCMDatanodeHeartbeatDispatcher { | ||
|
|
||
| @Test | ||
| public void testNodeReportDispatcher() throws IOException { | ||
| public void testNodeReportDispatcher() throws IOException, NodeNotFoundException { | ||
|
|
||
| AtomicInteger eventReceived = new AtomicInteger(); | ||
|
|
||
|
|
@@ -62,6 +68,7 @@ public void testNodeReportDispatcher() throws IOException { | |
| NodeManager mockNodeManager = mock(NodeManager.class); | ||
| when(mockNodeManager.isNodeRegistered(any())) | ||
| .thenReturn(true); | ||
| when(mockNodeManager.getNodeStatus(any())).thenReturn(NodeStatus.inServiceHealthy()); | ||
|
|
||
| SCMDatanodeHeartbeatDispatcher dispatcher = | ||
| new SCMDatanodeHeartbeatDispatcher(mockNodeManager, | ||
|
|
@@ -89,7 +96,7 @@ public <PAYLOAD, EVENT extends Event<PAYLOAD>> void fireEvent( | |
| } | ||
|
|
||
| @Test | ||
| public void testContainerReportDispatcher() throws IOException { | ||
| public void testContainerReportDispatcher() throws IOException, NodeNotFoundException { | ||
|
|
||
|
|
||
| AtomicInteger eventReceived = new AtomicInteger(); | ||
|
|
@@ -102,6 +109,7 @@ public void testContainerReportDispatcher() throws IOException { | |
| NodeManager mockNodeManager = mock(NodeManager.class); | ||
| when(mockNodeManager.isNodeRegistered(any())) | ||
| .thenReturn(true); | ||
| when(mockNodeManager.getNodeStatus(any())).thenReturn(NodeStatus.inServiceHealthy()); | ||
|
|
||
| SCMDatanodeHeartbeatDispatcher dispatcher = | ||
| new SCMDatanodeHeartbeatDispatcher( | ||
|
|
@@ -141,9 +149,10 @@ public <PAYLOAD, EVENT extends Event<PAYLOAD>> void fireEvent( | |
| } | ||
|
|
||
| @Test | ||
| public void testVersionReportProcessedOnlyWhenPresent() throws IOException { | ||
| public void testVersionReportProcessedOnlyWhenPresent() throws IOException, NodeNotFoundException { | ||
| NodeManager mockNodeManager = mock(NodeManager.class); | ||
| when(mockNodeManager.isNodeRegistered(any())).thenReturn(true); | ||
| when(mockNodeManager.getNodeStatus(any())).thenReturn(NodeStatus.inServiceHealthy()); | ||
|
|
||
| SCMDatanodeHeartbeatDispatcher dispatcher = | ||
| new SCMDatanodeHeartbeatDispatcher(mockNodeManager, mock(EventPublisher.class)); | ||
|
|
@@ -166,6 +175,84 @@ public void testVersionReportProcessedOnlyWhenPresent() throws IOException { | |
| verify(mockNodeManager, times(1)).processVersionReport(any(), any()); | ||
| } | ||
|
|
||
| private static Stream<NodeStatus> unhealthyNodeStatuses() { | ||
| return Stream.of(NodeStatus.inServiceStale(), NodeStatus.inServiceDead()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testHealthyNodeWithVersionReportIsNeverFenced() throws Exception { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test trivially passes regardless of the node status because |
||
| // Healthy nodes passed the version gate at registration; their version only changes on restart, | ||
| // which causes re-registration on its own. The dispatcher must never fence a healthy node. | ||
| NodeManager mockNodeManager = mock(NodeManager.class); | ||
| when(mockNodeManager.isNodeRegistered(any())).thenReturn(true); | ||
| when(mockNodeManager.getNodeStatus(any())).thenReturn(NodeStatus.inServiceHealthy()); | ||
|
|
||
| SCMDatanodeHeartbeatDispatcher dispatcher = | ||
| new SCMDatanodeHeartbeatDispatcher(mockNodeManager, mock(EventPublisher.class)); | ||
|
|
||
| DatanodeVersionProto version = DatanodeVersionProto.newBuilder() | ||
| .setApparentVersion(1).setSoftwareVersion(1).build(); | ||
| SCMHeartbeatRequestProto heartbeat = SCMHeartbeatRequestProto.newBuilder() | ||
| .setDatanodeDetails(randomDatanodeDetails().getProtoBufMessage()) | ||
| .setDatanodeVersion(version) | ||
| .build(); | ||
|
|
||
| dispatcher.dispatch(heartbeat); | ||
|
|
||
| verify(mockNodeManager, never()).addDatanodeCommand(any(DatanodeID.class), any(ReregisterCommand.class)); | ||
| verify(mockNodeManager, times(1)).processHeartbeat(any(), any()); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @MethodSource("unhealthyNodeStatuses") | ||
| public void testUnhealthyNodeWithIncompatibleVersionGetsReregisterCommand( | ||
| NodeStatus nodeStatus) throws Exception { | ||
| NodeManager mockNodeManager = mock(NodeManager.class); | ||
| when(mockNodeManager.isNodeRegistered(any())).thenReturn(true); | ||
| when(mockNodeManager.getNodeStatus(any())).thenReturn(nodeStatus); | ||
| when(mockNodeManager.shouldFenceDatanode(any(), any())).thenReturn(true); | ||
|
|
||
| SCMDatanodeHeartbeatDispatcher dispatcher = | ||
| new SCMDatanodeHeartbeatDispatcher(mockNodeManager, mock(EventPublisher.class)); | ||
|
|
||
| DatanodeVersionProto version = DatanodeVersionProto.newBuilder() | ||
| .setApparentVersion(1).setSoftwareVersion(1).build(); | ||
| SCMHeartbeatRequestProto heartbeat = SCMHeartbeatRequestProto.newBuilder() | ||
| .setDatanodeDetails(randomDatanodeDetails().getProtoBufMessage()) | ||
| .setDatanodeVersion(version) | ||
| .build(); | ||
|
|
||
| dispatcher.dispatch(heartbeat); | ||
|
|
||
| verify(mockNodeManager, times(1)).addDatanodeCommand(any(DatanodeID.class), any(ReregisterCommand.class)); | ||
| verify(mockNodeManager, never()).processHeartbeat(any(), any()); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @MethodSource("unhealthyNodeStatuses") | ||
| public void testUnhealthyNodeWithCompatibleVersionProcessesHeartbeatNormally( | ||
| NodeStatus nodeStatus) throws Exception { | ||
| NodeManager mockNodeManager = mock(NodeManager.class); | ||
| when(mockNodeManager.isNodeRegistered(any())).thenReturn(true); | ||
| when(mockNodeManager.getNodeStatus(any())).thenReturn(nodeStatus); | ||
| when(mockNodeManager.shouldFenceDatanode(any(), any())).thenReturn(false); | ||
|
|
||
| SCMDatanodeHeartbeatDispatcher dispatcher = | ||
| new SCMDatanodeHeartbeatDispatcher(mockNodeManager, mock(EventPublisher.class)); | ||
|
|
||
| DatanodeVersionProto version = DatanodeVersionProto.newBuilder() | ||
| .setApparentVersion(1).setSoftwareVersion(1).build(); | ||
| SCMHeartbeatRequestProto heartbeat = SCMHeartbeatRequestProto.newBuilder() | ||
| .setDatanodeDetails(randomDatanodeDetails().getProtoBufMessage()) | ||
| .setDatanodeVersion(version) | ||
| .build(); | ||
|
|
||
| dispatcher.dispatch(heartbeat); | ||
|
|
||
| verify(mockNodeManager, never()).addDatanodeCommand(any(DatanodeID.class), any(ReregisterCommand.class)); | ||
| verify(mockNodeManager, times(1)).processHeartbeat(any(), any()); | ||
| } | ||
|
|
||
| /** | ||
| * Asserts scm informs datanodes to re-register on a restart. | ||
| * | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.