Search in sources :

Example 11 with MasterState

use of org.apache.flink.runtime.checkpoint.MasterState in project flink by apache.

the class MetadataV3SerializerTest method testCheckpointWithMasterAndTaskState.

private void testCheckpointWithMasterAndTaskState(String basePath) throws Exception {
    final Random rnd = new Random();
    final int maxNumMasterStates = 5;
    final int maxTaskStates = 20;
    final int maxNumSubtasks = 20;
    for (int i = 0; i < 100; ++i) {
        final long checkpointId = rnd.nextLong() & 0x7fffffffffffffffL;
        final int numTasks = rnd.nextInt(maxTaskStates) + 1;
        final int numSubtasks = rnd.nextInt(maxNumSubtasks) + 1;
        final Collection<OperatorState> taskStates = CheckpointTestUtils.createOperatorStates(rnd, basePath, numTasks, 0, 0, numSubtasks);
        final int numMasterStates = rnd.nextInt(maxNumMasterStates) + 1;
        final Collection<MasterState> masterStates = CheckpointTestUtils.createRandomMasterStates(rnd, numMasterStates);
        testCheckpointSerialization(checkpointId, taskStates, masterStates, basePath);
    }
}
Also used : Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) MasterState(org.apache.flink.runtime.checkpoint.MasterState) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState)

Example 12 with MasterState

use of org.apache.flink.runtime.checkpoint.MasterState in project flink by apache.

the class CheckpointTestUtils method createRandomMasterStates.

/**
 * Creates a bunch of random master states.
 */
public static Collection<MasterState> createRandomMasterStates(Random random, int num) {
    final ArrayList<MasterState> states = new ArrayList<>(num);
    for (int i = 0; i < num; i++) {
        int version = random.nextInt(10);
        String name = StringUtils.getRandomString(random, 5, 500);
        byte[] bytes = new byte[random.nextInt(5000) + 1];
        random.nextBytes(bytes);
        states.add(new MasterState(name, bytes, version));
    }
    return states;
}
Also used : MasterState(org.apache.flink.runtime.checkpoint.MasterState) ArrayList(java.util.ArrayList)

Example 13 with MasterState

use of org.apache.flink.runtime.checkpoint.MasterState in project flink by apache.

the class MetadataV3SerializerTest method testCheckpointWithFinishedTasks.

private void testCheckpointWithFinishedTasks(String basePath) throws Exception {
    final Random rnd = new Random();
    final int maxNumMasterStates = 5;
    final int maxNumSubtasks = 20;
    final int maxAllRunningTaskStates = 20;
    final int maxPartlyFinishedStates = 10;
    final int maxFullyFinishedSubtasks = 10;
    final long checkpointId = rnd.nextLong() & 0x7fffffffffffffffL;
    final int numSubtasks = rnd.nextInt(maxNumSubtasks) + 1;
    final int numAllRunningTasks = rnd.nextInt(maxAllRunningTaskStates) + 1;
    final int numPartlyFinishedTasks = rnd.nextInt(maxPartlyFinishedStates) + 1;
    final int numFullyFinishedTasks = rnd.nextInt(maxFullyFinishedSubtasks) + 1;
    final Collection<OperatorState> taskStates = CheckpointTestUtils.createOperatorStates(rnd, basePath, numAllRunningTasks, numPartlyFinishedTasks, numFullyFinishedTasks, numSubtasks);
    final int numMasterStates = rnd.nextInt(maxNumMasterStates) + 1;
    final Collection<MasterState> masterStates = CheckpointTestUtils.createRandomMasterStates(rnd, numMasterStates);
    testCheckpointSerialization(checkpointId, taskStates, masterStates, basePath);
}
Also used : Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) MasterState(org.apache.flink.runtime.checkpoint.MasterState) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState)

Aggregations

MasterState (org.apache.flink.runtime.checkpoint.MasterState)13 OperatorState (org.apache.flink.runtime.checkpoint.OperatorState)9 Random (java.util.Random)6 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)3 DataInputStream (java.io.DataInputStream)2 IOException (java.io.IOException)2 LinkedHashMap (java.util.LinkedHashMap)2 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)2 MasterTriggerRestoreHook (org.apache.flink.runtime.checkpoint.MasterTriggerRestoreHook)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataOutputStream (java.io.DataOutputStream)1 Collection (java.util.Collection)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionException (java.util.concurrent.CompletionException)1 Executor (java.util.concurrent.Executor)1 Nullable (javax.annotation.Nullable)1 FSDataInputStream (org.apache.flink.core.fs.FSDataInputStream)1