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