use of org.apache.hadoop.ozone.container.common.transport.server.ratis.RatisServerConfiguration in project ozone by apache.
the class TestContainerStateMachine method testRatisSnapshotRetention.
@Test
public void testRatisSnapshotRetention() throws Exception {
ContainerStateMachine stateMachine = (ContainerStateMachine) TestHelper.getStateMachine(cluster);
SimpleStateMachineStorage storage = (SimpleStateMachineStorage) stateMachine.getStateMachineStorage();
Assert.assertNull(storage.findLatestSnapshot());
// Write 10 keys. Num snapshots should be equal to config value.
for (int i = 1; i <= 10; i++) {
OzoneOutputStream key = objectStore.getVolume(volumeName).getBucket(bucketName).createKey(("ratis" + i), 1024, ReplicationType.RATIS, ReplicationFactor.ONE, new HashMap<>());
// First write and flush creates a container in the datanode
key.write(("ratis" + i).getBytes(UTF_8));
key.flush();
key.write(("ratis" + i).getBytes(UTF_8));
key.close();
}
RatisServerConfiguration ratisServerConfiguration = conf.getObject(RatisServerConfiguration.class);
stateMachine = (ContainerStateMachine) TestHelper.getStateMachine(cluster);
storage = (SimpleStateMachineStorage) stateMachine.getStateMachineStorage();
Path parentPath = storage.findLatestSnapshot().getFile().getPath();
int numSnapshots = parentPath.getParent().toFile().listFiles().length;
Assert.assertTrue(Math.abs(ratisServerConfiguration.getNumSnapshotsRetained() - numSnapshots) <= 1);
// Write 10 more keys. Num Snapshots should remain the same.
for (int i = 11; i <= 20; i++) {
OzoneOutputStream key = objectStore.getVolume(volumeName).getBucket(bucketName).createKey(("ratis" + i), 1024, ReplicationType.RATIS, ReplicationFactor.ONE, new HashMap<>());
// First write and flush creates a container in the datanode
key.write(("ratis" + i).getBytes(UTF_8));
key.flush();
key.write(("ratis" + i).getBytes(UTF_8));
key.close();
}
stateMachine = (ContainerStateMachine) TestHelper.getStateMachine(cluster);
storage = (SimpleStateMachineStorage) stateMachine.getStateMachineStorage();
parentPath = storage.findLatestSnapshot().getFile().getPath();
numSnapshots = parentPath.getParent().toFile().listFiles().length;
Assert.assertTrue(Math.abs(ratisServerConfiguration.getNumSnapshotsRetained() - numSnapshots) <= 1);
}
Aggregations