-
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 all 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
37 changes: 37 additions & 0 deletions
37
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,37 @@ | ||
| /** | ||
| * 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; | ||
|
|
||
| /** | ||
| * A {@link PipelineChoosePolicy} support choosing pipeline from exist list. | ||
| */ | ||
| public interface PipelineChoosePolicy { | ||
|
|
||
| /** | ||
| * 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, | ||
| PipelineRequestInformation pri); | ||
| } |
59 changes: 59 additions & 0 deletions
59
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/PipelineRequestInformation.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,59 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| /** | ||
| * The information of the request of pipeline. | ||
| */ | ||
| public final class PipelineRequestInformation { | ||
| private long size; | ||
|
|
||
| /** | ||
| * Builder for PipelineRequestInformation. | ||
| */ | ||
| public static class Builder { | ||
| private long size; | ||
|
|
||
| public static Builder getBuilder() { | ||
| return new Builder(); | ||
| } | ||
|
|
||
| /** | ||
| * sets the size. | ||
| * @param sz request size | ||
| * @return Builder for PipelineRequestInformation | ||
| */ | ||
| public Builder setSize(long sz) { | ||
| this.size = sz; | ||
| return this; | ||
| } | ||
|
|
||
| public PipelineRequestInformation build() { | ||
| return new PipelineRequestInformation(size); | ||
| } | ||
| } | ||
|
|
||
| private PipelineRequestInformation(long size) { | ||
| this.size = size; | ||
| } | ||
|
|
||
| public long getSize() { | ||
| return size; | ||
| } | ||
| } |
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
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.PipelineRequestInformation; | ||
| import org.apache.hadoop.hdds.scm.pipeline.Pipeline; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * The healthy pipeline choose policy that chooses pipeline | ||
| * until return healthy pipeline. | ||
| */ | ||
| public class HealthyPipelineChoosePolicy extends RandomPipelineChoosePolicy { | ||
|
|
||
| @Override | ||
| public Pipeline choosePipeline(List<Pipeline> pipelineList, | ||
| PipelineRequestInformation pri) { | ||
| Pipeline fallback = null; | ||
| while (pipelineList.size() > 0) { | ||
| Pipeline pipeline = super.choosePipeline(pipelineList, pri); | ||
| if (pipeline.isHealthy()) { | ||
| return pipeline; | ||
| } else { | ||
| fallback = pipeline; | ||
| pipelineList.remove(pipeline); | ||
| } | ||
| } | ||
| return fallback; | ||
| } | ||
| } |
106 changes: 106 additions & 0 deletions
106
...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,106 @@ | ||
| /** | ||
| * 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 com.google.common.annotations.VisibleForTesting; | ||
| import org.apache.hadoop.hdds.conf.ConfigurationSource; | ||
| import org.apache.hadoop.hdds.scm.PipelineChoosePolicy; | ||
| import org.apache.hadoop.hdds.scm.ScmConfig; | ||
| 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 ScmConfig}. | ||
| */ | ||
| public final class PipelineChoosePolicyFactory { | ||
| private static final Logger LOG = | ||
| LoggerFactory.getLogger(PipelineChoosePolicyFactory.class); | ||
|
|
||
| @VisibleForTesting | ||
| public static final Class<? extends PipelineChoosePolicy> | ||
| OZONE_SCM_PIPELINE_CHOOSE_POLICY_IMPL_DEFAULT = | ||
| RandomPipelineChoosePolicy.class; | ||
|
|
||
| private PipelineChoosePolicyFactory() { | ||
| } | ||
|
|
||
| public static PipelineChoosePolicy getPolicy( | ||
| ConfigurationSource conf) throws SCMException { | ||
| ScmConfig scmConfig = conf.getObject(ScmConfig.class); | ||
| Class<? extends PipelineChoosePolicy> policyClass = getClass( | ||
| scmConfig.getPipelineChoosePolicyName(), 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()); | ||
| } | ||
| } | ||
|
|
||
| private static <U> Class<? extends U> getClass(String name, | ||
| Class<U> xface) { | ||
| try { | ||
| Class<?> theClass = Class.forName(name); | ||
| if (!xface.isAssignableFrom(theClass)) { | ||
| throw new RuntimeException(theClass + " not " + xface.getName()); | ||
| } else { | ||
| return theClass.asSubclass(xface); | ||
| } | ||
| } catch (Exception e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| } | ||
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.