Search in sources :

Example 1 with ContainerKeyPrefix

use of org.apache.hadoop.ozone.recon.api.types.ContainerKeyPrefix in project ozone by apache.

the class TestReconWithOzoneManagerHA method testReconGetsSnapshotFromLeader.

@Test
public void testReconGetsSnapshotFromLeader() throws Exception {
    AtomicReference<OzoneManager> ozoneManager = new AtomicReference<>();
    // Wait for OM leader election to finish
    GenericTestUtils.waitFor(() -> {
        OzoneManager om = cluster.getOMLeader();
        ozoneManager.set(om);
        return om != null;
    }, 100, 120000);
    Assert.assertNotNull("Timed out waiting OM leader election to finish: " + "no leader or more than one leader.", ozoneManager);
    Assert.assertTrue("Should have gotten the leader!", ozoneManager.get().isLeaderReady());
    OzoneManagerServiceProviderImpl impl = (OzoneManagerServiceProviderImpl) cluster.getReconServer().getOzoneManagerServiceProvider();
    String hostname = ozoneManager.get().getHttpServer().getHttpAddress().getHostName();
    String expectedUrl = "http://" + (hostname.equals("0.0.0.0") ? "localhost" : hostname) + ":" + ozoneManager.get().getHttpServer().getHttpAddress().getPort() + OZONE_DB_CHECKPOINT_HTTP_ENDPOINT;
    String snapshotUrl = impl.getOzoneManagerSnapshotUrl();
    Assert.assertEquals("OM Snapshot should be requested from the leader.", expectedUrl, snapshotUrl);
    // Write some data
    String keyPrefix = "ratis";
    OzoneOutputStream key = objectStore.getVolume(VOL_NAME).getBucket(VOL_NAME).createKey(keyPrefix, 1024, ReplicationType.RATIS, ReplicationFactor.ONE, new HashMap<>());
    key.write(keyPrefix.getBytes(UTF_8));
    key.flush();
    key.close();
    // Sync data to Recon
    impl.syncDataFromOM();
    ReconContainerMetadataManager reconContainerMetadataManager = cluster.getReconServer().getReconContainerMetadataManager();
    TableIterator iterator = reconContainerMetadataManager.getContainerTableIterator();
    String reconKeyPrefix = null;
    while (iterator.hasNext()) {
        Table.KeyValue<ContainerKeyPrefix, Integer> keyValue = (Table.KeyValue<ContainerKeyPrefix, Integer>) iterator.next();
        reconKeyPrefix = keyValue.getKey().getKeyPrefix();
    }
    Assert.assertEquals("Container data should be synced to recon.", String.format("/%s/%s/%s", VOL_NAME, VOL_NAME, keyPrefix), reconKeyPrefix);
}
Also used : Table(org.apache.hadoop.hdds.utils.db.Table) AtomicReference(java.util.concurrent.atomic.AtomicReference) OzoneOutputStream(org.apache.hadoop.ozone.client.io.OzoneOutputStream) OzoneManagerServiceProviderImpl(org.apache.hadoop.ozone.recon.spi.impl.OzoneManagerServiceProviderImpl) TableIterator(org.apache.hadoop.hdds.utils.db.TableIterator) ReconContainerMetadataManager(org.apache.hadoop.ozone.recon.spi.ReconContainerMetadataManager) OzoneManager(org.apache.hadoop.ozone.om.OzoneManager) ContainerKeyPrefix(org.apache.hadoop.ozone.recon.api.types.ContainerKeyPrefix) Test(org.junit.Test)

Example 2 with ContainerKeyPrefix

use of org.apache.hadoop.ozone.recon.api.types.ContainerKeyPrefix in project ozone by apache.

the class TestReconContainerMetadataManagerImpl method testInitNewContainerDB.

