Search in sources :

Example 1 with ExcludeList

use of org.apache.hadoop.hdds.scm.container.common.helpers.ExcludeList in project ozone by apache.

the class TestOmBlockVersioning method testAllocateCommit.

@Test
public void testAllocateCommit() throws Exception {
    String volumeName = "volume" + RandomStringUtils.randomNumeric(5);
    String bucketName = "bucket" + RandomStringUtils.randomNumeric(5);
    String keyName = "key" + RandomStringUtils.randomNumeric(5);
    OzoneBucket bucket = TestDataUtil.createVolumeAndBucket(cluster, volumeName, bucketName);
    // Versioning isn't supported currently, but just preserving old behaviour
    bucket.setVersioning(true);
    OmKeyArgs keyArgs = new OmKeyArgs.Builder().setVolumeName(volumeName).setBucketName(bucketName).setKeyName(keyName).setDataSize(1000).setRefreshPipeline(true).setAcls(new ArrayList<>()).setReplicationConfig(StandaloneReplicationConfig.getInstance(ONE)).build();
    // 1st update, version 0
    OpenKeySession openKey = writeClient.openKey(keyArgs);
    // explicitly set the keyLocation list before committing the key.
    keyArgs.setLocationInfoList(openKey.getKeyInfo().getLatestVersionLocations().getBlocksLatestVersionOnly());
    writeClient.commitKey(keyArgs, openKey.getId());
    OmKeyInfo keyInfo = ozoneManager.lookupKey(keyArgs);
    OmKeyLocationInfoGroup highestVersion = checkVersions(keyInfo.getKeyLocationVersions());
    assertEquals(0, highestVersion.getVersion());
    assertEquals(1, highestVersion.getLocationList().size());
    // 2nd update, version 1
    openKey = writeClient.openKey(keyArgs);
    // OmKeyLocationInfo locationInfo =
    // writeClient.allocateBlock(keyArgs, openKey.getId());
    // explicitly set the keyLocation list before committing the key.
    keyArgs.setLocationInfoList(openKey.getKeyInfo().getLatestVersionLocations().getBlocksLatestVersionOnly());
    writeClient.commitKey(keyArgs, openKey.getId());
    keyInfo = ozoneManager.lookupKey(keyArgs);
    highestVersion = checkVersions(keyInfo.getKeyLocationVersions());
    assertEquals(1, highestVersion.getVersion());
    assertEquals(1, highestVersion.getLocationList().size());
    // 3rd update, version 2
    openKey = writeClient.openKey(keyArgs);
    // this block will be appended to the latest version of version 2.
    OmKeyLocationInfo locationInfo = writeClient.allocateBlock(keyArgs, openKey.getId(), new ExcludeList());
    List<OmKeyLocationInfo> locationInfoList = openKey.getKeyInfo().getLatestVersionLocations().getBlocksLatestVersionOnly();
    Assert.assertTrue(locationInfoList.size() == 1);
    locationInfoList.add(locationInfo);
    keyArgs.setLocationInfoList(locationInfoList);
    writeClient.commitKey(keyArgs, openKey.getId());
    keyInfo = ozoneManager.lookupKey(keyArgs);
    highestVersion = checkVersions(keyInfo.getKeyLocationVersions());
    assertEquals(2, highestVersion.getVersion());
    assertEquals(2, highestVersion.getLocationList().size());
}
Also used : OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) ExcludeList(org.apache.hadoop.hdds.scm.container.common.helpers.ExcludeList) OmKeyLocationInfoGroup(org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) OpenKeySession(org.apache.hadoop.ozone.om.helpers.OpenKeySession) OmKeyArgs(org.apache.hadoop.ozone.om.helpers.OmKeyArgs) OmKeyLocationInfo(org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo) Test(org.junit.Test)

Example 2 with ExcludeList

use of org.apache.hadoop.hdds.scm.container.common.helpers.ExcludeList in project ozone by apache.

