devmadhuu commented on code in PR #12201:
URL: https://github.com/apache/ozone/pull/12201#discussion_r4752016145


##########
hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestContainerEndpoint.java:
##########
@@ -1092,7 +1092,50 @@ public void testUnhealthyContainersPaging()
   }
 
   @Test
-  public void testReplicaHistorySurvivesOmReprocess() throws Exception {
+  public void testUnhealthyContainersSkipsRowOfContainerNotInRecon() throws 
IOException, TimeoutException {
+    containerHealthSchemaManager.clearAllUnhealthyContainerRecords();
+    putContainerInfos(1);
+    id1 = newDatanode("host1", "127.0.0.1");
+    id2 = newDatanode("host2", "127.0.0.2");
+    id3 = newDatanode("host3", "127.0.0.3");
+    id4 = newDatanode("host4", "127.0.0.4");
+    // Container 100000 keeps a MISSING row but is no longer in Recon, as 
after an SCM snapshot replaced Recon's DB.
+    createUnhealthyRecord(1, UnHealthyContainerStates.MISSING.toString(), 3, 
0, 3, null, false);
+    createUnhealthyRecord(100000, UnHealthyContainerStates.MISSING.toString(), 
3, 0, 3, null, false);
+
+    UnhealthyContainersResponse all =
+        (UnhealthyContainersResponse) 
containerEndpoint.getUnhealthyContainers(1000, 0, 0).getEntity();
+    assertEquals(1, all.getContainers().size());
+    assertEquals(1L, all.getContainers().iterator().next().getContainerID());
+    assertEquals(1L, all.getFirstKey());
+    assertEquals(100000L, all.getLastKey());

Review Comment:
   Could we also `assert all.getMissingCount()` here? It is 2 while the list 
has 1 entry. That documents the current behaviour, and the test will catch it 
when the orphan rows are cleaned up.



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/ContainerEndpoint.java:
##########
@@ -483,6 +490,11 @@ private UnhealthyContainerMetadata toUnhealthyMetadata(
           record.getReason());
       return new UnhealthyContainerMetadata(unhealthyContainers, datanodes,
           pipelineID, keyCount);
+    } catch (ContainerNotFoundException e) {
+      // The row can outlive the container, for example after Recon replaced 
its SCM DB with an SCM snapshot.
+      LOG.warn("Skipping {} row of container {}, which is not in Recon.", 
record.getContainerState(),

Review Comment:
   Skipping fixes the HTTP 500, but the row itself is never removed: the health 
task only deletes and re-inserts rows for container IDs that Recon still has 
(`ReconReplicationManager.persistUnhealthyRecords`). So the summary count still 
includes it (the UI shows MISSING=2 while the list has 1), and this WARN is 
logged on every call.
   Could we file a follow-up to delete rows whose container is no longer in 
Recon, either in the health task or when Recon replaces its SCM DB from a 
snapshot? Until then, would DEBUG, or a WARN once per container, be better here 
to avoid log noise?



##########
hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestContainerEndpoint.java:
##########
@@ -1092,7 +1092,50 @@ public void testUnhealthyContainersPaging()
   }
 
   @Test
-  public void testReplicaHistorySurvivesOmReprocess() throws Exception {
+  public void testUnhealthyContainersSkipsRowOfContainerNotInRecon() throws 
IOException, TimeoutException {
+    containerHealthSchemaManager.clearAllUnhealthyContainerRecords();
+    putContainerInfos(1);
+    id1 = newDatanode("host1", "127.0.0.1");
+    id2 = newDatanode("host2", "127.0.0.2");
+    id3 = newDatanode("host3", "127.0.0.3");
+    id4 = newDatanode("host4", "127.0.0.4");
+    // Container 100000 keeps a MISSING row but is no longer in Recon, as 
after an SCM snapshot replaced Recon's DB.
+    createUnhealthyRecord(1, UnHealthyContainerStates.MISSING.toString(), 3, 
0, 3, null, false);
+    createUnhealthyRecord(100000, UnHealthyContainerStates.MISSING.toString(), 
3, 0, 3, null, false);
+
+    UnhealthyContainersResponse all =
+        (UnhealthyContainersResponse) 
containerEndpoint.getUnhealthyContainers(1000, 0, 0).getEntity();
+    assertEquals(1, all.getContainers().size());
+    assertEquals(1L, all.getContainers().iterator().next().getContainerID());
+    assertEquals(1L, all.getFirstKey());
+    assertEquals(100000L, all.getLastKey());
+
+    // A page that holds only the skipped row still returns its key, so that 
paging goes on past it.
+    UnhealthyContainersResponse page = (UnhealthyContainersResponse) 
containerEndpoint.getUnhealthyContainers(
+        UnHealthyContainerStates.MISSING.toString(), 1, 0, 1).getEntity();
+    assertTrue(page.getContainers().isEmpty());
+    assertEquals(100000L, page.getLastKey());
+  }
+
+  @Test
+  public void testGetMissingContainersSkipsRowOfContainerNotInRecon() throws 
IOException, TimeoutException {
+    containerHealthSchemaManager.clearAllUnhealthyContainerRecords();
+    putContainerInfos(1);
+    id1 = newDatanode("host1", "127.0.0.1");
+    id2 = newDatanode("host2", "127.0.0.2");
+    id3 = newDatanode("host3", "127.0.0.3");
+    id4 = newDatanode("host4", "127.0.0.4");
+    createUnhealthyRecord(1, UnHealthyContainerStates.MISSING.toString(), 3, 
0, 3, null, false);
+    createUnhealthyRecord(100000, UnHealthyContainerStates.MISSING.toString(), 
3, 0, 3, null, false);
+
+    MissingContainersResponse response =
+        (MissingContainersResponse) 
containerEndpoint.getMissingContainers(1000).getEntity();
+    assertEquals(1, response.getTotalCount());
+    assertEquals(1L, 
response.getContainers().iterator().next().getContainerID());
+  }
+
+  @Test
+  public void testReplicaHistorySurvivesOmReprocess()throws Exception {

Review Comment:
   nit: space before throws is removed.



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/ContainerEndpoint.java:
##########


Review Comment:
   this also can throw when container not exists, can throw pipeline null and 
then nullpointer exception.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to