@Test
public void testInitNewContainerDB() throws Exception {
    long containerId = System.currentTimeMillis();
    Map<ContainerKeyPrefix, Integer> prefixCounts = new HashMap<>();
    ContainerKeyPrefix ckp1 = new ContainerKeyPrefix(containerId, "V1/B1/K1", 0);
    prefixCounts.put(ckp1, 1);
    ContainerKeyPrefix ckp2 = new ContainerKeyPrefix(containerId, "V1/B1/K2", 0);
    prefixCounts.put(ckp2, 2);
    ContainerKeyPrefix ckp3 = new ContainerKeyPrefix(containerId, "V1/B2/K3", 0);
    prefixCounts.put(ckp3, 3);
    for (Map.Entry<ContainerKeyPrefix, Integer> entry : prefixCounts.entrySet()) {
        reconContainerMetadataManager.storeContainerKeyMapping(entry.getKey(), prefixCounts.get(entry.getKey()));
    }
    assertEquals(1, reconContainerMetadataManager.getCountForContainerKeyPrefix(ckp1).intValue());
    prefixCounts.clear();
    prefixCounts.put(ckp2, 12);
    prefixCounts.put(ckp3, 13);
    ContainerKeyPrefix ckp4 = new ContainerKeyPrefix(containerId, "V1/B3/K1", 0);
    prefixCounts.put(ckp4, 14);
    ContainerKeyPrefix ckp5 = new ContainerKeyPrefix(containerId, "V1/B3/K2", 0);
    prefixCounts.put(ckp5, 15);
    reconContainerMetadataManager.reinitWithNewContainerDataFromOm(prefixCounts);
    Map<ContainerKeyPrefix, Integer> keyPrefixesForContainer = reconContainerMetadataManager.getKeyPrefixesForContainer(containerId);
    assertEquals(4, keyPrefixesForContainer.size());
    assertEquals(12, keyPrefixesForContainer.get(ckp2).intValue());
    assertEquals(13, keyPrefixesForContainer.get(ckp3).intValue());
    assertEquals(14, keyPrefixesForContainer.get(ckp4).intValue());
    assertEquals(15, keyPrefixesForContainer.get(ckp5).intValue());
    assertEquals(0, reconContainerMetadataManager.getCountForContainerKeyPrefix(ckp1).intValue());
}
Also used : HashMap(java.util.HashMap) ContainerKeyPrefix(org.apache.hadoop.ozone.recon.api.types.ContainerKeyPrefix) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 3 with ContainerKeyPrefix

use of org.apache.hadoop.ozone.recon.api.types.ContainerKeyPrefix in project ozone by apache.

the class TestReconContainerMetadataManagerImpl method testStoreContainerKeyMapping.

@Test
public void testStoreContainerKeyMapping() throws Exception {
    long containerId = System.currentTimeMillis();
    Map<String, Integer> prefixCounts = new HashMap<>();
    prefixCounts.put(keyPrefix1, 1);
    prefixCounts.put(keyPrefix2, 2);
    prefixCounts.put(keyPrefix3, 3);
    for (Map.Entry<String, Integer> entry : prefixCounts.entrySet()) {
        ContainerKeyPrefix containerKeyPrefix = new ContainerKeyPrefix(containerId, entry.getKey(), 0);
        reconContainerMetadataManager.storeContainerKeyMapping(containerKeyPrefix, prefixCounts.get(entry.getKey()));
    }
    Assert.assertEquals(1, reconContainerMetadataManager.getCountForContainerKeyPrefix(new ContainerKeyPrefix(containerId, keyPrefix1, 0)).longValue());
    Assert.assertEquals(2, reconContainerMetadataManager.getCountForContainerKeyPrefix(new ContainerKeyPrefix(containerId, keyPrefix2, 0)).longValue());
    Assert.assertEquals(3, reconContainerMetadataManager.getCountForContainerKeyPrefix(new ContainerKeyPrefix(containerId, keyPrefix3, 0)).longValue());
}
Also used : HashMap(java.util.HashMap) ContainerKeyPrefix(org.apache.hadoop.ozone.recon.api.types.ContainerKeyPrefix) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with ContainerKeyPrefix

use of org.apache.hadoop.ozone.recon.api.types.ContainerKeyPrefix in project ozone by apache.

