Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ public final class ScmConfigKeys {
public static final String OZONE_SCM_PIPELINE_OWNER_CONTAINER_COUNT =
"ozone.scm.pipeline.owner.container.count";
public static final int OZONE_SCM_PIPELINE_OWNER_CONTAINER_COUNT_DEFAULT = 3;
// Pipeline choose policy:
public static final String OZONE_SCM_PIPELINE_CHOOSE_POLICY_IMPL_KEY =
"ozone.scm.pipeline.choose.policy.impl";
// Pipeline placement policy:
// Upper limit for how many pipelines a datanode can engage in.
public static final String OZONE_DATANODE_PIPELINE_LIMIT =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public enum ResultCodes {
FAILED_TO_FIND_ACTIVE_PIPELINE,
FAILED_TO_INIT_CONTAINER_PLACEMENT_POLICY,
FAILED_TO_ALLOCATE_ENOUGH_BLOCKS,
INTERNAL_ERROR
INTERNAL_ERROR,
FAILED_TO_INIT_PIPELINE_CHOOSE_POLICY
}
}
14 changes: 14 additions & 0 deletions hadoop-hdds/common/src/main/resources/ozone-default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,20 @@
value.
</description>
</property>
<property>
Copy link
Member

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

<name>ozone.scm.pipeline.choose.policy.impl</name>
<value>
org.apache.hadoop.hdds.scm.pipeline.choose.algorithms.RandomPipelineChoosePolicy
</value>
<tag>OZONE, MANAGEMENT</tag>
<description>
The full name of class which implements
org.apache.hadoop.hdds.scm.PipelineChoosePolicy.
The class decides which pipeline will be used to find or allocate container. If not set,
org.apache.hadoop.hdds.scm.pipeline.choose.algorithms.RandomPipelineChoosePolicy will be used as default
value.
</description>
</property>
<property>
<name>ozone.scm.pipeline.owner.container.count</name>
<value>3</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ enum Status {
FAILED_TO_INIT_CONTAINER_PLACEMENT_POLICY = 26;
FAILED_TO_ALLOCATE_ENOUGH_BLOCKS = 27;
INTERNAL_ERROR = 29;
FAILED_TO_INIT_PIPELINE_CHOOSE_POLICY = 30;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions hadoop-hdds/interface-server/src/main/resources/proto.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,10 @@
{
"name": "INTERNAL_ERROR",
"integer": 29
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proto.lock file change should be excluded. the proto.lock should represent and old state: the last released state to use it as a base for comparison.

Rebase to the latest master and you won't see the changed proto lock files (which makes it easy to add lock files accidentally)

{
"name": "FAILED_TO_INIT_PIPELINE_CHOOSE_POLICY",
"integer": 30
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ScmOps;
import org.apache.hadoop.hdds.scm.PipelineChoosePolicy;
import org.apache.hadoop.hdds.scm.ScmConfigKeys;
import org.apache.hadoop.hdds.scm.ScmUtils;
import org.apache.hadoop.hdds.scm.container.ContainerInfo;
Expand Down Expand Up @@ -77,6 +78,7 @@ public class BlockManagerImpl implements BlockManager, BlockmanagerMXBean {

private ObjectName mxBean;
private SafeModePrecheck safeModePrecheck;
private PipelineChoosePolicy pipelineChoosePolicy;

/**
* Constructor.
Expand All @@ -90,7 +92,7 @@ public BlockManagerImpl(final ConfigurationSource conf,
Objects.requireNonNull(scm, "SCM cannot be null");
this.pipelineManager = scm.getPipelineManager();
this.containerManager = scm.getContainerManager();

this.pipelineChoosePolicy = scm.getPipelineChoosePolicy();
this.containerSize = (long)conf.getStorageSize(
ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE,
ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE_DEFAULT,
Expand Down Expand Up @@ -222,9 +224,11 @@ public AllocatedBlock allocateBlock(final long size, ReplicationType type,
}

if (null == pipeline) {
// TODO: #CLUTIL Make the selection policy driven.
pipeline = availablePipelines
.get((int) (Math.random() * availablePipelines.size()));
Map<String, Object> params = new HashMap<>();
params.put(
PipelineChoosePolicy.PIPELINE_CHOOSE_POLICY_PARAM_SIZE, size);
pipeline = pipelineChoosePolicy.choosePipeline(
availablePipelines, params);
}

// look for OPEN containers that match the criteria.
Expand Down
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;
}
}
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();
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());
}
}
}
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()));
}
}
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.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.NodeState;
import org.apache.hadoop.hdds.scm.PipelineChoosePolicy;
import org.apache.hadoop.hdds.scm.PlacementPolicy;
import org.apache.hadoop.hdds.scm.ScmConfig;
import org.apache.hadoop.hdds.scm.ScmConfigKeys;
Expand Down Expand Up @@ -82,6 +83,7 @@
import org.apache.hadoop.hdds.scm.pipeline.PipelineManager;
import org.apache.hadoop.hdds.scm.pipeline.PipelineReportHandler;
import org.apache.hadoop.hdds.scm.pipeline.SCMPipelineManager;
import org.apache.hadoop.hdds.scm.pipeline.choose.algorithms.PipelineChoosePolicyFactory;
import org.apache.hadoop.hdds.scm.safemode.SCMSafeModeManager;
import org.apache.hadoop.hdds.security.exception.SCMSecurityException;
import org.apache.hadoop.hdds.security.x509.SecurityConfig;
Expand Down Expand Up @@ -199,6 +201,7 @@ public final class StorageContainerManager extends ServiceRuntimeInfoImpl
* Network topology Map.
*/
private NetworkTopology clusterMap;
private PipelineChoosePolicy pipelineChoosePolicy;

/**
* Creates a new StorageContainerManager. Configuration will be
Expand Down Expand Up @@ -421,6 +424,7 @@ private void initializeSystemManagers(OzoneConfiguration conf,
pipelineManager);
}

pipelineChoosePolicy = PipelineChoosePolicyFactory.getPolicy(conf);
if (configurator.getScmBlockManager() != null) {
scmBlockManager = configurator.getScmBlockManager();
} else {
Expand Down Expand Up @@ -1132,4 +1136,8 @@ public Map<String, String> getRuleStatusMetrics() {
}
return map;
}

public PipelineChoosePolicy getPipelineChoosePolicy() {
return this.pipelineChoosePolicy;
}
}