the class TestKeyDeletingService method createAndDeleteKeys.

private void createAndDeleteKeys(KeyManager keyManager, int keyCount, int numBlocks) throws IOException {
    for (int x = 0; x < keyCount; x++) {
        String volumeName = String.format("volume%s", RandomStringUtils.randomAlphanumeric(5));
        String bucketName = String.format("bucket%s", RandomStringUtils.randomAlphanumeric(5));
        String keyName = String.format("key%s", RandomStringUtils.randomAlphanumeric(5));
        String volumeBytes = keyManager.getMetadataManager().getVolumeKey(volumeName);
        String bucketBytes = keyManager.getMetadataManager().getBucketKey(volumeName, bucketName);
        // cheat here, just create a volume and bucket entry so that we can
        // create the keys, we put the same data for key and value since the
        // system does not decode the object
        OMRequestTestUtils.addVolumeToOM(keyManager.getMetadataManager(), OmVolumeArgs.newBuilder().setOwnerName("o").setAdminName("a").setVolume(volumeName).build());
        OMRequestTestUtils.addBucketToOM(keyManager.getMetadataManager(), OmBucketInfo.newBuilder().setVolumeName(volumeName).setBucketName(bucketName).build());
        OmKeyArgs arg = new OmKeyArgs.Builder().setVolumeName(volumeName).setBucketName(bucketName).setKeyName(keyName).setAcls(Collections.emptyList()).setReplicationConfig(StandaloneReplicationConfig.getInstance(HddsProtos.ReplicationFactor.ONE)).setLocationInfoList(new ArrayList<>()).build();
        // Open, Commit and Delete the Keys in the Key Manager.
        OpenKeySession session = writeClient.openKey(arg);
        for (int i = 0; i < numBlocks; i++) {
            arg.addLocationInfo(writeClient.allocateBlock(arg, session.getId(), new ExcludeList()));
        }
        writeClient.commitKey(arg, session.getId());
        writeClient.deleteKey(arg);
    }
}
Also used : ExcludeList(org.apache.hadoop.hdds.scm.container.common.helpers.ExcludeList) ArrayList(java.util.ArrayList) OpenKeySession(org.apache.hadoop.ozone.om.helpers.OpenKeySession) OmKeyArgs(org.apache.hadoop.ozone.om.helpers.OmKeyArgs)

Example 3 with ExcludeList

use of org.apache.hadoop.hdds.scm.container.common.helpers.ExcludeList in project ozone by apache.

the class TestBlockManager method testMultipleBlockAllocation.

@Test(timeout = 10000)
public void testMultipleBlockAllocation() throws IOException, TimeoutException, InterruptedException {
    pipelineManager.createPipeline(replicationConfig);
    pipelineManager.createPipeline(replicationConfig);
    HddsTestUtils.openAllRatisPipelines(pipelineManager);
    AllocatedBlock allocatedBlock = blockManager.allocateBlock(DEFAULT_BLOCK_SIZE, replicationConfig, OzoneConsts.OZONE, new ExcludeList());
    // block should be allocated in different pipelines
    GenericTestUtils.waitFor(() -> {
        try {
            AllocatedBlock block = blockManager.allocateBlock(DEFAULT_BLOCK_SIZE, replicationConfig, OzoneConsts.OZONE, new ExcludeList());
            return !block.getPipeline().getId().equals(allocatedBlock.getPipeline().getId());
        } catch (IOException e) {
        }
        return false;
    }, 100, 1000);
}
Also used : ExcludeList(org.apache.hadoop.hdds.scm.container.common.helpers.ExcludeList) AllocatedBlock(org.apache.hadoop.hdds.scm.container.common.helpers.AllocatedBlock) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with ExcludeList

use of org.apache.hadoop.hdds.scm.container.common.helpers.ExcludeList in project ozone by apache.

the class TestBlockManager method testAllocateBlockFailureInSafeMode.

