Hello, restoring a checkpoint or a savepoint for m...
# troubleshooting
a
Hello, restoring a checkpoint or a savepoint for my StreamTableEnvironment sql query from a Kafka topic table + collect results in an error:
Copy code
Caused by: java.lang.IllegalStateException: userVisibleTail should not be larger than offset. This is a bug.
	at org.apache.flink.util.Preconditions.checkState(Preconditions.java:193)
	at org.apache.flink.streaming.api.operators.collect.AbstractCollectResultBuffer.sanityCheck(AbstractCollectResultBuffer.java:144)
	at org.apache.flink.streaming.api.operators.collect.AbstractCollectResultBuffer.dealWithResponse(AbstractCollectResultBuffer.java:94)
	at org.apache.flink.streaming.api.operators.collect.CollectResultFetcher.next(CollectResultFetcher.java:150)
	at org.apache.flink.streaming.api.operators.collect.CollectResultIterator.nextResultFromFetcher(CollectResultIterator.java:126)
	at org.apache.flink.streaming.api.operators.collect.CollectResultIterator.hasNext(CollectResultIterator.java:100)
	at java.base/java.util.Iterator.forEachRemaining(Unknown Source)
	at com.mycompany.flink.FlinkApp.main(FlinkApp.java:89)
Here is the code that I run inside the jobmanager as a jar:
Copy code
public static void main(String[] args) {
        var environment = StreamExecutionEnvironment.getExecutionEnvironment();

        environment.setRestartStrategy(RestartStrategies.fixedDelayRestart(5, Time.seconds(5)));
        environment.setStateBackend(new HashMapStateBackend());
        environment.enableCheckpointing(3000, CheckpointingMode.EXACTLY_ONCE);
        environment.setParallelism(1);
        // make sure 500 ms of progress happen between checkpoints
        environment.getCheckpointConfig().setMinPauseBetweenCheckpoints(500);

        // checkpoints have to complete within one minute, or are discarded
        environment.getCheckpointConfig().setCheckpointTimeout(60000);

        // only two consecutive checkpoint failures are tolerated
        environment.getCheckpointConfig().setTolerableCheckpointFailureNumber(2);

        // allow only one checkpoint to be in progress at the same time
        environment.getCheckpointConfig().setMaxConcurrentCheckpoints(1);

        // enable externalized checkpoints which are retained
        // after job cancellation
        environment
                .getCheckpointConfig()
                .setExternalizedCheckpointCleanup(CheckpointConfig.ExternalizedCheckpointCleanup.RETAIN_ON_CANCELLATION);

        // enables the unaligned checkpoints
        environment.getCheckpointConfig().enableUnalignedCheckpoints();

        // sets the checkpoint storage where checkpoint snapshots will be written
        Configuration config = new Configuration();
        config.set(CheckpointingOptions.CHECKPOINT_STORAGE, "filesystem");
        config.set(CheckpointingOptions.CHECKPOINTS_DIRECTORY, "file:////tmp///flink-checkpoints-directory");
        config.set(ExecutionCheckpointingOptions.ENABLE_CHECKPOINTS_AFTER_TASKS_FINISH, true);
        environment.configure(config);

        var flinkTableEnvironment = StreamTableEnvironment.create(environment);

        flinkTableEnvironment.executeSql("CREATE DATABASE IF NOT EXISTS `test`;").print();
        flinkTableEnvironment.executeSql("USE `test`;").print();
        flinkTableEnvironment
                .executeSql(
                        "CREATE TABLE `mytable` (" + "\n" +
                                "key STRING," + "\n" +
                                "`offset` BIGINT METADATA VIRTUAL," + "\n" +
                                "`ts` TIMESTAMP(3) METADATA FROM 'timestamp'," + "\n" +
                                "WATERMARK FOR ts AS ts" + "\n" +
                                ") WITH (" + "\n" +
                                "'connector' = 'kafka'," + "\n" +
                                "'topic' = 'mytopic'," + "\n" +
                                "'properties.bootstrap.servers' = 'redpanda:29092'," + "\n" +
                                "'properties.group.id' = 'testGroup1'," + "\n" +
                                "'properties.auto.offset.reset' = 'earliest'," + "\n" +
                                "'value.format' = 'avro-confluent'," + "\n" +
                                "'value.avro-confluent.url' = 'http://redpanda:8081'," + "\n" +
                                "'value.fields-include' = 'EXCEPT_KEY'," + "\n" +
                                "'key.fields' = 'key'," + "\n" +
                                "'key.format' = 'raw'," + "\n" +
                                "'scan.startup.mode' = 'group-offsets'" + "\n" +
                                ");"
                )
                .print();

        var query = flinkTableEnvironment.sqlQuery("SELECT * FROM `mytable`");
        try (var collected = flinkTableEnvironment.toChangelogStream(query).executeAndCollect("myjob")) {
            collected.forEachRemaining(row -> log.info("kind {}", row.getKind()));
        }
    }
Any idea what is wrong with the config? I tried both stopping the job with savepoint and resuming from there, or cancelling the job and resuming from a checkpoint but they both result in the same exception
r
Did you make any change to the underlying Flink version or your code?
Maybe the Flink version changed because you are referencing a
:latest
docker image?
a
I think there might have been a version mismatch between local (1.17.2) and containerized job manager (latest). I did switch the implementation to use a jdbc sink directly and executing the job without explicit collect part and now the check/savepointing works as expected
r
okay
Flink SQL doesn't support changing the code across check/savepoints
a
Yes, I did the change after nothing seemed to work with the sql + collect approach. Currently the project is good though with using a sink for the query, but there might be an underlying issue with kafka sql source + sql api collect when it comes to save/checkpoints