Search in sources :

Example 71 with BlockID

use of org.apache.hadoop.hdds.client.BlockID in project ozone by apache.

the class TestFailureHandlingByClient method testContainerExclusionWithClosedContainerException.

@Test
public void testContainerExclusionWithClosedContainerException() throws Exception {
    startCluster();
    String keyName = UUID.randomUUID().toString();
    OzoneOutputStream key = createKey(keyName, ReplicationType.RATIS, blockSize);
    String data = ContainerTestHelper.getFixedLengthString(keyString, chunkSize);
    // get the name of a valid container
    Assert.assertTrue(key.getOutputStream() instanceof KeyOutputStream);
    KeyOutputStream keyOutputStream = (KeyOutputStream) key.getOutputStream();
    List<BlockOutputStreamEntry> streamEntryList = keyOutputStream.getStreamEntries();
    // Assert that 1 block will be preallocated
    Assert.assertEquals(1, streamEntryList.size());
    key.write(data.getBytes(UTF_8));
    key.flush();
    long containerId = streamEntryList.get(0).getBlockID().getContainerID();
    BlockID blockId = streamEntryList.get(0).getBlockID();
    List<Long> containerIdList = new ArrayList<>();
    containerIdList.add(containerId);
    // below check will assert if the container does not get closed
    TestHelper.waitForContainerClose(cluster, containerIdList.toArray(new Long[0]));
    // This write will hit ClosedContainerException and this container should
    // will be added in the excludelist
    key.write(data.getBytes(UTF_8));
    key.flush();
    Assert.assertTrue(keyOutputStream.getExcludeList().getContainerIds().contains(ContainerID.valueOf(containerId)));
    Assert.assertTrue(keyOutputStream.getExcludeList().getDatanodes().isEmpty());
    Assert.assertTrue(keyOutputStream.getExcludeList().getPipelineIds().isEmpty());
    // The close will just write to the buffer
    key.close();
    OmKeyArgs keyArgs = new OmKeyArgs.Builder().setVolumeName(volumeName).setBucketName(bucketName).setReplicationConfig(RatisReplicationConfig.getInstance(THREE)).setKeyName(keyName).setRefreshPipeline(true).build();
    OmKeyInfo keyInfo = cluster.getOzoneManager().lookupKey(keyArgs);
    // Make sure a new block is written
    Assert.assertNotEquals(keyInfo.getLatestVersionLocations().getBlocksLatestVersionOnly().get(0).getBlockID(), blockId);
    Assert.assertEquals(2 * data.getBytes(UTF_8).length, keyInfo.getDataSize());
    validateData(keyName, data.concat(data).getBytes(UTF_8));
}
Also used : ArrayList(java.util.ArrayList) OzoneOutputStream(org.apache.hadoop.ozone.client.io.OzoneOutputStream) OmKeyArgs(org.apache.hadoop.ozone.om.helpers.OmKeyArgs) BlockOutputStreamEntry(org.apache.hadoop.ozone.client.io.BlockOutputStreamEntry) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) BlockID(org.apache.hadoop.hdds.client.BlockID) KeyOutputStream(org.apache.hadoop.ozone.client.io.KeyOutputStream) Test(org.junit.jupiter.api.Test)

Example 72 with BlockID

use of org.apache.hadoop.hdds.client.BlockID in project ozone by apache.

the class TestContainerStateMachineIdempotency method testContainerStateMachineIdempotency.

@Test
public void testContainerStateMachineIdempotency() throws Exception {
    ContainerWithPipeline container = storageContainerLocationClient.allocateContainer(HddsProtos.ReplicationType.RATIS, HddsProtos.ReplicationFactor.ONE, OzoneConsts.OZONE);
    long containerID = container.getContainerInfo().getContainerID();
    Pipeline pipeline = container.getPipeline();
    XceiverClientSpi client = xceiverClientManager.acquireClient(pipeline);
    try {
        // create the container
        ContainerProtocolCalls.createContainer(client, containerID, null);
        // call create Container again
        BlockID blockID = ContainerTestHelper.getTestBlockID(containerID);
        byte[] data = RandomStringUtils.random(RandomUtils.nextInt(0, 1024)).getBytes(UTF_8);
        ContainerProtos.ContainerCommandRequestProto writeChunkRequest = ContainerTestHelper.getWriteChunkRequest(container.getPipeline(), blockID, data.length, null);
        client.sendCommand(writeChunkRequest);
        // Make the write chunk request again without requesting for overWrite
        client.sendCommand(writeChunkRequest);
        // Now, explicitly make a putKey request for the block.
        ContainerProtos.ContainerCommandRequestProto putKeyRequest = ContainerTestHelper.getPutBlockRequest(pipeline, writeChunkRequest.getWriteChunk());
        client.sendCommand(putKeyRequest).getPutBlock();
        // send the putBlock again
        client.sendCommand(putKeyRequest);
        // close container call
        ContainerProtocolCalls.closeContainer(client, containerID, null);
        ContainerProtocolCalls.closeContainer(client, containerID, null);
    } catch (IOException ioe) {
        Assert.fail("Container operation failed" + ioe);
    }
    xceiverClientManager.releaseClient(client, false);
}
Also used : ContainerProtos(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos) BlockID(org.apache.hadoop.hdds.client.BlockID) IOException(java.io.IOException) XceiverClientSpi(org.apache.hadoop.hdds.scm.XceiverClientSpi) ContainerWithPipeline(org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline) ContainerWithPipeline(org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline) Test(org.junit.Test)

