Search in sources :

Example 1 with ContainerAction

use of org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerAction in project ozone by apache.

the class HddsDispatcher method sendCloseContainerActionIfNeeded.

/**
 * If the container usage reaches the close threshold or the container is
 * marked unhealthy we send Close ContainerAction to SCM.
 * @param container current state of container
 */
private void sendCloseContainerActionIfNeeded(Container container) {
    // We have to find a more efficient way to close a container.
    boolean isSpaceFull = isContainerFull(container);
    boolean shouldClose = isSpaceFull || isContainerUnhealthy(container);
    if (shouldClose) {
        ContainerData containerData = container.getContainerData();
        ContainerAction.Reason reason = isSpaceFull ? ContainerAction.Reason.CONTAINER_FULL : ContainerAction.Reason.CONTAINER_UNHEALTHY;
        ContainerAction action = ContainerAction.newBuilder().setContainerID(containerData.getContainerID()).setAction(ContainerAction.Action.CLOSE).setReason(reason).build();
        context.addContainerActionIfAbsent(action);
    }
}
Also used : ContainerAction(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerAction)

Example 2 with ContainerAction

use of org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerAction in project ozone by apache.

the class StateContext method getPendingContainerAction.

/**
 * Returns pending ContainerActions from the ContainerAction queue with a
 * max limit on list size, or empty list if the queue is empty.
 *
 * @return {@literal List<ContainerAction>}
 */
public List<ContainerAction> getPendingContainerAction(InetSocketAddress endpoint, int maxLimit) {
    List<ContainerAction> containerActionList = new ArrayList<>();
    synchronized (containerActions) {
        if (!containerActions.isEmpty() && CollectionUtils.isNotEmpty(containerActions.get(endpoint))) {
            Queue<ContainerAction> actions = containerActions.get(endpoint);
            int size = actions.size();
            int limit = size > maxLimit ? maxLimit : size;
            for (int count = 0; count < limit; count++) {
                // we need to remove the action from the containerAction queue
                // as well
                ContainerAction action = actions.poll();
                Preconditions.checkNotNull(action);
                containerActionList.add(action);
            }
        }
        return containerActionList;
    }
}
Also used : ContainerAction(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerAction) ArrayList(java.util.ArrayList)

Example 3 with ContainerAction

use of org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerAction in project ozone by apache.

the class TestStateContext method testActionAPIs.

@Test
public void testActionAPIs() {
    OzoneConfiguration conf = new OzoneConfiguration();
    DatanodeStateMachine datanodeStateMachineMock = mock(DatanodeStateMachine.class);
    StateContext stateContext = new StateContext(conf, DatanodeStates.getInitState(), datanodeStateMachineMock);
    InetSocketAddress scm1 = new InetSocketAddress("scm1", 9001);
    InetSocketAddress scm2 = new InetSocketAddress("scm2", 9001);
    // Try to get containerActions for endpoint which is not yet added.
    List<ContainerAction> containerActions = stateContext.getPendingContainerAction(scm1, 10);
    assertTrue(containerActions.isEmpty());
    // Try to get pipelineActions for endpoint which is not yet added.
    List<PipelineAction> pipelineActions = stateContext.getPendingPipelineAction(scm1, 10);
    assertTrue(pipelineActions.isEmpty());
    // Add 2 scm endpoints.
    stateContext.addEndpoint(scm1);
    stateContext.addEndpoint(scm2);
    final ClosePipelineInfo closePipelineInfo = ClosePipelineInfo.newBuilder().setPipelineID(PipelineID.randomId().getProtobuf()).setReason(ClosePipelineInfo.Reason.PIPELINE_FAILED).setDetailedReason("Test").build();
    final PipelineAction pipelineAction = PipelineAction.newBuilder().setClosePipeline(closePipelineInfo).setAction(PipelineAction.Action.CLOSE).build();
    // Add PipelineAction. Should be added to all endpoints.
    stateContext.addPipelineActionIfAbsent(pipelineAction);
    pipelineActions = stateContext.getPendingPipelineAction(scm2, 10);
    assertEquals(1, pipelineActions.size());
    // The pipeline action is dequeued from scm2 now, but still in scm1
    // The same pipeline action will not be added if it already exists
    stateContext.addPipelineActionIfAbsent(pipelineAction);
    pipelineActions = stateContext.getPendingPipelineAction(scm1, 10);
    assertEquals(1, pipelineActions.size());
    // The pipeline action should have been be added back to the scm2
    pipelineActions = stateContext.getPendingPipelineAction(scm2, 10);
    assertEquals(1, pipelineActions.size());
    // Add ContainerAction. Should be added to all endpoints.
    stateContext.addContainerAction(ContainerAction.newBuilder().setAction(CLOSE).setContainerID(100L).build());
    containerActions = stateContext.getPendingContainerAction(scm2, 10);
    assertEquals(1, containerActions.size());
}
Also used : ClosePipelineInfo(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ClosePipelineInfo) ContainerAction(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerAction) InetSocketAddress(java.net.InetSocketAddress) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) PipelineAction(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.PipelineAction) Test(org.junit.Test)

