Skip to content

Commit

Permalink
HDDS-8188. Support max allowed length in response of ozone admin cont…
Browse files Browse the repository at this point in the history
…ainer list (apache#7181)
  • Loading branch information
sarvekshayr authored Oct 10, 2024
1 parent 7f2e0e3 commit 911a583
Show file tree
Hide file tree
Showing 18 changed files with 399 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ public final class ScmConfigKeys {
"hdds.ratis.snapshot.threshold";
public static final long HDDS_RATIS_SNAPSHOT_THRESHOLD_DEFAULT = 100000;

public static final String OZONE_SCM_CONTAINER_LIST_MAX_COUNT =
"ozone.scm.container.list.max.count";

public static final int OZONE_SCM_CONTAINER_LIST_MAX_COUNT_DEFAULT = 4096;

// TODO : this is copied from OzoneConsts, may need to move to a better place
public static final String OZONE_SCM_CHUNK_SIZE_KEY = "ozone.scm.chunk.size";
// 4 MB by default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.ContainerBalancerStatusInfoResponseProto;
import org.apache.hadoop.hdds.scm.DatanodeAdminError;
import org.apache.hadoop.hdds.scm.container.ContainerID;
import org.apache.hadoop.hdds.scm.container.ContainerListResult;
import org.apache.hadoop.hdds.scm.container.ContainerReplicaInfo;
import org.apache.hadoop.hdds.scm.container.ReplicationManagerReport;
import org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline;
Expand Down Expand Up @@ -122,10 +123,11 @@ void deleteContainer(long containerId, Pipeline pipeline, boolean force)
* @param startContainerID start containerID.
* @param count count must be {@literal >} 0.
*
* @return a list of pipeline.
* @return a list of containers capped by max count allowed
* in "ozone.scm.container.list.max.count" and total number of containers.
* @throws IOException
*/
List<ContainerInfo> listContainer(long startContainerID,
ContainerListResult listContainer(long startContainerID,
int count) throws IOException;

/**
Expand All @@ -135,10 +137,11 @@ List<ContainerInfo> listContainer(long startContainerID,
* @param count count must be {@literal >} 0.
* @param state Container of this state will be returned.
* @param replicationConfig container replication Config.
* @return a list of pipeline.
* @return a list of containers capped by max count allowed
* in "ozone.scm.container.list.max.count" and total number of containers.
* @throws IOException
*/
List<ContainerInfo> listContainer(long startContainerID, int count,
ContainerListResult listContainer(long startContainerID, int count,
HddsProtos.LifeCycleState state,
HddsProtos.ReplicationType replicationType,
ReplicationConfig replicationConfig)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.container;

import java.util.List;

/**
* Wrapper class for the result of listing containers with their total count.
*/
public class ContainerListResult {
private final List<ContainerInfo> containerInfoList;
private final long totalCount;

/**
* Constructs a new ContainerListResult.
*
* @param containerInfoList the list of containers
* @param totalCount the total number of containers
*/
public ContainerListResult(List<ContainerInfo> containerInfoList, long totalCount) {
this.containerInfoList = containerInfoList;
this.totalCount = totalCount;
}

/**
* Gets the list of containers.
*
* @return the list of containers
*/
public List<ContainerInfo> getContainerInfoList() {
return containerInfoList;
}

/**
* Gets the total count of containers.
*
* @return the total count of containers
*/
public long getTotalCount() {
return totalCount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.hadoop.hdds.scm.DatanodeAdminError;
import org.apache.hadoop.hdds.scm.ScmConfig;
import org.apache.hadoop.hdds.scm.ScmInfo;
import org.apache.hadoop.hdds.scm.container.ContainerListResult;
import org.apache.hadoop.hdds.scm.container.ContainerID;
import org.apache.hadoop.hdds.scm.container.ContainerInfo;
import org.apache.hadoop.hdds.scm.container.ReplicationManagerReport;
Expand Down Expand Up @@ -146,10 +147,11 @@ List<ContainerWithPipeline> getExistContainerWithPipelinesInBatch(
* Usually the count will be replace with a very big
* value instead of being unlimited in case the db is very big)
*
* @return a list of container.
* @return a list of containers capped by max count allowed
* in "ozone.scm.container.list.max.count" and total number of containers.
* @throws IOException
*/
List<ContainerInfo> listContainer(long startContainerID,
ContainerListResult listContainer(long startContainerID,
int count) throws IOException;

/**
Expand All @@ -165,10 +167,11 @@ List<ContainerInfo> listContainer(long startContainerID,
* value instead of being unlimited in case the db is very big)
* @param state Container with this state will be returned.
*
* @return a list of container.
* @return a list of containers capped by max count allowed
* in "ozone.scm.container.list.max.count" and total number of containers.
* @throws IOException
*/
List<ContainerInfo> listContainer(long startContainerID,
ContainerListResult listContainer(long startContainerID,
int count, HddsProtos.LifeCycleState state) throws IOException;

/**
Expand All @@ -184,14 +187,14 @@ List<ContainerInfo> listContainer(long startContainerID,
* value instead of being unlimited in case the db is very big)
* @param state Container with this state will be returned.
* @param factor Container factor
* @return a list of container.
* @return a list of containers capped by max count allowed
* in "ozone.scm.container.list.max.count" and total number of containers.
* @throws IOException
*/
List<ContainerInfo> listContainer(long startContainerID,
ContainerListResult listContainer(long startContainerID,
int count, HddsProtos.LifeCycleState state,
HddsProtos.ReplicationFactor factor) throws IOException;


/**
* Ask SCM for a list of containers with a range of container ID, state
* and replication config, and the limit of count.
Expand All @@ -205,10 +208,11 @@ List<ContainerInfo> listContainer(long startContainerID,
* value instead of being unlimited in case the db is very big)
* @param state Container with this state will be returned.
* @param replicationConfig Replication config for the containers
* @return a list of container.
* @return a list of containers capped by max count allowed
* in "ozone.scm.container.list.max.count" and total number of containers.
* @throws IOException
*/
List<ContainerInfo> listContainer(long startContainerID,
ContainerListResult listContainer(long startContainerID,
int count, HddsProtos.LifeCycleState state,
HddsProtos.ReplicationType replicationType,
ReplicationConfig replicationConfig) throws IOException;
Expand Down
7 changes: 7 additions & 0 deletions hadoop-hdds/common/src/main/resources/ozone-default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@
this not set. Ideally, this should be mapped to a fast disk like an SSD.
</description>
</property>
<property>
<name>ozone.scm.container.list.max.count</name>
<value>4096</value>
<tag>OZONE, SCM, CONTAINER</tag>
<description>The max number of containers info could be included in
response of ListContainer request.</description>
</property>
<property>
<name>hdds.datanode.dir</name>
<value/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
import org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.ContainerBalancerStatusInfoRequestProto;
import org.apache.hadoop.hdds.scm.DatanodeAdminError;
import org.apache.hadoop.hdds.scm.ScmInfo;
import org.apache.hadoop.hdds.scm.container.ContainerListResult;
import org.apache.hadoop.hdds.scm.container.ContainerID;
import org.apache.hadoop.hdds.scm.container.ContainerInfo;
import org.apache.hadoop.hdds.scm.container.ReplicationManagerReport;
Expand Down Expand Up @@ -389,19 +390,19 @@ public List<ContainerWithPipeline> getExistContainerWithPipelinesInBatch(
* {@inheritDoc}
*/
@Override
public List<ContainerInfo> listContainer(long startContainerID, int count)
public ContainerListResult listContainer(long startContainerID, int count)
throws IOException {
return listContainer(startContainerID, count, null, null, null);
}

@Override
public List<ContainerInfo> listContainer(long startContainerID, int count,
public ContainerListResult listContainer(long startContainerID, int count,
HddsProtos.LifeCycleState state) throws IOException {
return listContainer(startContainerID, count, state, null, null);
}

@Override
public List<ContainerInfo> listContainer(long startContainerID, int count,
public ContainerListResult listContainer(long startContainerID, int count,
HddsProtos.LifeCycleState state,
HddsProtos.ReplicationType replicationType,
ReplicationConfig replicationConfig)
Expand Down Expand Up @@ -443,12 +444,17 @@ public List<ContainerInfo> listContainer(long startContainerID, int count,
.getContainersList()) {
containerList.add(ContainerInfo.fromProtobuf(containerInfoProto));
}
return containerList;

if (response.hasContainerCount()) {
return new ContainerListResult(containerList, response.getContainerCount());
} else {
return new ContainerListResult(containerList, -1);
}
}

@Deprecated
@Override
public List<ContainerInfo> listContainer(long startContainerID, int count,
public ContainerListResult listContainer(long startContainerID, int count,
HddsProtos.LifeCycleState state, HddsProtos.ReplicationFactor factor)
throws IOException {
throw new UnsupportedOperationException("Should no longer be called from " +
Expand Down Expand Up @@ -1209,7 +1215,7 @@ public void close() {
public List<ContainerInfo> getListOfContainers(
long startContainerID, int count, HddsProtos.LifeCycleState state)
throws IOException {
return listContainer(startContainerID, count, state);
return listContainer(startContainerID, count, state).getContainerInfoList();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ message SCMListContainerRequestProto {

message SCMListContainerResponseProto {
repeated ContainerInfoProto containers = 1;
optional int64 containerCount = 2;
}

message SCMDeleteContainerRequestProto {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public class ContainerManagerImpl implements ContainerManager {
@SuppressWarnings("java:S2245") // no need for secure random
private final Random random = new Random();

private int maxCountOfContainerList;

/**
*
*/
Expand Down Expand Up @@ -115,6 +117,10 @@ public ContainerManagerImpl(
.getInt(ScmConfigKeys.OZONE_SCM_PIPELINE_OWNER_CONTAINER_COUNT,
ScmConfigKeys.OZONE_SCM_PIPELINE_OWNER_CONTAINER_COUNT_DEFAULT);

this.maxCountOfContainerList = conf
.getInt(ScmConfigKeys.OZONE_SCM_CONTAINER_LIST_MAX_COUNT,
ScmConfigKeys.OZONE_SCM_CONTAINER_LIST_MAX_COUNT_DEFAULT);

this.scmContainerManagerMetrics = SCMContainerManagerMetrics.create();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
import org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.ResetDeletedBlockRetryCountResponseProto;
import org.apache.hadoop.hdds.scm.DatanodeAdminError;
import org.apache.hadoop.hdds.scm.ScmInfo;
import org.apache.hadoop.hdds.scm.container.ContainerListResult;
import org.apache.hadoop.hdds.scm.container.ContainerID;
import org.apache.hadoop.hdds.scm.container.ContainerInfo;
import org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline;
Expand Down Expand Up @@ -857,21 +858,21 @@ public SCMListContainerResponseProto listContainer(
} else if (request.hasFactor()) {
factor = request.getFactor();
}
List<ContainerInfo> containerList;
ContainerListResult containerListAndTotalCount;
if (factor != null) {
// Call from a legacy client
containerList =
containerListAndTotalCount =
impl.listContainer(startContainerID, count, state, factor);
} else {
containerList =
impl.listContainer(startContainerID, count, state, replicationType,
repConfig);
containerListAndTotalCount =
impl.listContainer(startContainerID, count, state, replicationType, repConfig);
}
SCMListContainerResponseProto.Builder builder =
SCMListContainerResponseProto.newBuilder();
for (ContainerInfo container : containerList) {
for (ContainerInfo container : containerListAndTotalCount.getContainerInfoList()) {
builder.addContainers(container.getProtobuf());
}
builder.setContainerCount(containerListAndTotalCount.getTotalCount());
return builder.build();
}

Expand Down
Loading

0 comments on commit 911a583

Please sign in to comment.