Search in sources :

Example 1 with DeleteContainerCommand

use of org.apache.hadoop.ozone.protocol.commands.DeleteContainerCommand in project ozone by apache.

the class TestDeleteContainerHandler method testDeleteContainerRequestHandlerOnOpenContainer.

@Test
public void testDeleteContainerRequestHandlerOnOpenContainer() throws Exception {
    // the easiest way to create an open container is creating a key
    String keyName = UUID.randomUUID().toString();
    // create key
    createKey(keyName);
    // get containerID of the key
    ContainerID containerId = getContainerID(keyName);
    HddsDatanodeService hddsDatanodeService = cluster.getHddsDatanodes().get(0);
    DatanodeDetails datanodeDetails = hddsDatanodeService.getDatanodeDetails();
    NodeManager nodeManager = cluster.getStorageContainerManager().getScmNodeManager();
    // Send delete container command with force flag set to false.
    SCMCommand<?> command = new DeleteContainerCommand(containerId.getId(), false);
    command.setTerm(cluster.getStorageContainerManager().getScmContext().getTermOfLeader());
    nodeManager.addDatanodeCommand(datanodeDetails.getUuid(), command);
    // Here it should not delete it, and the container should exist in the
    // containerset
    int count = 1;
    // is issued, giving some time for it to process.
    while (!isContainerDeleted(hddsDatanodeService, containerId.getId())) {
        Thread.sleep(1000);
        count++;
        if (count == 5) {
            break;
        }
    }
    Assert.assertFalse(isContainerDeleted(hddsDatanodeService, containerId.getId()));
    // Now delete container with force flag set to true. now it should delete
    // container
    command = new DeleteContainerCommand(containerId.getId(), true);
    command.setTerm(cluster.getStorageContainerManager().getScmContext().getTermOfLeader());
    nodeManager.addDatanodeCommand(datanodeDetails.getUuid(), command);
    GenericTestUtils.waitFor(() -> isContainerDeleted(hddsDatanodeService, containerId.getId()), 500, 5 * 1000);
    Assert.assertTrue(isContainerDeleted(hddsDatanodeService, containerId.getId()));
}
Also used : NodeManager(org.apache.hadoop.hdds.scm.node.NodeManager) ContainerID(org.apache.hadoop.hdds.scm.container.ContainerID) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) HddsDatanodeService(org.apache.hadoop.ozone.HddsDatanodeService) DeleteContainerCommand(org.apache.hadoop.ozone.protocol.commands.DeleteContainerCommand) Test(org.junit.Test)

Example 2 with DeleteContainerCommand

use of org.apache.hadoop.ozone.protocol.commands.DeleteContainerCommand in project ozone by apache.

the class HeartbeatEndpointTask method processResponse.

/**
 * Add this command to command processing Queue.
 *
 * @param response - SCMHeartbeat response.
 */