the class TestReconContainerMetadataManagerImpl method testDeleteContainerMapping.

@Test
public void testDeleteContainerMapping() throws Exception {
    long containerId = 1L;
    long nextContainerId = 2L;
    populateKeysInContainers(containerId, nextContainerId);
    Map<ContainerKeyPrefix, Integer> keyPrefixMap = reconContainerMetadataManager.getKeyPrefixesForContainer(containerId);
    assertEquals(2, keyPrefixMap.size());
    reconContainerMetadataManager.deleteContainerMapping(new ContainerKeyPrefix(containerId, keyPrefix2, 0));
    keyPrefixMap = reconContainerMetadataManager.getKeyPrefixesForContainer(containerId);
    assertEquals(1, keyPrefixMap.size());
}
Also used : ContainerKeyPrefix(org.apache.hadoop.ozone.recon.api.types.ContainerKeyPrefix) Test(org.junit.Test)

Example 5 with ContainerKeyPrefix

use of org.apache.hadoop.ozone.recon.api.types.ContainerKeyPrefix in project ozone by apache.

the class TestReconContainerMetadataManagerImpl method testGetKeyPrefixesForContainerWithKeyPrefix.

@Test
public void testGetKeyPrefixesForContainerWithKeyPrefix() throws Exception {
    long containerId = 1L;
    long nextContainerId = 2L;
    populateKeysInContainers(containerId, nextContainerId);
    ContainerKeyPrefix containerKeyPrefix2 = new ContainerKeyPrefix(containerId, keyPrefix2, 0);
    Map<ContainerKeyPrefix, Integer> keyPrefixMap = reconContainerMetadataManager.getKeyPrefixesForContainer(containerId, keyPrefix1);
    assertEquals(1, keyPrefixMap.size());
    assertEquals(2, keyPrefixMap.get(containerKeyPrefix2).longValue());
    keyPrefixMap = reconContainerMetadataManager.getKeyPrefixesForContainer(nextContainerId, keyPrefix3);
    assertEquals(0, keyPrefixMap.size());
    // test for negative cases
    keyPrefixMap = reconContainerMetadataManager.getKeyPrefixesForContainer(containerId, "V3/B1/invalid");
    assertEquals(0, keyPrefixMap.size());
    keyPrefixMap = reconContainerMetadataManager.getKeyPrefixesForContainer(containerId, keyPrefix3);
    assertEquals(0, keyPrefixMap.size());
    keyPrefixMap = reconContainerMetadataManager.getKeyPrefixesForContainer(10L, "");
    assertEquals(0, keyPrefixMap.size());
}
Also used : ContainerKeyPrefix(org.apache.hadoop.ozone.recon.api.types.ContainerKeyPrefix) Test(org.junit.Test)

Aggregations

ContainerKeyPrefix (org.apache.hadoop.ozone.recon.api.types.ContainerKeyPrefix)16 Test (org.junit.Test)10 OmKeyLocationInfo (org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo)4 OmKeyLocationInfoGroup (org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup)4 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 HashMap (java.util.HashMap)2 BlockID (org.apache.hadoop.hdds.client.BlockID)2 Pipeline (org.apache.hadoop.hdds.scm.pipeline.Pipeline)2 Table (org.apache.hadoop.hdds.utils.db.Table)2 OmKeyInfo (org.apache.hadoop.ozone.om.helpers.OmKeyInfo)2 OMMetadataManagerTestUtils.getOmKeyLocationInfo (org.apache.hadoop.ozone.recon.OMMetadataManagerTestUtils.getOmKeyLocationInfo)2 OMMetadataManagerTestUtils.getRandomPipeline (org.apache.hadoop.ozone.recon.OMMetadataManagerTestUtils.getRandomPipeline)2 ContainerMetadata (org.apache.hadoop.ozone.recon.api.types.ContainerMetadata)2 IOException (java.io.IOException)1 Instant (java.time.Instant)1 HashSet (java.util.HashSet)1 List (java.util.List)1 UUID (java.util.UUID)1