@Test
public void testAllocateBlockFailureInSafeMode() throws Exception {
    scm.getScmContext().updateSafeModeStatus(new SCMSafeModeManager.SafeModeStatus(true, true));
    // Test1: In safe mode expect an SCMException.
    thrown.expectMessage("SafeModePrecheck failed for " + "allocateBlock");
    blockManager.allocateBlock(DEFAULT_BLOCK_SIZE, replicationConfig, OzoneConsts.OZONE, new ExcludeList());
}
Also used : ExcludeList(org.apache.hadoop.hdds.scm.container.common.helpers.ExcludeList) SafeModeStatus(org.apache.hadoop.hdds.scm.safemode.SCMSafeModeManager.SafeModeStatus) SCMSafeModeManager(org.apache.hadoop.hdds.scm.safemode.SCMSafeModeManager) Test(org.junit.Test)

Example 5 with ExcludeList

use of org.apache.hadoop.hdds.scm.container.common.helpers.ExcludeList in project ozone by apache.

the class TestBlockManager method testAllocateBlockWithExclusion.

@Test
public void testAllocateBlockWithExclusion() throws Exception {
    try {
        while (true) {
            pipelineManager.createPipeline(replicationConfig);
        }
    } catch (IOException e) {
    }
    HddsTestUtils.openAllRatisPipelines(pipelineManager);
    ExcludeList excludeList = new ExcludeList();
    excludeList.addPipeline(pipelineManager.getPipelines(replicationConfig).get(0).getId());
    AllocatedBlock block = blockManager.allocateBlock(DEFAULT_BLOCK_SIZE, replicationConfig, OzoneConsts.OZONE, excludeList);
    Assert.assertNotNull(block);
    for (PipelineID id : excludeList.getPipelineIds()) {
        Assert.assertNotEquals(block.getPipeline().getId(), id);
    }
    for (Pipeline pipeline : pipelineManager.getPipelines(replicationConfig)) {
        excludeList.addPipeline(pipeline.getId());
    }
    block = blockManager.allocateBlock(DEFAULT_BLOCK_SIZE, replicationConfig, OzoneConsts.OZONE, excludeList);
    Assert.assertNotNull(block);
    Assert.assertTrue(excludeList.getPipelineIds().contains(block.getPipeline().getId()));
}
Also used : ExcludeList(org.apache.hadoop.hdds.scm.container.common.helpers.ExcludeList) AllocatedBlock(org.apache.hadoop.hdds.scm.container.common.helpers.AllocatedBlock) PipelineID(org.apache.hadoop.hdds.scm.pipeline.PipelineID) IOException(java.io.IOException) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline) Test(org.junit.Test)

Aggregations

ExcludeList (org.apache.hadoop.hdds.scm.container.common.helpers.ExcludeList)18 Test (org.junit.Test)13 IOException (java.io.IOException)7 AllocatedBlock (org.apache.hadoop.hdds.scm.container.common.helpers.AllocatedBlock)7 Pipeline (org.apache.hadoop.hdds.scm.pipeline.Pipeline)7 ArrayList (java.util.ArrayList)4 OmKeyLocationInfo (org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo)4 List (java.util.List)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ExecutorService (java.util.concurrent.ExecutorService)3 TimeoutException (java.util.concurrent.TimeoutException)3 OmKeyArgs (org.apache.hadoop.ozone.om.helpers.OmKeyArgs)3 KeyArgs (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyArgs)3 ExpectedException (org.junit.rules.ExpectedException)3 HddsProtos (org.apache.hadoop.hdds.protocol.proto.HddsProtos)2 PipelineID (org.apache.hadoop.hdds.scm.pipeline.PipelineID)2 OmKeyInfo (org.apache.hadoop.ozone.om.helpers.OmKeyInfo)2 OmKeyLocationInfoGroup (org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup)2 OpenKeySession (org.apache.hadoop.ozone.om.helpers.OpenKeySession)2