Search in sources :

Example 1 with RatisServerConfiguration

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);
}
Also used : ContainerStateMachine(org.apache.hadoop.ozone.container.common.transport.server.ratis.ContainerStateMachine) Path(java.nio.file.Path) RatisServerConfiguration(org.apache.hadoop.ozone.container.common.transport.server.ratis.RatisServerConfiguration) SimpleStateMachineStorage(org.apache.ratis.statemachine.impl.SimpleStateMachineStorage) OzoneOutputStream(org.apache.hadoop.ozone.client.io.OzoneOutputStream) Test(org.junit.Test)

Aggregations

Path (java.nio.file.Path)1 OzoneOutputStream (org.apache.hadoop.ozone.client.io.OzoneOutputStream)1 ContainerStateMachine (org.apache.hadoop.ozone.container.common.transport.server.ratis.ContainerStateMachine)1 RatisServerConfiguration (org.apache.hadoop.ozone.container.common.transport.server.ratis.RatisServerConfiguration)1 SimpleStateMachineStorage (org.apache.ratis.statemachine.impl.SimpleStateMachineStorage)1 Test (org.junit.Test)1