-
Notifications
You must be signed in to change notification settings - Fork 588
HDDS-8982. Infinite loop in WritableRatisContainerProvider if pipeline's nodes are not found #5742
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c7f57ab
fix infinite loop, add unit test
da60a77
update ozone-default.xml
289de98
update WritableECContainerProvider
76eb8cf
return 0 as containerID of broken pipeline, move config ozone.scm.get…
eb181ae
update unit test TestWritableRatisContainerProvider
c3dc5a4
properly mock value of MAX_RETRY_GET_CONTAINER in unit test TestWrita…
394edef
fix checkstyle
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
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
181 changes: 181 additions & 0 deletions
181
...src/test/java/org/apache/hadoop/hdds/scm/pipeline/TestWritableRatisContainerProvider.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,181 @@ | ||
| /* | ||
| * 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.hdds.scm.pipeline; | ||
|
|
||
| import org.apache.hadoop.hdds.client.ReplicationConfig; | ||
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||
| import org.apache.hadoop.hdds.scm.PipelineChoosePolicy; | ||
| import org.apache.hadoop.hdds.scm.PipelineRequestInformation; | ||
| import org.apache.hadoop.hdds.scm.container.ContainerInfo; | ||
| import org.apache.hadoop.hdds.scm.container.ContainerManager; | ||
| import org.apache.hadoop.hdds.scm.container.common.helpers.ExcludeList; | ||
| import org.apache.hadoop.hdds.scm.pipeline.choose.algorithms.HealthyPipelineChoosePolicy; | ||
| import org.apache.hadoop.hdds.scm.pipeline.choose.algorithms.RandomPipelineChoosePolicy; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
| import org.junit.runners.Parameterized; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.junit.jupiter.api.Assertions.fail; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.ArgumentMatchers.anyCollection; | ||
| import static org.mockito.ArgumentMatchers.anyList; | ||
| import static org.mockito.ArgumentMatchers.anyLong; | ||
| import static org.mockito.ArgumentMatchers.anySet; | ||
| import static org.mockito.ArgumentMatchers.anyString; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.spy; | ||
| import static org.mockito.Mockito.times; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
|
|
||
| /** | ||
| * Tests to validate the WritableRatisContainerProvider works correctly. | ||
| */ | ||
| public class TestWritableRatisContainerProvider { | ||
|
|
||
| private static final String OWNER = "SCM"; | ||
| private PipelineManager pipelineManager; | ||
| private ContainerManager containerManager; | ||
| private OzoneConfiguration conf; | ||
| private WritableRatisContainerProvider provider; | ||
| private ReplicationConfig repConfig; | ||
|
|
||
| private int testSCMGetContainerMaxRetry; | ||
|
|
||
| @Parameterized.Parameters | ||
| public static Collection<PipelineChoosePolicy> policies() { | ||
| Collection<PipelineChoosePolicy> policies = new ArrayList<>(); | ||
|
|
||
| Pipeline pipeline = mock(Pipeline.class); | ||
| RandomPipelineChoosePolicy randomPipelineChoosePolicy = | ||
| mock(RandomPipelineChoosePolicy.class); | ||
| when(randomPipelineChoosePolicy.choosePipeline(anyList(), | ||
| any(PipelineRequestInformation.class))).thenReturn(pipeline); | ||
|
|
||
| HealthyPipelineChoosePolicy healthyPipelineChoosePolicy = | ||
| mock(HealthyPipelineChoosePolicy.class); | ||
| when(healthyPipelineChoosePolicy.choosePipeline(anyList(), | ||
| any(PipelineRequestInformation.class))).thenReturn(pipeline); | ||
|
|
||
| policies.add(randomPipelineChoosePolicy); | ||
| policies.add(healthyPipelineChoosePolicy); | ||
|
|
||
| return policies; | ||
| } | ||
|
|
||
| void setup(PipelineChoosePolicy policy) { | ||
| conf = new OzoneConfiguration(); | ||
| testSCMGetContainerMaxRetry = 3; | ||
|
|
||
| repConfig = mock(ReplicationConfig.class); | ||
| pipelineManager = mock(PipelineManager.class); | ||
| containerManager = mock(ContainerManager.class); | ||
| provider = spy(new WritableRatisContainerProvider(conf, | ||
| pipelineManager, containerManager, policy)); | ||
| when(provider.getMaxRetryGetContainer()) | ||
| .thenReturn(testSCMGetContainerMaxRetry); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @MethodSource("policies") | ||
| public void testSelectContainerShouldNoMoreThanMaxRetry( | ||
| PipelineChoosePolicy policy) { | ||
| setup(policy); | ||
| List<Pipeline> pipelines = mock(ArrayList.class); | ||
| when(pipelines.size()).thenReturn(3); | ||
| when(pipelineManager.getPipelines(any(ReplicationConfig.class), | ||
| any(Pipeline.PipelineState.class), anyCollection(), | ||
| anyCollection())).thenReturn(pipelines); | ||
| ContainerInfo containerInfo = mock(ContainerInfo.class); | ||
| when(containerInfo.getContainerID()).thenReturn(0L); | ||
| when(containerManager.getMatchingContainer(anyLong(), anyString(), | ||
| any(Pipeline.class), anySet())).thenReturn(containerInfo); | ||
|
|
||
| ExcludeList exclude = mock(ExcludeList.class); | ||
|
|
||
| try { | ||
| provider.getContainer( | ||
| 1, repConfig, OWNER, exclude); | ||
| fail("expected IOException"); | ||
| } catch (IOException e) { | ||
| assertTrue(e.getMessage() | ||
| .contains("Unable to allocate a container to the block")); | ||
| } | ||
|
|
||
| verify(provider, times(testSCMGetContainerMaxRetry)) | ||
| .selectContainer(anyList(), anyLong(), | ||
| anyString(), any(ExcludeList.class)); | ||
| } | ||
|
|
||
|
|
||
| @ParameterizedTest | ||
| @MethodSource("policies") | ||
| public void testSelectContainerShouldNoMoreThanMaxRetryAfterCreateNewPipeline( | ||
| PipelineChoosePolicy policy) throws IOException { | ||
| setup(policy); | ||
| List<Pipeline> emptyPipelines = new ArrayList<>(); | ||
| List<Pipeline> pipelines = mock(ArrayList.class); | ||
| when(pipelines.size()).thenReturn(3); | ||
| when(pipelineManager.getPipelines(any(ReplicationConfig.class), | ||
| any(Pipeline.PipelineState.class), anyCollection(), anyCollection())) | ||
| .thenReturn(emptyPipelines, pipelines); | ||
|
|
||
| Pipeline pipeline1 = mock(Pipeline.class); | ||
| when(pipeline1.getId()).thenReturn(mock(PipelineID.class)); | ||
| when(pipelineManager.createPipeline(any(ReplicationConfig.class))) | ||
| .thenReturn(pipeline1); | ||
|
|
||
| ContainerInfo containerInfo = mock(ContainerInfo.class); | ||
| when(containerInfo.getContainerID()).thenReturn(0L); | ||
|
|
||
| PipelineID pipelineID2 = PipelineID.valueOf(UUID.randomUUID()); | ||
|
|
||
| when(containerInfo.getPipelineID()).thenReturn(pipelineID2); | ||
| when(containerManager.getMatchingContainer(anyLong(), anyString(), any( | ||
| Pipeline.class), anySet())).thenReturn(containerInfo); | ||
|
|
||
| ExcludeList exclude = new ExcludeList(); | ||
|
|
||
| try { | ||
| provider.getContainer( | ||
| 1, repConfig, OWNER, exclude); | ||
| fail("expected IOException"); | ||
| } catch (IOException e) { | ||
| assertTrue(e.getMessage(). | ||
| contains("Unable to allocate a container to the block")); | ||
| } | ||
|
|
||
| assertEquals(exclude.getPipelineIds(), | ||
| new HashSet<>(Arrays.asList(pipelineID2))); | ||
| verify(provider, times(testSCMGetContainerMaxRetry)) | ||
| .selectContainer(anyList(), anyLong(), anyString(), | ||
| any(ExcludeList.class)); | ||
| } | ||
|
|
||
| } |
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.
Trying to exclude the faulty pipeline may not work, because:
ozone/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/WritableRatisContainerProvider.java
Lines 192 to 196 in d1a92b9
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.
yeah, the reason I add it in the first part of findPipelinesByState(Line 100) of this method is to prevent that broken pipeline from being selected in the second part of findPipelinesByState (Line 164 , after pipelineManager.createPipeline) I just feel it's nice to have that, but it could be removed too. I'm open to any suggestion whether to keep it or not here. Thanks!