Skip to content

Commit 6da44f3

Browse files
author
Devesh Kumar Singh
committed
HDDS-13891. Fixing failing tests.
1 parent 587638a commit 6da44f3

4 files changed

Lines changed: 32 additions & 6 deletions

File tree

hadoop-hdds/common/src/main/resources/ozone-default.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4414,6 +4414,20 @@
44144414
Interval in MINUTES by Recon to request SCM DB Snapshot.
44154415
</description>
44164416
</property>
4417+
4418+
<property>
4419+
<name>ozone.recon.container.health.use.scm.report</name>
4420+
<value>false</value>
4421+
<tag>OZONE, MANAGEMENT, RECON</tag>
4422+
<description>
4423+
Feature flag to enable ContainerHealthTaskV2 which uses SCM's ReplicationManager
4424+
as the single source of truth for container health states. When enabled, V2 task
4425+
will sync container health states directly from SCM instead of computing them locally.
4426+
This provides more accurate and consistent container health reporting.
4427+
Default is false (uses legacy implementation).
4428+
</description>
4429+
</property>
4430+
44174431
<property>
44184432
<name>ozone.om.snapshot.compaction.dag.max.time.allowed</name>
44194433
<value>30d</value>

hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/fsck/ContainerHealthTaskV2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ private UnhealthyContainerRecordV2 createRecord(
349349
int actualReplicaCount,
350350
String reason) {
351351

352-
int replicaDelta = actualReplicaCount - expectedReplicaCount;
352+
int replicaDelta = expectedReplicaCount - actualReplicaCount;
353353

354354
return new UnhealthyContainerRecordV2(
355355
container.getContainerID(),

hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/fsck/TestContainerHealthTaskV2.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static org.junit.jupiter.api.Assertions.assertEquals;
2323
import static org.mockito.ArgumentMatchers.any;
2424
import static org.mockito.ArgumentMatchers.anyInt;
25+
import static org.mockito.ArgumentMatchers.anyLong;
2526
import static org.mockito.Mockito.mock;
2627
import static org.mockito.Mockito.when;
2728

@@ -316,13 +317,24 @@ public void testContainerInSCMButNotInRecon() throws Exception {
316317
List<ContainerInfo> scmContainers = getMockContainers(1);
317318
ContainerInfo scmContainer = scmContainers.get(0);
318319

319-
when(scmClientMock.getListOfContainers(anyInt(), anyInt(),
320-
any(HddsProtos.LifeCycleState.class))).thenReturn(scmContainers);
320+
// Mock getListOfContainers to handle pagination correctly
321+
// Return container for CLOSED state with startId=0, empty otherwise
322+
when(scmClientMock.getListOfContainers(anyLong(), anyInt(),
323+
any(HddsProtos.LifeCycleState.class))).thenAnswer(invocation -> {
324+
long startId = invocation.getArgument(0);
325+
HddsProtos.LifeCycleState state = invocation.getArgument(2);
326+
// Only return container for CLOSED state and startId=0
327+
if (state == HddsProtos.LifeCycleState.CLOSED && startId == 0) {
328+
return scmContainers;
329+
}
330+
return Collections.emptyList();
331+
});
321332
when(containerManagerMock.getContainer(scmContainer.containerID()))
322333
.thenThrow(new ContainerNotFoundException("Container not found in Recon"));
323334

324335
ReplicationManagerReport report = createMockReport(0, 1, 0, 0);
325-
when(scmClientMock.checkContainerStatus(scmContainer)).thenReturn(report);
336+
// Use any() matcher since getListOfContainers returns a list with the same container
337+
when(scmClientMock.checkContainerStatus(any(ContainerInfo.class))).thenReturn(report);
326338

327339
ReconTaskConfig reconTaskConfig = new ReconTaskConfig();
328340
reconTaskConfig.setMissingContainerTaskInterval(Duration.ofSeconds(2));
@@ -378,7 +390,7 @@ public void testContainerInReconButNotInSCM() throws Exception {
378390
// SCM doesn't have this container
379391
when(scmClientMock.checkContainerStatus(reconContainer))
380392
.thenThrow(new ContainerNotFoundException("Container not found in SCM"));
381-
when(scmClientMock.getListOfContainers(anyInt(), anyInt(),
393+
when(scmClientMock.getListOfContainers(anyLong(), anyInt(),
382394
any(HddsProtos.LifeCycleState.class))).thenReturn(Collections.emptyList());
383395

384396
// Insert a record for this container first

hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/persistence/AbstractReconSqlDBTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public String getDriverClass() {
179179
@Override
180180
public String getJdbcUrl() {
181181
return "jdbc:derby:" + tempDir.getAbsolutePath() +
182-
File.separator + "derby_recon.db";
182+
File.separator + "derby_recon.db;user=RECON;create=true";
183183
}
184184

185185
@Override

0 commit comments

Comments
 (0)