-
Notifications
You must be signed in to change notification settings - Fork 588
HDDS-3833. Use Pipeline choose policy to choose pipeline from exist pipeline list #1096
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 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3596e41
HDDS-3833. Use Pipeline choose policy to choose pipeline from exist p…
maobaolong 54bc1ea
HDDS-3833. Address comments, rename the key, add fallback code.
maobaolong 1d48df4
HDDS-3833. Address comments. Add a new policy.
maobaolong 85f8292
fix style.
maobaolong 7bdcbb9
Correct the ozone-default.xml
maobaolong c7b62a3
Address comments, create PipelineRequestInformation as the general pa…
maobaolong b16249d
Revert proto.lock
maobaolong d938116
Merge branch 'master' of https://github.com/apache/hadoop-ozone into …
maobaolong 5e9a203
Use Java based configuration API to write config.
maobaolong 9b7cfc5
fix style.
maobaolong 399d574
Add some tests.
maobaolong 8f3769d
fix test failed
maobaolong 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
41 changes: 41 additions & 0 deletions
41
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/PipelineChoosePolicy.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,41 @@ | ||
| /** | ||
| * 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; | ||
|
|
||
| import org.apache.hadoop.hdds.scm.pipeline.Pipeline; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * A {@link PipelineChoosePolicy} support choosing pipeline from exist list. | ||
| */ | ||
| public interface PipelineChoosePolicy { | ||
|
|
||
| String PIPELINE_CHOOSE_POLICY_PARAM_SIZE = | ||
| "pipeline_choose_policy_param_size"; | ||
|
|
||
| /** | ||
| * Given an initial list of pipelines, return one of the pipelines. | ||
| * | ||
| * @param pipelineList list of pipelines. | ||
| * @return one of the pipelines. | ||
| */ | ||
| Pipeline choosePipeline(List<Pipeline> pipelineList, | ||
| Map<String, Object> params); | ||
| } |
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
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 |
|---|---|---|
|
|
@@ -1209,6 +1209,10 @@ | |
| { | ||
| "name": "INTERNAL_ERROR", | ||
| "integer": 29 | ||
| }, | ||
|
||
| { | ||
| "name": "FAILED_TO_INIT_PIPELINE_CHOOSE_POLICY", | ||
| "integer": 30 | ||
| } | ||
| ] | ||
| }, | ||
|
|
||
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
46 changes: 46 additions & 0 deletions
46
...va/org/apache/hadoop/hdds/scm/pipeline/choose/algorithms/HealthyPipelineChoosePolicy.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,46 @@ | ||
| /** | ||
| * 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.choose.algorithms; | ||
|
|
||
| import org.apache.hadoop.hdds.scm.pipeline.Pipeline; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * The healthy pipeline choose policy that chooses pipeline | ||
| * until return healthy pipeline. | ||
| */ | ||
| public class HealthyPipelineChoosePolicy extends RandomPipelineChoosePolicy { | ||
|
|
||
| @Override | ||
| public Pipeline choosePipeline(List<Pipeline> pipelineList, | ||
| Map<String, Object> params) { | ||
| Pipeline fallback = null; | ||
| while (pipelineList.size() > 0) { | ||
| Pipeline pipeline = super.choosePipeline(pipelineList, params); | ||
| if (pipeline.isHealthy()) { | ||
| return pipeline; | ||
| } else { | ||
| fallback = pipeline; | ||
| pipelineList.remove(pipeline); | ||
| } | ||
| } | ||
| return fallback; | ||
| } | ||
| } |
90 changes: 90 additions & 0 deletions
90
...va/org/apache/hadoop/hdds/scm/pipeline/choose/algorithms/PipelineChoosePolicyFactory.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,90 @@ | ||
| /** | ||
| * 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 | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * 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.choose.algorithms; | ||
|
|
||
| import org.apache.hadoop.hdds.conf.ConfigurationSource; | ||
| import org.apache.hadoop.hdds.scm.PipelineChoosePolicy; | ||
| import org.apache.hadoop.hdds.scm.ScmConfigKeys; | ||
| import org.apache.hadoop.hdds.scm.exceptions.SCMException; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.lang.reflect.Constructor; | ||
|
|
||
| /** | ||
| * A factory to create pipeline choose policy instance based on configuration | ||
| * property {@link ScmConfigKeys#OZONE_SCM_PIPELINE_CHOOSE_POLICY_IMPL_KEY}. | ||
| */ | ||
| public final class PipelineChoosePolicyFactory { | ||
| private static final Logger LOG = | ||
| LoggerFactory.getLogger(PipelineChoosePolicyFactory.class); | ||
|
|
||
| private static final Class<? extends PipelineChoosePolicy> | ||
| OZONE_SCM_PIPELINE_CHOOSE_POLICY_IMPL_DEFAULT = | ||
| RandomPipelineChoosePolicy.class; | ||
|
|
||
| private PipelineChoosePolicyFactory() { | ||
| } | ||
|
|
||
| public static PipelineChoosePolicy getPolicy( | ||
| ConfigurationSource conf) throws SCMException { | ||
| final Class<? extends PipelineChoosePolicy> policyClass = conf | ||
| .getClass(ScmConfigKeys.OZONE_SCM_PIPELINE_CHOOSE_POLICY_IMPL_KEY, | ||
| OZONE_SCM_PIPELINE_CHOOSE_POLICY_IMPL_DEFAULT, | ||
| PipelineChoosePolicy.class); | ||
| try { | ||
| return createPipelineChoosePolicyFromClass(policyClass); | ||
| } catch (Exception e) { | ||
| if (policyClass != OZONE_SCM_PIPELINE_CHOOSE_POLICY_IMPL_DEFAULT) { | ||
| LOG.error("Met an exception while create pipeline choose policy " | ||
| + "for the given class " + policyClass.getName() | ||
| + ". Fallback to the default pipeline choose policy " | ||
| + OZONE_SCM_PIPELINE_CHOOSE_POLICY_IMPL_DEFAULT, e); | ||
| return createPipelineChoosePolicyFromClass( | ||
| OZONE_SCM_PIPELINE_CHOOSE_POLICY_IMPL_DEFAULT); | ||
| } | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| @NotNull | ||
| private static PipelineChoosePolicy createPipelineChoosePolicyFromClass( | ||
| Class<? extends PipelineChoosePolicy> policyClass) throws SCMException { | ||
| Constructor<? extends PipelineChoosePolicy> constructor; | ||
| try { | ||
| constructor = policyClass.getDeclaredConstructor(); | ||
avijayanhwx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| LOG.info("Create pipeline choose policy of type {}", | ||
| policyClass.getCanonicalName()); | ||
| } catch (NoSuchMethodException e) { | ||
| String msg = "Failed to find constructor() for class " + | ||
| policyClass.getCanonicalName(); | ||
| LOG.error(msg); | ||
| throw new SCMException(msg, | ||
| SCMException.ResultCodes.FAILED_TO_INIT_PIPELINE_CHOOSE_POLICY); | ||
| } | ||
|
|
||
| try { | ||
| return constructor.newInstance(); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException("Failed to instantiate class " + | ||
| policyClass.getCanonicalName() + " for " + e.getMessage()); | ||
| } | ||
| } | ||
| } | ||
38 changes: 38 additions & 0 deletions
38
...ava/org/apache/hadoop/hdds/scm/pipeline/choose/algorithms/RandomPipelineChoosePolicy.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,38 @@ | ||
| /** | ||
| * 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.choose.algorithms; | ||
|
|
||
| import org.apache.hadoop.hdds.scm.PipelineChoosePolicy; | ||
| import org.apache.hadoop.hdds.scm.pipeline.Pipeline; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Random choose policy that randomly chooses pipeline. | ||
| * That are we just randomly place containers without any considerations of | ||
| * utilization. | ||
| */ | ||
| public class RandomPipelineChoosePolicy implements PipelineChoosePolicy { | ||
|
|
||
| @Override | ||
| public Pipeline choosePipeline(List<Pipeline> pipelineList, | ||
| Map<String, Object> params) { | ||
| return pipelineList.get((int) (Math.random() * pipelineList.size())); | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
...scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/choose/algorithms/package-info.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,18 @@ | ||
| /** | ||
| * 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.choose.algorithms; | ||
| // Various pipeline choosing algorithms. |
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.
I would prefer to use the new, Java based configuration API:
https://cwiki.apache.org/confluence/display/HADOOP/Java-based+configuration+API