Search in sources :

Example 1 with FinalizeNewLayoutVersionCommand

use of org.apache.hadoop.ozone.protocol.commands.FinalizeNewLayoutVersionCommand 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 2 with FinalizeNewLayoutVersionCommand

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

the class FinalizeNewLayoutVersionCommandHandler method handle.

/**
 * Handles a given SCM command.
 *
 * @param command           - SCM Command
 * @param ozoneContainer         - Ozone Container.
 * @param context           - Current Context.
 * @param connectionManager - The SCMs that we are talking to.
 */
@Override
public void handle(SCMCommand command, OzoneContainer ozoneContainer, StateContext context, SCMConnectionManager connectionManager) {
    LOG.info("Processing FinalizeNewLayoutVersionCommandHandler command.");
    invocationCount.incrementAndGet();
    final long startTime = Time.monotonicNow();
    DatanodeStateMachine dsm = context.getParent();
    final FinalizeNewLayoutVersionCommandProto finalizeCommand = ((FinalizeNewLayoutVersionCommand) command).getProto();
    try {
        if (finalizeCommand.getFinalizeNewLayoutVersion()) {
            // SCM is asking datanode to finalize
            if (dsm.getLayoutVersionManager().getUpgradeState() == FINALIZATION_REQUIRED) {
                // SCM will keep sending Finalize command until datanode mlv == slv
                // we need to avoid multiple invocations of finalizeUpgrade.
                LOG.info("Finalize Upgrade called!");
                dsm.finalizeUpgrade();
            }
        }
    } catch (Exception e) {
        LOG.debug("Unexpected Error: {} ", e);
    } finally {
        long endTime = Time.monotonicNow();
        totalTime += endTime - startTime;
    }
}
Also used : FinalizeNewLayoutVersionCommandProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.FinalizeNewLayoutVersionCommandProto) DatanodeStateMachine(org.apache.hadoop.ozone.container.common.statemachine.DatanodeStateMachine) FinalizeNewLayoutVersionCommand(org.apache.hadoop.ozone.protocol.commands.FinalizeNewLayoutVersionCommand)

Example 3 with FinalizeNewLayoutVersionCommand

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

the class SCMNodeManager method processLayoutVersionReport.

/**
 * Process Layout Version report.
 *
 * @param datanodeDetails
 * @param layoutVersionReport
 */
@Override
public void processLayoutVersionReport(DatanodeDetails datanodeDetails, LayoutVersionProto layoutVersionReport) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Processing Layout Version report from [datanode={}]", datanodeDetails.getHostName());
    }
    if (LOG.isTraceEnabled()) {
        LOG.trace("HB is received from [datanode={}]: <json>{}</json>", datanodeDetails.getHostName(), layoutVersionReport.toString().replaceAll("\n", "\\\\n"));
    }
    int scmSlv = scmLayoutVersionManager.getSoftwareLayoutVersion();
    int scmMlv = scmLayoutVersionManager.getMetadataLayoutVersion();
    int dnSlv = layoutVersionReport.getSoftwareLayoutVersion();
    int dnMlv = layoutVersionReport.getMetadataLayoutVersion();
    // If the data node slv is > scm slv => log error condition
    if (dnSlv > scmSlv) {
        LOG.error("Invalid data node in the cluster : {}. " + "DataNode SoftwareLayoutVersion = {}, SCM " + "SoftwareLayoutVersion = {}", datanodeDetails.getHostName(), dnSlv, scmSlv);
    }
    // any pipeline. However it can be allowed to join the cluster
    if (dnMlv < scmMlv) {
        LOG.warn("Data node {} can not be used in any pipeline in the " + "cluster. " + "DataNode MetadataLayoutVersion = {}, SCM " + "MetadataLayoutVersion = {}", datanodeDetails.getHostName(), dnMlv, scmMlv);
        FinalizeNewLayoutVersionCommand finalizeCmd = new FinalizeNewLayoutVersionCommand(true, LayoutVersionProto.newBuilder().setSoftwareLayoutVersion(dnSlv).setMetadataLayoutVersion(dnSlv).build());
        try {
            finalizeCmd.setTerm(scmContext.getTermOfLeader());
            // Send Finalize command to the data node. Its OK to
            // send Finalize command multiple times.
            scmNodeEventPublisher.fireEvent(SCMEvents.DATANODE_COMMAND, new CommandForDatanode<>(datanodeDetails.getUuid(), finalizeCmd));
        } catch (NotLeaderException ex) {
            LOG.warn("Skip sending finalize upgrade command since current SCM is" + "not leader.", ex);
        }
    }
}
Also used : NotLeaderException(org.apache.ratis.protocol.exceptions.NotLeaderException) FinalizeNewLayoutVersionCommand(org.apache.hadoop.ozone.protocol.commands.FinalizeNewLayoutVersionCommand)

Aggregations

FinalizeNewLayoutVersionCommand (org.apache.hadoop.ozone.protocol.commands.FinalizeNewLayoutVersionCommand)3 FinalizeNewLayoutVersionCommandProto (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.FinalizeNewLayoutVersionCommandProto)1 SCMCommandProto (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMCommandProto)1 DatanodeStateMachine (org.apache.hadoop.ozone.container.common.statemachine.DatanodeStateMachine)1 CloseContainerCommand (org.apache.hadoop.ozone.protocol.commands.CloseContainerCommand)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 DeleteContainerCommand (org.apache.hadoop.ozone.protocol.commands.DeleteContainerCommand)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 NotLeaderException (org.apache.ratis.protocol.exceptions.NotLeaderException)1