-
Notifications
You must be signed in to change notification settings - Fork 616
HDDS-9959. Propagate group remove to other datanodes during pipeline close #5827
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 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
49d0356
HDDS-9959. Propagate group remove to other datanodes during pipeline …
ivandika3 da492b1
Remove destroy pipeline logic from RatisPipelineUtils
ivandika3 0392153
Use equals
ivandika3 85aeb91
Add group id to log
ivandika3 83e7549
Remove MockitoExtension and use static import
ivandika3 5d139ff
Merge branch 'master' into HDDS-9959
ivandika3 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
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
139 changes: 139 additions & 0 deletions
139
...p/ozone/container/common/statemachine/commandhandler/TestClosePipelineCommandHandler.java
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 |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| /* | ||
| * 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 | ||
| * <p> | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * <p> | ||
| * 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.hadoop.ozone.container.common.statemachine.commandhandler; | ||
|
|
||
| import com.google.common.util.concurrent.MoreExecutors; | ||
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||
| import org.apache.hadoop.hdds.protocol.DatanodeDetails; | ||
| import org.apache.hadoop.hdds.protocol.MockDatanodeDetails; | ||
| import org.apache.hadoop.hdds.ratis.RatisHelper; | ||
| import org.apache.hadoop.hdds.scm.pipeline.PipelineID; | ||
| import org.apache.hadoop.ozone.container.common.ContainerTestUtils; | ||
| import org.apache.hadoop.ozone.container.common.statemachine.SCMConnectionManager; | ||
| import org.apache.hadoop.ozone.container.common.statemachine.StateContext; | ||
| import org.apache.hadoop.ozone.container.common.transport.server.ratis.XceiverServerRatis; | ||
| import org.apache.hadoop.ozone.container.ozoneimpl.OzoneContainer; | ||
| import org.apache.hadoop.ozone.protocol.commands.ClosePipelineCommand; | ||
| import org.apache.hadoop.ozone.protocol.commands.SCMCommand; | ||
| import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ClosePipelineCommandProto; | ||
| import org.apache.ratis.client.RaftClient; | ||
| import org.apache.ratis.client.api.GroupManagementApi; | ||
| import org.apache.ratis.protocol.RaftPeer; | ||
| import org.apache.ratis.protocol.RaftPeerId; | ||
| import org.apache.ratis.server.RaftServer; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.Mockito; | ||
| import org.mockito.junit.jupiter.MockitoExtension; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| /** | ||
| * Test cases to verify ClosePipelineCommandHandler. | ||
| */ | ||
| @ExtendWith(MockitoExtension.class) | ||
| public class TestClosePipelineCommandHandler { | ||
|
|
||
| private OzoneContainer ozoneContainer; | ||
| private StateContext stateContext; | ||
| private SCMConnectionManager connectionManager; | ||
| private RaftClient raftClient; | ||
| private GroupManagementApi raftClientGroupManager; | ||
| private OzoneConfiguration conf; | ||
|
|
||
| @BeforeEach | ||
| public void setup() throws Exception { | ||
| conf = new OzoneConfiguration(); | ||
| ozoneContainer = Mockito.mock(OzoneContainer.class); | ||
|
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. nit: Please add static import for
Contributor
Author
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. Thank you for the review. Updated. |
||
| connectionManager = Mockito.mock(SCMConnectionManager.class); | ||
| raftClient = Mockito.mock(RaftClient.class); | ||
| raftClientGroupManager = Mockito.mock(GroupManagementApi.class); | ||
| Mockito.lenient().when(raftClient.getGroupManagementApi( | ||
| Mockito.any(RaftPeerId.class))).thenReturn(raftClientGroupManager); | ||
| } | ||
|
|
||
| @Test | ||
| void testPipelineClose() throws IOException { | ||
| final List<DatanodeDetails> datanodes = getDatanodes(); | ||
| final DatanodeDetails currentDatanode = datanodes.get(0); | ||
| final PipelineID pipelineID = PipelineID.randomId(); | ||
| final SCMCommand<ClosePipelineCommandProto> command = | ||
| new ClosePipelineCommand(pipelineID); | ||
| stateContext = ContainerTestUtils.getMockContext(currentDatanode, conf); | ||
|
|
||
| final boolean shouldDeleteRatisLogDirectory = true; | ||
| XceiverServerRatis writeChannel = Mockito.mock(XceiverServerRatis.class); | ||
| Mockito.when(ozoneContainer.getWriteChannel()).thenReturn(writeChannel); | ||
| Mockito.when(writeChannel.getShouldDeleteRatisLogDirectory()).thenReturn(shouldDeleteRatisLogDirectory); | ||
| Mockito.when(writeChannel.isExist(pipelineID.getProtobuf())).thenReturn(true); | ||
| Collection<RaftPeer> raftPeers = datanodes.stream() | ||
| .map(RatisHelper::toRaftPeer) | ||
| .collect(Collectors.toList()); | ||
| Mockito.when(writeChannel.getServer()).thenReturn(Mockito.mock(RaftServer.class)); | ||
| Mockito.when(writeChannel.getServer().getId()).thenReturn(RatisHelper.toRaftPeerId(currentDatanode)); | ||
| Mockito.when(writeChannel.getRaftPeersInPipeline(pipelineID)).thenReturn(raftPeers); | ||
|
|
||
| final ClosePipelineCommandHandler commandHandler = | ||
| new ClosePipelineCommandHandler((leader, tls) -> raftClient, MoreExecutors.directExecutor()); | ||
| commandHandler.handle(command, ozoneContainer, stateContext, connectionManager); | ||
|
|
||
| Mockito.verify(writeChannel, Mockito.times(1)) | ||
| .removeGroup(pipelineID.getProtobuf()); | ||
|
|
||
| Mockito.verify(raftClientGroupManager, Mockito.times(2)) | ||
| .remove(Mockito.any(), Mockito.eq(shouldDeleteRatisLogDirectory), Mockito.eq(!shouldDeleteRatisLogDirectory)); | ||
| } | ||
|
|
||
| @Test | ||
| void testCommandIdempotency() throws IOException { | ||
| final List<DatanodeDetails> datanodes = getDatanodes(); | ||
| final DatanodeDetails currentDatanode = datanodes.get(0); | ||
| final PipelineID pipelineID = PipelineID.randomId(); | ||
| final SCMCommand<ClosePipelineCommandProto> command = | ||
| new ClosePipelineCommand(pipelineID); | ||
| stateContext = ContainerTestUtils.getMockContext(currentDatanode, conf); | ||
|
|
||
| XceiverServerRatis writeChannel = Mockito.mock(XceiverServerRatis.class); | ||
| Mockito.when(ozoneContainer.getWriteChannel()).thenReturn(writeChannel); | ||
| // When the pipeline has been closed earlier by other datanode that received a close pipeline command | ||
| Mockito.when(writeChannel.isExist(pipelineID.getProtobuf())).thenReturn(false); | ||
|
|
||
| final ClosePipelineCommandHandler commandHandler = | ||
| new ClosePipelineCommandHandler(conf, MoreExecutors.directExecutor()); | ||
| commandHandler.handle(command, ozoneContainer, stateContext, connectionManager); | ||
|
|
||
| Mockito.verify(writeChannel, Mockito.times(0)) | ||
| .removeGroup(pipelineID.getProtobuf()); | ||
|
|
||
| Mockito.verify(raftClientGroupManager, Mockito.times(0)) | ||
| .remove(Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean()); | ||
| } | ||
|
|
||
| private List<DatanodeDetails> getDatanodes() { | ||
| final DatanodeDetails dnOne = MockDatanodeDetails.randomDatanodeDetails(); | ||
| final DatanodeDetails dnTwo = MockDatanodeDetails.randomDatanodeDetails(); | ||
| final DatanodeDetails dnThree = MockDatanodeDetails.randomDatanodeDetails(); | ||
| return Arrays.asList(dnOne, dnTwo, dnThree); | ||
| } | ||
|
|
||
| } | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MockitoExtensionis unnecessary, there are no variables annotated as@Mock.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the review. Updated.
We might also need to remove this for
TestCreatePipelineCommandHandler.