Example 4 with ContainerAction

use of org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerAction in project ozone by apache.

the class HeartbeatEndpointTask method addContainerActions.

/**
 * Adds all the pending ContainerActions to the heartbeat.
 *
 * @param requestBuilder builder to which the report has to be added.
 */
private void addContainerActions(SCMHeartbeatRequestProto.Builder requestBuilder) {
    List<ContainerAction> actions = context.getPendingContainerAction(rpcEndpoint.getAddress(), maxContainerActionsPerHB);
    if (!actions.isEmpty()) {
        ContainerActionsProto cap = ContainerActionsProto.newBuilder().addAllContainerActions(actions).build();
        requestBuilder.setContainerActions(cap);
    }
}
Also used : ContainerAction(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerAction) ContainerActionsProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerActionsProto)

Example 5 with ContainerAction

use of org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerAction in project ozone by apache.

the class TestContainerActionsHandler method testCloseContainerAction.

@Test
public void testCloseContainerAction() {
    EventQueue queue = new EventQueue();
    ContainerActionsHandler actionsHandler = new ContainerActionsHandler();
    CloseContainerEventHandler closeContainerEventHandler = Mockito.mock(CloseContainerEventHandler.class);
    queue.addHandler(SCMEvents.CLOSE_CONTAINER, closeContainerEventHandler);
    queue.addHandler(SCMEvents.CONTAINER_ACTIONS, actionsHandler);
    ContainerAction action = ContainerAction.newBuilder().setContainerID(1L).setAction(ContainerAction.Action.CLOSE).setReason(ContainerAction.Reason.CONTAINER_FULL).build();
    ContainerActionsProto cap = ContainerActionsProto.newBuilder().addContainerActions(action).build();
    ContainerActionsFromDatanode containerActions = new ContainerActionsFromDatanode(MockDatanodeDetails.randomDatanodeDetails(), cap);
    queue.fireEvent(SCMEvents.CONTAINER_ACTIONS, containerActions);
    queue.processAll(1000L);
    verify(closeContainerEventHandler, times(1)).onMessage(ContainerID.valueOf(1L), queue);
}
Also used : ContainerAction(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerAction) ContainerActionsFromDatanode(org.apache.hadoop.hdds.scm.server.SCMDatanodeHeartbeatDispatcher.ContainerActionsFromDatanode) ContainerActionsProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerActionsProto) EventQueue(org.apache.hadoop.hdds.server.events.EventQueue) Test(org.junit.Test)

Aggregations

ContainerAction (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerAction)5 ContainerActionsProto (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerActionsProto)2 Test (org.junit.Test)2 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)1 ClosePipelineInfo (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ClosePipelineInfo)1 PipelineAction (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.PipelineAction)1 ContainerActionsFromDatanode (org.apache.hadoop.hdds.scm.server.SCMDatanodeHeartbeatDispatcher.ContainerActionsFromDatanode)1 EventQueue (org.apache.hadoop.hdds.server.events.EventQueue)1