ChenSammi commented on code in PR #5047: URL: https://github.com/apache/ozone/pull/5047#discussion_r1302793909
########## hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/impl/BlockDeletingService.java: ########## @@ -0,0 +1,290 @@ +/** + * 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.ozone.container.common.impl; + +import org.apache.hadoop.hdds.conf.ConfigurationSource; +import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos; +import org.apache.hadoop.hdds.scm.ScmConfigKeys; +import org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException; +import org.apache.hadoop.hdds.scm.pipeline.PipelineID; +import org.apache.hadoop.hdds.utils.BackgroundService; +import org.apache.hadoop.hdds.utils.BackgroundTask; +import org.apache.hadoop.hdds.utils.BackgroundTaskQueue; +import org.apache.hadoop.ozone.container.common.helpers.BlockDeletingServiceMetrics; +import org.apache.hadoop.ozone.container.common.helpers.ContainerUtils; +import org.apache.hadoop.ozone.container.common.interfaces.ContainerDeletionChoosingPolicy; +import org.apache.hadoop.ozone.container.common.statemachine.DatanodeConfiguration; +import org.apache.hadoop.ozone.container.common.transport.server.ratis.XceiverServerRatis; +import org.apache.hadoop.ozone.container.keyvalue.statemachine.background.BlockDeletingTask; +import org.apache.hadoop.ozone.container.ozoneimpl.OzoneContainer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; +import java.util.stream.Collectors; + +/** + * A per-datanode container block deleting service takes in charge + * of deleting staled ozone blocks. + */ +public class BlockDeletingService extends BackgroundService { + + private static final Logger LOG = + LoggerFactory.getLogger(BlockDeletingService.class); + + private final OzoneContainer ozoneContainer; + private final ContainerDeletionChoosingPolicy containerDeletionPolicy; + private final ConfigurationSource conf; + + private final int blockLimitPerInterval; + + private final BlockDeletingServiceMetrics metrics; + + // Task priority is useful when a to-delete block has weight. + private static final int TASK_PRIORITY_DEFAULT = 1; + + public BlockDeletingService(OzoneContainer ozoneContainer, + long serviceInterval, long serviceTimeout, + TimeUnit timeUnit, int workerSize, + ConfigurationSource conf) { + super("BlockDeletingService", serviceInterval, timeUnit, + workerSize, serviceTimeout); + this.ozoneContainer = ozoneContainer; + try { + containerDeletionPolicy = conf.getClass( + ScmConfigKeys.OZONE_SCM_KEY_VALUE_CONTAINER_DELETION_CHOOSING_POLICY, + TopNOrderedContainerDeletionChoosingPolicy.class, + ContainerDeletionChoosingPolicy.class).newInstance(); + } catch (Exception e) { + throw new RuntimeException(e); + } + this.conf = conf; + DatanodeConfiguration dnConf = conf.getObject(DatanodeConfiguration.class); + this.blockLimitPerInterval = dnConf.getBlockDeletionLimit(); + metrics = BlockDeletingServiceMetrics.create(); + } + + /** + * Pair of container data and the number of blocks to delete. + */ + public static class ContainerBlockInfo { + private final ContainerData containerData; + private final Long numBlocksToDelete; + + public ContainerBlockInfo(ContainerData containerData, Long blocks) { + this.containerData = containerData; + this.numBlocksToDelete = blocks; + } + + public ContainerData getContainerData() { + return containerData; + } + + public Long getBlocks() { + return numBlocksToDelete; + } + + } + + @Override + public BackgroundTaskQueue getTasks() { + BackgroundTaskQueue queue = new BackgroundTaskQueue(); + + try { + // We at most list a number of containers a time, + // in case there are too many containers and start too many workers. + // We must ensure there is no empty container in this result. + // The chosen result depends on what container deletion policy is + // configured. + List<ContainerBlockInfo> containers = + chooseContainerForBlockDeletion(blockLimitPerInterval, + containerDeletionPolicy); + + BackgroundTask + containerBlockInfos = null; + long totalBlocks = 0; + for (ContainerBlockInfo containerBlockInfo : containers) { + BlockDeletingTaskBuilder builder = + new BlockDeletingTaskBuilder(); + builder.setBlockDeletingService(this) + .setContainerBlockInfo(containerBlockInfo) + .setPriority(TASK_PRIORITY_DEFAULT); + containerBlockInfos = builder.build(); + queue.add(containerBlockInfos); + totalBlocks += containerBlockInfo.getBlocks(); Review Comment: the deleted blocks count is containerBlockInfo.numBlocksToDelete. ########## hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/impl/BlockDeletingService.java: ########## @@ -0,0 +1,290 @@ +/** + * 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.ozone.container.common.impl; + +import org.apache.hadoop.hdds.conf.ConfigurationSource; +import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos; +import org.apache.hadoop.hdds.scm.ScmConfigKeys; +import org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException; +import org.apache.hadoop.hdds.scm.pipeline.PipelineID; +import org.apache.hadoop.hdds.utils.BackgroundService; +import org.apache.hadoop.hdds.utils.BackgroundTask; +import org.apache.hadoop.hdds.utils.BackgroundTaskQueue; +import org.apache.hadoop.ozone.container.common.helpers.BlockDeletingServiceMetrics; +import org.apache.hadoop.ozone.container.common.helpers.ContainerUtils; +import org.apache.hadoop.ozone.container.common.interfaces.ContainerDeletionChoosingPolicy; +import org.apache.hadoop.ozone.container.common.statemachine.DatanodeConfiguration; +import org.apache.hadoop.ozone.container.common.transport.server.ratis.XceiverServerRatis; +import org.apache.hadoop.ozone.container.keyvalue.statemachine.background.BlockDeletingTask; +import org.apache.hadoop.ozone.container.ozoneimpl.OzoneContainer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; +import java.util.stream.Collectors; + +/** + * A per-datanode container block deleting service takes in charge + * of deleting staled ozone blocks. + */ +public class BlockDeletingService extends BackgroundService { + + private static final Logger LOG = + LoggerFactory.getLogger(BlockDeletingService.class); + + private final OzoneContainer ozoneContainer; + private final ContainerDeletionChoosingPolicy containerDeletionPolicy; + private final ConfigurationSource conf; + + private final int blockLimitPerInterval; + + private final BlockDeletingServiceMetrics metrics; + + // Task priority is useful when a to-delete block has weight. + private static final int TASK_PRIORITY_DEFAULT = 1; + + public BlockDeletingService(OzoneContainer ozoneContainer, + long serviceInterval, long serviceTimeout, + TimeUnit timeUnit, int workerSize, + ConfigurationSource conf) { + super("BlockDeletingService", serviceInterval, timeUnit, + workerSize, serviceTimeout); + this.ozoneContainer = ozoneContainer; + try { + containerDeletionPolicy = conf.getClass( + ScmConfigKeys.OZONE_SCM_KEY_VALUE_CONTAINER_DELETION_CHOOSING_POLICY, + TopNOrderedContainerDeletionChoosingPolicy.class, + ContainerDeletionChoosingPolicy.class).newInstance(); + } catch (Exception e) { + throw new RuntimeException(e); + } + this.conf = conf; + DatanodeConfiguration dnConf = conf.getObject(DatanodeConfiguration.class); + this.blockLimitPerInterval = dnConf.getBlockDeletionLimit(); + metrics = BlockDeletingServiceMetrics.create(); + } + + /** + * Pair of container data and the number of blocks to delete. + */ + public static class ContainerBlockInfo { + private final ContainerData containerData; + private final Long numBlocksToDelete; + + public ContainerBlockInfo(ContainerData containerData, Long blocks) { + this.containerData = containerData; + this.numBlocksToDelete = blocks; + } + + public ContainerData getContainerData() { + return containerData; + } + + public Long getBlocks() { + return numBlocksToDelete; + } + + } + + @Override + public BackgroundTaskQueue getTasks() { + BackgroundTaskQueue queue = new BackgroundTaskQueue(); + + try { + // We at most list a number of containers a time, + // in case there are too many containers and start too many workers. + // We must ensure there is no empty container in this result. + // The chosen result depends on what container deletion policy is + // configured. + List<ContainerBlockInfo> containers = + chooseContainerForBlockDeletion(blockLimitPerInterval, + containerDeletionPolicy); + + BackgroundTask + containerBlockInfos = null; + long totalBlocks = 0; + for (ContainerBlockInfo containerBlockInfo : containers) { + BlockDeletingTaskBuilder builder = + new BlockDeletingTaskBuilder(); + builder.setBlockDeletingService(this) + .setContainerBlockInfo(containerBlockInfo) + .setPriority(TASK_PRIORITY_DEFAULT); + containerBlockInfos = builder.build(); + queue.add(containerBlockInfos); + totalBlocks += containerBlockInfo.getBlocks(); Review Comment: the deleted blocks count is containerBlockInfo.numBlocksToDelete(). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
