use of org.hadoop.ozone.recon.schema.tables.records.UnhealthyContainersRecord in project ozone by apache.
the class TestContainerHealthTaskRecordGenerator method testUnderReplicatedRecordRetainedAndUpdated.
@Test
public void testUnderReplicatedRecordRetainedAndUpdated() {
// under replicated container
Set<ContainerReplica> replicas = generateReplicas(container, CLOSED, CLOSED);
ContainerHealthStatus status = new ContainerHealthStatus(container, replicas, placementPolicy);
UnhealthyContainersRecord rec = underReplicatedRecord();
assertTrue(ContainerHealthTask.ContainerHealthRecords.retainOrUpdateRecord(status, rec));
// The record actual count should be updated from 1 -> 2
assertEquals(2, rec.getActualReplicaCount().intValue());
assertEquals(1, rec.getReplicaDelta().intValue());
// Missing / Over / Mis replicated should not be retained
assertFalse(ContainerHealthTask.ContainerHealthRecords.retainOrUpdateRecord(status, missingRecord()));
assertFalse(ContainerHealthTask.ContainerHealthRecords.retainOrUpdateRecord(status, overReplicatedRecord()));
assertFalse(ContainerHealthTask.ContainerHealthRecords.retainOrUpdateRecord(status, misReplicatedRecord()));
// Container is now replicated OK - should be removed.
replicas = generateReplicas(container, CLOSED, CLOSED, CLOSED);
status = new ContainerHealthStatus(container, replicas, placementPolicy);
assertFalse(ContainerHealthTask.ContainerHealthRecords.retainOrUpdateRecord(status, rec));
}
use of org.hadoop.ozone.recon.schema.tables.records.UnhealthyContainersRecord in project ozone by apache.
the class TestContainerHealthTaskRecordGenerator method testMisReplicatedRecordRetainedAndUpdated.
@Test
public void testMisReplicatedRecordRetainedAndUpdated() {
// under replicated container
Set<ContainerReplica> replicas = generateReplicas(container, CLOSED, CLOSED, CLOSED);
when(placementPolicy.validateContainerPlacement(Mockito.anyList(), Mockito.anyInt())).thenReturn(new ContainerPlacementStatusDefault(2, 3, 5));
ContainerHealthStatus status = new ContainerHealthStatus(container, replicas, placementPolicy);
UnhealthyContainersRecord rec = misReplicatedRecord();
assertTrue(ContainerHealthTask.ContainerHealthRecords.retainOrUpdateRecord(status, rec));
// The record actual count should be updated from 1 -> 2
assertEquals(2, rec.getActualReplicaCount().intValue());
assertEquals(1, rec.getReplicaDelta().intValue());
assertNotNull(rec.getReason());
// Missing / Over / Mis replicated should not be retained
assertFalse(ContainerHealthTask.ContainerHealthRecords.retainOrUpdateRecord(status, missingRecord()));
assertFalse(ContainerHealthTask.ContainerHealthRecords.retainOrUpdateRecord(status, underReplicatedRecord()));
assertFalse(ContainerHealthTask.ContainerHealthRecords.retainOrUpdateRecord(status, overReplicatedRecord()));
// Container is now placed OK - should be removed.
when(placementPolicy.validateContainerPlacement(Mockito.anyList(), Mockito.anyInt())).thenReturn(new ContainerPlacementStatusDefault(3, 3, 5));
status = new ContainerHealthStatus(container, replicas, placementPolicy);
assertFalse(ContainerHealthTask.ContainerHealthRecords.retainOrUpdateRecord(status, rec));
}
use of org.hadoop.ozone.recon.schema.tables.records.UnhealthyContainersRecord in project ozone by apache.
the class TestContainerHealthTaskRecordGenerator method testOverReplicatedRecordRetainedAndUpdated.
@Test
public void testOverReplicatedRecordRetainedAndUpdated() {
// under replicated container
Set<ContainerReplica> replicas = generateReplicas(container, CLOSED, CLOSED, CLOSED, CLOSED);
ContainerHealthStatus status = new ContainerHealthStatus(container, replicas, placementPolicy);
UnhealthyContainersRecord rec = overReplicatedRecord();
assertTrue(ContainerHealthTask.ContainerHealthRecords.retainOrUpdateRecord(status, rec));
// The record actual count should be updated from 5 -> 4
assertEquals(4, rec.getActualReplicaCount().intValue());
assertEquals(-1, rec.getReplicaDelta().intValue());
// Missing / Over / Mis replicated should not be retained
assertFalse(ContainerHealthTask.ContainerHealthRecords.retainOrUpdateRecord(status, missingRecord()));
assertFalse(ContainerHealthTask.ContainerHealthRecords.retainOrUpdateRecord(status, underReplicatedRecord()));
assertFalse(ContainerHealthTask.ContainerHealthRecords.retainOrUpdateRecord(status, misReplicatedRecord()));
// Container is now replicated OK - should be removed.
replicas = generateReplicas(container, CLOSED, CLOSED, CLOSED);
status = new ContainerHealthStatus(container, replicas, placementPolicy);
assertFalse(ContainerHealthTask.ContainerHealthRecords.retainOrUpdateRecord(status, rec));
}
use of org.hadoop.ozone.recon.schema.tables.records.UnhealthyContainersRecord in project ozone by apache.
the class ContainerHealthTask method processExistingDBRecords.
/**
* This method reads all existing records in the UnhealthyContainers table.
* The container records are read sorted by Container ID, as there can be
* more than 1 record per container.
* Each record is checked to see if it should be retained or deleted, and if
* any of the replica counts have changed the record is updated. Each record
* for a container is collected into a Set and when the next container id
* changes, indicating the end of the records for the current container,
* completeProcessingContainer is called. This will check to see if any
* additional records need to be added to the database.
*
* @param currentTime Timestamp to place on all records generated by this run
* @return Count of records processed
*/
private long processExistingDBRecords(long currentTime) {
long recordCount = 0;
try (Cursor<UnhealthyContainersRecord> cursor = containerHealthSchemaManager.getAllUnhealthyRecordsCursor()) {
ContainerHealthStatus currentContainer = null;
Set<String> existingRecords = new HashSet<>();
while (cursor.hasNext()) {
recordCount++;
UnhealthyContainersRecord rec = cursor.fetchNext();
try {
if (currentContainer == null) {
currentContainer = setCurrentContainer(rec.getContainerId());
}
if (currentContainer.getContainerID() != rec.getContainerId()) {
completeProcessingContainer(currentContainer, existingRecords, currentTime);
existingRecords.clear();
currentContainer = setCurrentContainer(rec.getContainerId());
}
if (ContainerHealthRecords.retainOrUpdateRecord(currentContainer, rec)) {
// Check if the missing container is deleted in SCM
if (currentContainer.isMissing() && containerDeletedInSCM(currentContainer.getContainer())) {
rec.delete();
}
existingRecords.add(rec.getContainerState());
if (rec.changed()) {
rec.update();
}
} else {
rec.delete();
}
} catch (ContainerNotFoundException cnf) {
rec.delete();
currentContainer = null;
}
}
// Remember to finish processing the last container
if (currentContainer != null) {
completeProcessingContainer(currentContainer, existingRecords, currentTime);
}
}
return recordCount;
}
Aggregations