-
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
Changes from 3 commits
c7f57ab
da60a77
289de98
76eb8cf
eb181ae
c3dc5a4
394edef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -36,6 +36,9 @@ | |||||||||||
| import java.util.List; | ||||||||||||
| import java.util.stream.Collectors; | ||||||||||||
|
|
||||||||||||
| import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_GET_CONTAINER_MAX_RETRY; | ||||||||||||
| import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_GET_CONTAINER_MAX_RETRY_DEFAULT; | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Class to obtain a writable container for Ratis and Standalone pipelines. | ||||||||||||
| */ | ||||||||||||
|
|
@@ -49,6 +52,8 @@ public class WritableRatisContainerProvider | |||||||||||
| private final PipelineManager pipelineManager; | ||||||||||||
| private final PipelineChoosePolicy pipelineChoosePolicy; | ||||||||||||
| private final ContainerManager containerManager; | ||||||||||||
| private int maxRetryGetContainer; | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| public WritableRatisContainerProvider(ConfigurationSource conf, | ||||||||||||
| PipelineManager pipelineManager, | ||||||||||||
|
|
@@ -58,6 +63,8 @@ public WritableRatisContainerProvider(ConfigurationSource conf, | |||||||||||
| this.pipelineManager = pipelineManager; | ||||||||||||
| this.containerManager = containerManager; | ||||||||||||
| this.pipelineChoosePolicy = pipelineChoosePolicy; | ||||||||||||
| this.maxRetryGetContainer = conf.getInt(OZONE_SCM_GET_CONTAINER_MAX_RETRY, | ||||||||||||
| OZONE_SCM_GET_CONTAINER_MAX_RETRY_DEFAULT); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
|
|
@@ -85,8 +92,8 @@ public ContainerInfo getContainer(final long size, | |||||||||||
| //TODO we need to continue the refactor to use repConfig everywhere | ||||||||||||
| //in downstream managers. | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| while (true) { | ||||||||||||
| int currentCount = 0; | ||||||||||||
| while (currentCount < maxRetryGetContainer) { | ||||||||||||
| List<Pipeline> availablePipelines; | ||||||||||||
| Pipeline pipeline; | ||||||||||||
| // Acquire pipeline manager lock, to avoid any updates to pipeline | ||||||||||||
|
|
@@ -103,7 +110,13 @@ public ContainerInfo getContainer(final long size, | |||||||||||
| excludeList); | ||||||||||||
| } | ||||||||||||
| if (containerInfo != null) { | ||||||||||||
| return containerInfo; | ||||||||||||
| // if containerID == -1, means Container allocation | ||||||||||||
| // failed on selected pipeline | ||||||||||||
| if (containerInfo.getContainerID() != -1) { | ||||||||||||
| return containerInfo; | ||||||||||||
| } else { | ||||||||||||
| excludeList.addPipeline(containerInfo.getPipelineID()); | ||||||||||||
|
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. Trying to exclude the faulty pipeline may not work, because: Lines 192 to 196 in d1a92b9
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. 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! |
||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| } finally { | ||||||||||||
| pipelineManager.releaseReadLock(); | ||||||||||||
|
|
@@ -164,12 +177,17 @@ public ContainerInfo getContainer(final long size, | |||||||||||
| containerInfo = selectContainer(availablePipelines, size, owner, | ||||||||||||
| excludeList); | ||||||||||||
| if (containerInfo != null) { | ||||||||||||
| return containerInfo; | ||||||||||||
| if (containerInfo.getContainerID() != -1) { | ||||||||||||
| return containerInfo; | ||||||||||||
| } else { | ||||||||||||
| excludeList.addPipeline(containerInfo.getPipelineID()); | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| } finally { | ||||||||||||
| pipelineManager.releaseReadLock(); | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| currentCount++; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // we have tried all strategies we know but somehow we are not able | ||||||||||||
|
|
@@ -197,7 +215,7 @@ private List<Pipeline> findPipelinesByState( | |||||||||||
| return pipelines; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| private ContainerInfo selectContainer(List<Pipeline> availablePipelines, | ||||||||||||
| protected ContainerInfo selectContainer(List<Pipeline> availablePipelines, | ||||||||||||
| long size, String owner, ExcludeList excludeList) { | ||||||||||||
| Pipeline pipeline; | ||||||||||||
| ContainerInfo containerInfo; | ||||||||||||
|
|
||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| /* | ||
| * 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.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_GET_CONTAINER_MAX_RETRY; | ||
| 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; | ||
| conf.setInt(OZONE_SCM_GET_CONTAINER_MAX_RETRY, | ||
| testSCMGetContainerMaxRetry); | ||
|
|
||
| repConfig = mock(ReplicationConfig.class); | ||
| pipelineManager = mock(PipelineManager.class); | ||
| containerManager = mock(ContainerManager.class); | ||
| provider = spy(new WritableRatisContainerProvider(conf, | ||
| pipelineManager, containerManager, policy)); | ||
| } | ||
|
|
||
| @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(-1L); | ||
| 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(-1L); | ||
|
|
||
| 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)); | ||
| } | ||
|
|
||
| } |
Uh oh!
There was an error while loading. Please reload this page.