private void processResponse(SCMHeartbeatResponseProto response, final DatanodeDetailsProto datanodeDetails) {
    Preconditions.checkState(response.getDatanodeUUID().equalsIgnoreCase(datanodeDetails.getUuid()), "Unexpected datanode ID in the response.");
    // Verify the response is indeed for this datanode.
    for (SCMCommandProto commandResponseProto : response.getCommandsList()) {
        switch(commandResponseProto.getCommandType()) {
            case reregisterCommand:
                if (rpcEndpoint.getState() == EndPointStates.HEARTBEAT) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Received SCM notification to register." + " Interrupt HEARTBEAT and transit to REGISTER state.");
                    }
                    rpcEndpoint.setState(EndPointStates.REGISTER);
                } else {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Illegal state {} found, expecting {}.", rpcEndpoint.getState().name(), EndPointStates.HEARTBEAT);
                    }
                }
                break;
            case deleteBlocksCommand:
                DeleteBlocksCommand deleteBlocksCommand = DeleteBlocksCommand.getFromProtobuf(commandResponseProto.getDeleteBlocksCommandProto());
                if (commandResponseProto.hasTerm()) {
                    deleteBlocksCommand.setTerm(commandResponseProto.getTerm());
                }
                if (!deleteBlocksCommand.blocksTobeDeleted().isEmpty()) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug(DeletedContainerBlocksSummary.getFrom(deleteBlocksCommand.blocksTobeDeleted()).toString());
                    }
                    this.context.addCommand(deleteBlocksCommand);
                }
                break;
            case closeContainerCommand:
                CloseContainerCommand closeContainer = CloseContainerCommand.getFromProtobuf(commandResponseProto.getCloseContainerCommandProto());
                if (commandResponseProto.hasTerm()) {
                    closeContainer.setTerm(commandResponseProto.getTerm());
                }
                if (commandResponseProto.hasEncodedToken()) {
                    closeContainer.setEncodedToken(commandResponseProto.getEncodedToken());
                }
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Received SCM container close request for container {}", closeContainer.getContainerID());
                }
                this.context.addCommand(closeContainer);
                break;
            case replicateContainerCommand:
                ReplicateContainerCommand replicateContainerCommand = ReplicateContainerCommand.getFromProtobuf(commandResponseProto.getReplicateContainerCommandProto());
                if (commandResponseProto.hasTerm()) {
                    replicateContainerCommand.setTerm(commandResponseProto.getTerm());
                }
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Received SCM container replicate request for container {}", replicateContainerCommand.getContainerID());
                }
                this.context.addCommand(replicateContainerCommand);
                break;
            case deleteContainerCommand:
                DeleteContainerCommand deleteContainerCommand = DeleteContainerCommand.getFromProtobuf(commandResponseProto.getDeleteContainerCommandProto());
                if (commandResponseProto.hasTerm()) {
                    deleteContainerCommand.setTerm(commandResponseProto.getTerm());
                }
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Received SCM delete container request for container {}", deleteContainerCommand.getContainerID());
                }
                this.context.addCommand(deleteContainerCommand);
                break;
            case createPipelineCommand:
                CreatePipelineCommand createPipelineCommand = CreatePipelineCommand.getFromProtobuf(commandResponseProto.getCreatePipelineCommandProto());
                if (commandResponseProto.hasTerm()) {
                    createPipelineCommand.setTerm(commandResponseProto.getTerm());
                }
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Received SCM create pipeline request {}", createPipelineCommand.getPipelineID());
                }
                this.context.addCommand(createPipelineCommand);
                break;
            case closePipelineCommand:
                ClosePipelineCommand closePipelineCommand = ClosePipelineCommand.getFromProtobuf(commandResponseProto.getClosePipelineCommandProto());
                if (commandResponseProto.hasTerm()) {
                    closePipelineCommand.setTerm(commandResponseProto.getTerm());
                }
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Received SCM close pipeline request {}", closePipelineCommand.getPipelineID());
                }
                this.context.addCommand(closePipelineCommand);
                break;
            case setNodeOperationalStateCommand:
                SetNodeOperationalStateCommand setNodeOperationalStateCommand = SetNodeOperationalStateCommand.getFromProtobuf(commandResponseProto.getSetNodeOperationalStateCommandProto());
                if (commandResponseProto.hasTerm()) {
                    setNodeOperationalStateCommand.setTerm(commandResponseProto.getTerm());
                }
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Received SCM set operational state command. State: {} " + "Expiry: {}", setNodeOperationalStateCommand.getOpState(), setNodeOperationalStateCommand.getStateExpiryEpochSeconds());
                }
                this.context.addCommand(setNodeOperationalStateCommand);
                break;
            case finalizeNewLayoutVersionCommand:
                FinalizeNewLayoutVersionCommand finalizeNewLayoutVersionCommand = FinalizeNewLayoutVersionCommand.getFromProtobuf(commandResponseProto.getFinalizeNewLayoutVersionCommandProto());
                if (commandResponseProto.hasTerm()) {
                    finalizeNewLayoutVersionCommand.setTerm(commandResponseProto.getTerm());
                }
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Received SCM finalize command {}", finalizeNewLayoutVersionCommand.getId());
                }
                this.context.addCommand(finalizeNewLayoutVersionCommand);
                break;
            case refreshVolumeUsageInfo:
                RefreshVolumeUsageCommand refreshVolumeUsageCommand = RefreshVolumeUsageCommand.getFromProtobuf(commandResponseProto.getRefreshVolumeUsageCommandProto());
                if (commandResponseProto.hasTerm()) {
                    refreshVolumeUsageCommand.setTerm(commandResponseProto.getTerm());
                }
                this.context.addCommand(refreshVolumeUsageCommand);
                break;
            default:
                throw new IllegalArgumentException("Unknown response : " + commandResponseProto.getCommandType().name());
        }
    }
}
Also used : RefreshVolumeUsageCommand(org.apache.hadoop.ozone.protocol.commands.RefreshVolumeUsageCommand) SCMCommandProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMCommandProto) ReplicateContainerCommand(org.apache.hadoop.ozone.protocol.commands.ReplicateContainerCommand) ClosePipelineCommand(org.apache.hadoop.ozone.protocol.commands.ClosePipelineCommand) CloseContainerCommand(org.apache.hadoop.ozone.protocol.commands.CloseContainerCommand) SetNodeOperationalStateCommand(org.apache.hadoop.ozone.protocol.commands.SetNodeOperationalStateCommand) DeleteBlocksCommand(org.apache.hadoop.ozone.protocol.commands.DeleteBlocksCommand) CreatePipelineCommand(org.apache.hadoop.ozone.protocol.commands.CreatePipelineCommand) FinalizeNewLayoutVersionCommand(org.apache.hadoop.ozone.protocol.commands.FinalizeNewLayoutVersionCommand) DeleteContainerCommand(org.apache.hadoop.ozone.protocol.commands.DeleteContainerCommand)

