Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_DEADNODE_INTERVAL;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_STALENODE_INTERVAL;
import static org.apache.hadoop.ozone.container.TestHelper.waitForContainerClose;
import static org.apache.hadoop.ozone.container.TestHelper.waitForContainerStateInSCM;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import java.io.OutputStream;
Expand All @@ -41,7 +41,6 @@
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.hdds.scm.container.ContainerID;
import org.apache.hadoop.hdds.scm.container.ContainerManager;
import org.apache.hadoop.hdds.scm.container.ContainerNotFoundException;
import org.apache.hadoop.ozone.HddsDatanodeService;
import org.apache.hadoop.ozone.MiniOzoneCluster;
import org.apache.hadoop.ozone.client.ObjectStore;
Expand All @@ -52,15 +51,12 @@
import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup;
import org.apache.ozone.test.GenericTestUtils;
import org.apache.ozone.test.tag.Flaky;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

/**
* Tests for container report handling.
*/
@Flaky("HDDS-12535")
public class TestContainerReportHandling {
private static final String VOLUME = "vol1";
private static final String BUCKET = "bucket1";
Expand Down Expand Up @@ -97,6 +93,9 @@ void testDeletingOrDeletedContainerTransitionsToClosedWhenNonEmptyReplicaIsRepor
ContainerID containerID = ContainerID.valueOf(keyLocation.getContainerID());
waitForContainerClose(cluster, containerID.getId());

// also wait till the container is closed in SCM
waitForContainerStateInSCM(cluster.getStorageContainerManager(), containerID, HddsProtos.LifeCycleState.CLOSED);

// move the container to DELETING
ContainerManager containerManager = cluster.getStorageContainerManager().getContainerManager();
containerManager.updateContainerState(containerID, HddsProtos.LifeCycleEvent.DELETE);
Expand All @@ -111,14 +110,7 @@ void testDeletingOrDeletedContainerTransitionsToClosedWhenNonEmptyReplicaIsRepor
// restart a DN and wait for the container to get CLOSED.
HddsDatanodeService dn = cluster.getHddsDatanode(keyLocation.getPipeline().getFirstNode());
cluster.restartHddsDatanode(dn.getDatanodeDetails(), false);
GenericTestUtils.waitFor(() -> {
try {
return containerManager.getContainer(containerID).getState() == HddsProtos.LifeCycleState.CLOSED;
} catch (ContainerNotFoundException e) {
fail(e);
}
return false;
}, 2000, 20000);
waitForContainerStateInSCM(cluster.getStorageContainerManager(), containerID, HddsProtos.LifeCycleState.CLOSED);

assertEquals(HddsProtos.LifeCycleState.CLOSED, containerManager.getContainer(containerID).getState());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,26 @@
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_DEADNODE_INTERVAL;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_STALENODE_INTERVAL;
import static org.apache.hadoop.ozone.container.TestHelper.waitForContainerClose;
import static org.apache.hadoop.ozone.container.TestHelper.waitForContainerStateInSCM;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.hdds.client.RatisReplicationConfig;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.hdds.scm.container.ContainerID;
import org.apache.hadoop.hdds.scm.container.ContainerManager;
import org.apache.hadoop.hdds.scm.container.ContainerNotFoundException;
import org.apache.hadoop.hdds.scm.server.StorageContainerManager;
import org.apache.hadoop.ozone.HddsDatanodeService;
import org.apache.hadoop.ozone.MiniOzoneCluster;
import org.apache.hadoop.ozone.MiniOzoneHAClusterImpl;
Expand All @@ -53,15 +54,12 @@
import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup;
import org.apache.ozone.test.GenericTestUtils;
import org.apache.ozone.test.tag.Flaky;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

/**
* Tests for container report handling with SCM High Availability.
*/
@Flaky("HDDS-12535")
public class TestContainerReportHandlingWithHA {
private static final String VOLUME = "vol1";
private static final String BUCKET = "bucket1";
Expand Down Expand Up @@ -99,6 +97,8 @@ void testDeletingOrDeletedContainerTransitionsToClosedWhenNonEmptyReplicaIsRepor
ContainerID containerID = ContainerID.valueOf(keyLocation.getContainerID());
waitForContainerClose(cluster, containerID.getId());

waitForContainerStateInAllSCMs(cluster, containerID, HddsProtos.LifeCycleState.CLOSED);

// move the container to DELETING
ContainerManager containerManager = cluster.getScmLeader().getContainerManager();
containerManager.updateContainerState(containerID, HddsProtos.LifeCycleEvent.DELETE);
Expand All @@ -113,23 +113,8 @@ void testDeletingOrDeletedContainerTransitionsToClosedWhenNonEmptyReplicaIsRepor
// restart a DN and wait for the container to get CLOSED in all SCMs
HddsDatanodeService dn = cluster.getHddsDatanode(keyLocation.getPipeline().getFirstNode());
cluster.restartHddsDatanode(dn.getDatanodeDetails(), false);
ContainerManager[] array = new ContainerManager[numSCM];
for (int i = 0; i < numSCM; i++) {
array[i] = cluster.getStorageContainerManager(i).getContainerManager();
}
Comment on lines -117 to -119
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously the HA test checked container state in all 3 SCMs, but I guess it is enough to check only the leader, as the test does with the patch.

GenericTestUtils.waitFor(() -> {
try {
for (ContainerManager manager : array) {
if (manager.getContainer(containerID).getState() != HddsProtos.LifeCycleState.CLOSED) {
return false;
}
}
return true;
} catch (ContainerNotFoundException e) {
fail(e);
}
return false;
}, 2000, 20000);

waitForContainerStateInAllSCMs(cluster, containerID, HddsProtos.LifeCycleState.CLOSED);

assertEquals(HddsProtos.LifeCycleState.CLOSED, containerManager.getContainer(containerID).getState());
}
Expand Down Expand Up @@ -177,4 +162,12 @@ private void createTestData(OzoneClient client) throws IOException {
}
}

private static void waitForContainerStateInAllSCMs(MiniOzoneHAClusterImpl cluster, ContainerID containerID,
HddsProtos.LifeCycleState desiredState)
throws TimeoutException, InterruptedException {
for (StorageContainerManager scm : cluster.getStorageContainerManagersList()) {
waitForContainerStateInSCM(scm, containerID, desiredState);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import java.security.MessageDigest;
Expand Down Expand Up @@ -455,4 +456,20 @@ public static void setConfig(OzoneConfiguration conf, String key, String value)
conf.set(key, value);
}
}

public static void waitForContainerStateInSCM(StorageContainerManager scm,
ContainerID containerID, HddsProtos.LifeCycleState expectedState)
throws TimeoutException, InterruptedException {
ContainerManager containerManager = scm.getContainerManager();
GenericTestUtils.waitFor(() -> {
try {
return containerManager.getContainer(containerID).getState() == expectedState;
} catch (ContainerNotFoundException e) {
LOG.error("Container {} not found while waiting for state {}",
containerID, expectedState, e);
fail("Container " + containerID + " not found while waiting for state " + expectedState + ": " + e);
return false;
}
}, 2000, 20000);
}
}