Example 73 with BlockID

use of org.apache.hadoop.hdds.client.BlockID in project ozone by apache.

the class OMRequestTestUtils method addKeyLocationInfo.

/**
 * Adds one block to {@code keyInfo} with the provided size and offset.
 */
public static void addKeyLocationInfo(OmKeyInfo keyInfo, long offset, long keyLength) throws IOException {
    Pipeline pipeline = Pipeline.newBuilder().setState(Pipeline.PipelineState.OPEN).setId(PipelineID.randomId()).setReplicationConfig(keyInfo.getReplicationConfig()).setNodes(new ArrayList<>()).build();
    OmKeyLocationInfo locationInfo = new OmKeyLocationInfo.Builder().setBlockID(new BlockID(100L, 1000L)).setOffset(offset).setLength(keyLength).setPipeline(pipeline).build();
    keyInfo.appendNewBlocks(Collections.singletonList(locationInfo), false);
}
Also used : ArrayList(java.util.ArrayList) BlockID(org.apache.hadoop.hdds.client.BlockID) OmKeyLocationInfo(org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline)

Example 74 with BlockID

use of org.apache.hadoop.hdds.client.BlockID in project ozone by apache.

the class TestKeyManagerUnit method sortDatanodes.

@Test
public void sortDatanodes() throws Exception {
    // GIVEN
    String client = "anyhost";
    int pipelineCount = 3;
    int keysPerPipeline = 5;
    OmKeyInfo[] keyInfos = new OmKeyInfo[pipelineCount * keysPerPipeline];
    List<List<String>> expectedSortDatanodesInvocations = new ArrayList<>();
    Map<Pipeline, List<DatanodeDetails>> expectedSortedNodes = new HashMap<>();
    int ki = 0;
    for (int p = 0; p < pipelineCount; p++) {
        final Pipeline pipeline = MockPipeline.createPipeline(3);
        final List<String> nodes = pipeline.getNodes().stream().map(DatanodeDetails::getUuidString).collect(toList());
        expectedSortDatanodesInvocations.add(nodes);
        final List<DatanodeDetails> sortedNodes = pipeline.getNodes().stream().sorted(comparing(DatanodeDetails::getUuidString)).collect(toList());
        expectedSortedNodes.put(pipeline, sortedNodes);
        when(blockClient.sortDatanodes(nodes, client)).thenReturn(sortedNodes);
        for (int i = 1; i <= keysPerPipeline; i++) {
            OmKeyLocationInfo keyLocationInfo = new OmKeyLocationInfo.Builder().setBlockID(new BlockID(i, 1L)).setPipeline(pipeline).setOffset(0).setLength(256000).build();
            OmKeyInfo keyInfo = new OmKeyInfo.Builder().setOmKeyLocationInfos(Arrays.asList(new OmKeyLocationInfoGroup(0, emptyList()), new OmKeyLocationInfoGroup(1, singletonList(keyLocationInfo)))).build();
            keyInfos[ki++] = keyInfo;
        }
    }
    // WHEN
    keyManager.sortDatanodes(client, keyInfos);
    // verify all key info locations got updated
    for (OmKeyInfo keyInfo : keyInfos) {
        OmKeyLocationInfoGroup locations = keyInfo.getLatestVersionLocations();
        Assert.assertNotNull(locations);
        for (OmKeyLocationInfo locationInfo : locations.getLocationList()) {
            Pipeline pipeline = locationInfo.getPipeline();
            List<DatanodeDetails> expectedOrder = expectedSortedNodes.get(pipeline);
            Assert.assertEquals(expectedOrder, pipeline.getNodesInOrder());
        }
    }
    // expect one invocation per pipeline
    for (List<String> nodes : expectedSortDatanodesInvocations) {
        verify(blockClient).sortDatanodes(nodes, client);
    }
}
Also used : HashMap(java.util.HashMap) Builder(org.apache.hadoop.ozone.om.helpers.OmKeyArgs.Builder) ArrayList(java.util.ArrayList) OmKeyLocationInfo(org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo) MockPipeline(org.apache.hadoop.hdds.scm.pipeline.MockPipeline) ContainerWithPipeline(org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline) OmKeyLocationInfoGroup(org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup) MockDatanodeDetails(org.apache.hadoop.hdds.protocol.MockDatanodeDetails) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) BlockID(org.apache.hadoop.hdds.client.BlockID) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ArrayList(java.util.ArrayList) OmMultipartUploadList(org.apache.hadoop.ozone.om.helpers.OmMultipartUploadList) Collectors.toList(java.util.stream.Collectors.toList) Test(org.junit.Test)