Example 3 with DeleteContainerCommand

use of org.apache.hadoop.ozone.protocol.commands.DeleteContainerCommand in project ozone by apache.

the class DeleteContainerCommandHandler method handle.

@Override
public void handle(final SCMCommand command, final OzoneContainer ozoneContainer, final StateContext context, final SCMConnectionManager connectionManager) {
    final DeleteContainerCommand deleteContainerCommand = (DeleteContainerCommand) command;
    final ContainerController controller = ozoneContainer.getController();
    executor.execute(() -> {
        final long startTime = Time.monotonicNow();
        invocationCount.incrementAndGet();
        try {
            controller.deleteContainer(deleteContainerCommand.getContainerID(), deleteContainerCommand.isForce());
        } catch (IOException e) {
            LOG.error("Exception occurred while deleting the container.", e);
        } finally {
            totalTime.getAndAdd(Time.monotonicNow() - startTime);
        }
    });
}
Also used : ContainerController(org.apache.hadoop.ozone.container.ozoneimpl.ContainerController) IOException(java.io.IOException) DeleteContainerCommand(org.apache.hadoop.ozone.protocol.commands.DeleteContainerCommand)

Example 4 with DeleteContainerCommand

use of org.apache.hadoop.ozone.protocol.commands.DeleteContainerCommand in project ozone by apache.

the class TestDeleteContainerHandler method testDeleteContainerRequestHandlerOnClosedContainer.

@Test(timeout = 60000)
public void testDeleteContainerRequestHandlerOnClosedContainer() throws Exception {
    // the easiest way to create an open container is creating a key
    String keyName = UUID.randomUUID().toString();
    // create key
    createKey(keyName);
    // get containerID of the key
    ContainerID containerId = getContainerID(keyName);
    ContainerInfo container = cluster.getStorageContainerManager().getContainerManager().getContainer(containerId);
    Pipeline pipeline = cluster.getStorageContainerManager().getPipelineManager().getPipeline(container.getPipelineID());
    // We need to close the container because delete container only happens
    // on closed containers with force flag set to false.
    HddsDatanodeService hddsDatanodeService = cluster.getHddsDatanodes().get(0);
    Assert.assertFalse(isContainerClosed(hddsDatanodeService, containerId.getId()));
    DatanodeDetails datanodeDetails = hddsDatanodeService.getDatanodeDetails();
    NodeManager nodeManager = cluster.getStorageContainerManager().getScmNodeManager();
    // send the order to close the container
    SCMCommand<?> command = new CloseContainerCommand(containerId.getId(), pipeline.getId());
    command.setTerm(cluster.getStorageContainerManager().getScmContext().getTermOfLeader());
    nodeManager.addDatanodeCommand(datanodeDetails.getUuid(), command);
    GenericTestUtils.waitFor(() -> isContainerClosed(hddsDatanodeService, containerId.getId()), 500, 5 * 1000);
    // double check if it's really closed (waitFor also throws an exception)
    Assert.assertTrue(isContainerClosed(hddsDatanodeService, containerId.getId()));
    // Check container exists before sending delete container command
    Assert.assertFalse(isContainerDeleted(hddsDatanodeService, containerId.getId()));
    // send delete container to the datanode
    command = new DeleteContainerCommand(containerId.getId(), false);
    command.setTerm(cluster.getStorageContainerManager().getScmContext().getTermOfLeader());
    nodeManager.addDatanodeCommand(datanodeDetails.getUuid(), command);
    GenericTestUtils.waitFor(() -> isContainerDeleted(hddsDatanodeService, containerId.getId()), 500, 5 * 1000);
    Assert.assertTrue(isContainerDeleted(hddsDatanodeService, containerId.getId()));
}
Also used : NodeManager(org.apache.hadoop.hdds.scm.node.NodeManager) ContainerID(org.apache.hadoop.hdds.scm.container.ContainerID) CloseContainerCommand(org.apache.hadoop.ozone.protocol.commands.CloseContainerCommand) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) ContainerInfo(org.apache.hadoop.hdds.scm.container.ContainerInfo) HddsDatanodeService(org.apache.hadoop.ozone.HddsDatanodeService) DeleteContainerCommand(org.apache.hadoop.ozone.protocol.commands.DeleteContainerCommand) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline) Test(org.junit.Test)

