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);
}
}
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;
}
}
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());
}
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);
}
}
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);
}
Aggregations