|
@@ -353,6 +353,71 @@ public class TestContainerStateMachineFailures {
|
|
|
Assert.assertTrue(snapshot.getPath().equals(latestSnapshot.getPath()));
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testApplyTransactionIdempotencyWithClosedContainer()
|
|
|
+ throws Exception {
|
|
|
+ OzoneOutputStream key =
|
|
|
+ objectStore.getVolume(volumeName).getBucket(bucketName)
|
|
|
+ .createKey("ratis", 1024, ReplicationType.RATIS,
|
|
|
+ ReplicationFactor.ONE, new HashMap<>());
|
|
|
+ // First write and flush creates a container in the datanode
|
|
|
+ key.write("ratis".getBytes());
|
|
|
+ key.flush();
|
|
|
+ key.write("ratis".getBytes());
|
|
|
+ KeyOutputStream groupOutputStream = (KeyOutputStream) key.getOutputStream();
|
|
|
+ List<OmKeyLocationInfo> locationInfoList =
|
|
|
+ groupOutputStream.getLocationInfoList();
|
|
|
+ Assert.assertEquals(1, locationInfoList.size());
|
|
|
+ OmKeyLocationInfo omKeyLocationInfo = locationInfoList.get(0);
|
|
|
+ ContainerData containerData =
|
|
|
+ cluster.getHddsDatanodes().get(0).getDatanodeStateMachine()
|
|
|
+ .getContainer().getContainerSet()
|
|
|
+ .getContainer(omKeyLocationInfo.getContainerID())
|
|
|
+ .getContainerData();
|
|
|
+ Assert.assertTrue(containerData instanceof KeyValueContainerData);
|
|
|
+ key.close();
|
|
|
+ ContainerStateMachine stateMachine =
|
|
|
+ (ContainerStateMachine) ContainerTestHelper.getStateMachine(cluster);
|
|
|
+ SimpleStateMachineStorage storage =
|
|
|
+ (SimpleStateMachineStorage) stateMachine.getStateMachineStorage();
|
|
|
+ Path parentPath = storage.findLatestSnapshot().getFile().getPath();
|
|
|
+ // Since the snapshot threshold is set to 1, since there are
|
|
|
+ // applyTransactions, we should see snapshots
|
|
|
+ Assert.assertTrue(parentPath.getParent().toFile().listFiles().length > 0);
|
|
|
+ FileInfo snapshot = storage.findLatestSnapshot().getFile();
|
|
|
+ Assert.assertNotNull(snapshot);
|
|
|
+ long containerID = omKeyLocationInfo.getContainerID();
|
|
|
+ Pipeline pipeline = cluster.getStorageContainerLocationClient()
|
|
|
+ .getContainerWithPipeline(containerID).getPipeline();
|
|
|
+ XceiverClientSpi xceiverClient =
|
|
|
+ xceiverClientManager.acquireClient(pipeline);
|
|
|
+ ContainerProtos.ContainerCommandRequestProto.Builder request =
|
|
|
+ ContainerProtos.ContainerCommandRequestProto.newBuilder();
|
|
|
+ request.setDatanodeUuid(pipeline.getFirstNode().getUuidString());
|
|
|
+ request.setCmdType(ContainerProtos.Type.CloseContainer);
|
|
|
+ request.setContainerID(containerID);
|
|
|
+ request.setCloseContainer(
|
|
|
+ ContainerProtos.CloseContainerRequestProto.getDefaultInstance());
|
|
|
+ try {
|
|
|
+ xceiverClient.sendCommand(request.build());
|
|
|
+ } catch (IOException e) {
|
|
|
+ Assert.fail("Exception should not be thrown");
|
|
|
+ }
|
|
|
+ Assert.assertTrue(
|
|
|
+ cluster.getHddsDatanodes().get(0).getDatanodeStateMachine()
|
|
|
+ .getContainer().getContainerSet().getContainer(containerID)
|
|
|
+ .getContainerState()
|
|
|
+ == ContainerProtos.ContainerDataProto.State.CLOSED);
|
|
|
+ Assert.assertTrue(stateMachine.isStateMachineHealthy());
|
|
|
+ try {
|
|
|
+ stateMachine.takeSnapshot();
|
|
|
+ } catch (IOException ioe) {
|
|
|
+ Assert.fail("Exception should not be thrown");
|
|
|
+ }
|
|
|
+ FileInfo latestSnapshot = storage.findLatestSnapshot().getFile();
|
|
|
+ Assert.assertFalse(snapshot.getPath().equals(latestSnapshot.getPath()));
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testValidateBCSIDOnDnRestart() throws Exception {
|
|
|
OzoneOutputStream key =
|