Example 75 with BlockID

use of org.apache.hadoop.hdds.client.BlockID in project ozone by apache.

the class ScmBlockLocationTestingClient method deleteKeyBlocks.

@Override
public List<DeleteBlockGroupResult> deleteKeyBlocks(List<BlockGroup> keyBlocksInfoList) throws IOException {
    List<DeleteBlockGroupResult> results = new ArrayList<>();
    List<DeleteBlockResult> blockResultList = new ArrayList<>();
    Result result;
    for (BlockGroup keyBlocks : keyBlocksInfoList) {
        for (BlockID blockKey : keyBlocks.getBlockIDList()) {
            currentCall++;
            switch(this.failCallsFrequency) {
                case 0:
                    result = success;
                    numBlocksDeleted++;
                    break;
                case 1:
                    result = unknownFailure;
                    break;
                default:
                    if (currentCall % this.failCallsFrequency == 0) {
                        result = unknownFailure;
                    } else {
                        result = success;
                        numBlocksDeleted++;
                    }
            }
            blockResultList.add(new DeleteBlockResult(blockKey, result));
        }
        results.add(new DeleteBlockGroupResult(keyBlocks.getGroupID(), blockResultList));
    }
    return results;
}
Also used : DeleteBlockGroupResult(org.apache.hadoop.ozone.common.DeleteBlockGroupResult) ArrayList(java.util.ArrayList) BlockID(org.apache.hadoop.hdds.client.BlockID) ContainerBlockID(org.apache.hadoop.hdds.client.ContainerBlockID) DeleteBlockResult(org.apache.hadoop.hdds.scm.container.common.helpers.DeleteBlockResult) DeleteBlockResult(org.apache.hadoop.hdds.scm.container.common.helpers.DeleteBlockResult) DeleteBlockGroupResult(org.apache.hadoop.ozone.common.DeleteBlockGroupResult) Result(org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.DeleteScmBlockResult.Result) BlockGroup(org.apache.hadoop.ozone.common.BlockGroup)

Aggregations

BlockID (org.apache.hadoop.hdds.client.BlockID)126 Test (org.junit.Test)63 ArrayList (java.util.ArrayList)49 Pipeline (org.apache.hadoop.hdds.scm.pipeline.Pipeline)44 ChunkInfo (org.apache.hadoop.ozone.container.common.helpers.ChunkInfo)33 OmKeyLocationInfo (org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo)30 ContainerProtos (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos)27 IOException (java.io.IOException)24 BlockData (org.apache.hadoop.ozone.container.common.helpers.BlockData)23 OmKeyInfo (org.apache.hadoop.ozone.om.helpers.OmKeyInfo)22 DatanodeDetails (org.apache.hadoop.hdds.protocol.DatanodeDetails)19 XceiverClientSpi (org.apache.hadoop.hdds.scm.XceiverClientSpi)19 KeyValueContainer (org.apache.hadoop.ozone.container.keyvalue.KeyValueContainer)19 ContainerWithPipeline (org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline)18 StorageContainerException (org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException)18 OmKeyLocationInfoGroup (org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup)16 ChunkBuffer (org.apache.hadoop.ozone.common.ChunkBuffer)15 ContainerBlockID (org.apache.hadoop.hdds.client.ContainerBlockID)13 ContainerCommandRequestProto (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto)11 MockPipeline (org.apache.hadoop.hdds.scm.pipeline.MockPipeline)11