Example 5 with DeleteContainerCommand

use of org.apache.hadoop.ozone.protocol.commands.DeleteContainerCommand in project ozone by apache.

the class ReplicationManager method sendDeleteCommand.

/**
 * Sends delete container command for the given container to the given
 * datanode.
 *
 * @param container Container to be deleted
 * @param datanode The datanode on which the replica should be deleted
 * @param force Should be set to true to delete an OPEN replica
 */
private void sendDeleteCommand(final ContainerInfo container, final DatanodeDetails datanode, final boolean force) {
    LOG.info("Sending delete container command for container {}" + " to datanode {}", container.containerID(), datanode);
    final ContainerID id = container.containerID();
    final DeleteContainerCommand deleteCommand = new DeleteContainerCommand(id.getId(), force);
    inflightDeletion.computeIfAbsent(id, k -> new ArrayList<>());
    sendAndTrackDatanodeCommand(datanode, deleteCommand, action -> inflightDeletion.get(id).add(action));
    metrics.incrNumDeletionCmdsSent();
    metrics.incrNumDeletionBytesTotal(container.getUsedBytes());
}
Also used : DeleteContainerCommand(org.apache.hadoop.ozone.protocol.commands.DeleteContainerCommand)

Aggregations

DeleteContainerCommand (org.apache.hadoop.ozone.protocol.commands.DeleteContainerCommand)5 DatanodeDetails (org.apache.hadoop.hdds.protocol.DatanodeDetails)2 ContainerID (org.apache.hadoop.hdds.scm.container.ContainerID)2 NodeManager (org.apache.hadoop.hdds.scm.node.NodeManager)2 HddsDatanodeService (org.apache.hadoop.ozone.HddsDatanodeService)2 CloseContainerCommand (org.apache.hadoop.ozone.protocol.commands.CloseContainerCommand)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 SCMCommandProto (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMCommandProto)1 ContainerInfo (org.apache.hadoop.hdds.scm.container.ContainerInfo)1 Pipeline (org.apache.hadoop.hdds.scm.pipeline.Pipeline)1 ContainerController (org.apache.hadoop.ozone.container.ozoneimpl.ContainerController)1 ClosePipelineCommand (org.apache.hadoop.ozone.protocol.commands.ClosePipelineCommand)1 CreatePipelineCommand (org.apache.hadoop.ozone.protocol.commands.CreatePipelineCommand)1 DeleteBlocksCommand (org.apache.hadoop.ozone.protocol.commands.DeleteBlocksCommand)1 FinalizeNewLayoutVersionCommand (org.apache.hadoop.ozone.protocol.commands.FinalizeNewLayoutVersionCommand)1 RefreshVolumeUsageCommand (org.apache.hadoop.ozone.protocol.commands.RefreshVolumeUsageCommand)1 ReplicateContainerCommand (org.apache.hadoop.ozone.protocol.commands.ReplicateContainerCommand)1 SetNodeOperationalStateCommand (org.apache.hadoop.ozone.protocol.commands.SetNodeOperationalStateCommand)1