Search in sources :

Example 1 with UnhealthyContainersRecord

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));
}
Also used : ContainerReplica(org.apache.hadoop.hdds.scm.container.ContainerReplica) UnhealthyContainersRecord(org.hadoop.ozone.recon.schema.tables.records.UnhealthyContainersRecord) Test(org.junit.Test)

Example 2 with UnhealthyContainersRecord

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));
}
Also used : ContainerReplica(org.apache.hadoop.hdds.scm.container.ContainerReplica) UnhealthyContainersRecord(org.hadoop.ozone.recon.schema.tables.records.UnhealthyContainersRecord) ContainerPlacementStatusDefault(org.apache.hadoop.hdds.scm.container.placement.algorithms.ContainerPlacementStatusDefault) Test(org.junit.Test)

Example 3 with UnhealthyContainersRecord

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));
}
Also used : ContainerReplica(org.apache.hadoop.hdds.scm.container.ContainerReplica) UnhealthyContainersRecord(org.hadoop.ozone.recon.schema.tables.records.UnhealthyContainersRecord) Test(org.junit.Test)

Example 4 with UnhealthyContainersRecord

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;
}
Also used : UnhealthyContainersRecord(org.hadoop.ozone.recon.schema.tables.records.UnhealthyContainersRecord) ContainerNotFoundException(org.apache.hadoop.hdds.scm.container.ContainerNotFoundException) HashSet(java.util.HashSet)

Aggregations

UnhealthyContainersRecord (org.hadoop.ozone.recon.schema.tables.records.UnhealthyContainersRecord)4 ContainerReplica (org.apache.hadoop.hdds.scm.container.ContainerReplica)3 Test (org.junit.Test)3 HashSet (java.util.HashSet)1 ContainerNotFoundException (org.apache.hadoop.hdds.scm.container.ContainerNotFoundException)1 ContainerPlacementStatusDefault (org.apache.hadoop.hdds.scm.container.placement.algorithms.ContainerPlacementStatusDefault)1