Source:
public void recover() throws Exception { LOG.info("Recovering checkpoints from ZooKeeper."); List<Tuple2<RetrievableStateHandle<CompletedCheckpoint>, String>> initialCheckpoints; while (true) { try { initialCheckpoints = checkpointsInZooKeeper.getAllAndLock(); break; } catch (ConcurrentModificationException e) { LOG.warn("Concurrent modification while reading from ZooKeeper. Retrying."); } } Collections.sort(initialCheckpoints, STRING_COMPARATOR); int numberOfInitialCheckpoints = initialCheckpoints.size(); LOG.info("Found checkpoints in ZooKeeper.", numberOfInitialCheckpoints); if (haveAllDownloaded(initialCheckpoints)) { LOG.info("All checkpoints found are already downloaded."); return; } List<CompletedCheckpoint> lastTryRetrievedCheckpoints = new ArrayList<>(numberOfInitialCheckpoints); List<CompletedCheckpoint> retrievedCheckpoints = new ArrayList<>(numberOfInitialCheckpoints); do { LOG.info("Trying to fetch checkpoints from storage.", numberOfInitialCheckpoints); lastTryRetrievedCheckpoints.clear(); lastTryRetrievedCheckpoints.addAll(retrievedCheckpoints); retrievedCheckpoints.clear(); for (Tuple2<RetrievableStateHandle<CompletedCheckpoint>, String> checkpointStateHandle : initialCheckpoints) { CompletedCheckpoint completedCheckpoint; try { completedCheckpoint = retrieveCompletedCheckpoint(checkpointStateHandle); if (completedCheckpoint != null) { retrievedCheckpoints.add(completedCheckpoint); } } catch (Exception e) { LOG.warn("Could not retrieve checkpoint, not adding to list of recovered checkpoints.", e); } } } while (retrievedCheckpoints.size() != numberOfInitialCheckpoints && !CompletedCheckpoint.checkpointsMatch(lastTryRetrievedCheckpoints, retrievedCheckpoints)); completedCheckpoints.clear(); completedCheckpoints.addAll(retrievedCheckpoints); if (completedCheckpoints.isEmpty() && numberOfInitialCheckpoints > 0) { throw new FlinkException( "Could not read any of the " + numberOfInitialCheckpoints + " checkpoints from storage."); } else if (completedCheckpoints.size() != numberOfInitialCheckpoints) { LOG.warn( "Could only fetch of checkpoints from storage.", completedCheckpoints.size(), numberOfInitialCheckpoints); } }

Target:
public void recover() throws Exception { LOG.info("Recovering checkpoints from ZooKeeper."); List<Tuple2<RetrievableStateHandle<CompletedCheckpoint>, String>> initialCheckpoints; while (true) { try { initialCheckpoints = checkpointsInZooKeeper.getAllAndLock(); break; } catch (ConcurrentModificationException e) { LOG.warn("Concurrent modification while reading from ZooKeeper. Retrying."); } } Collections.sort(initialCheckpoints, STRING_COMPARATOR); int numberOfInitialCheckpoints = initialCheckpoints.size(); LOG.info("Found checkpoints in ZooKeeper.", numberOfInitialCheckpoints); if (haveAllDownloaded(initialCheckpoints)) { LOG.info("All checkpoints found are already downloaded.", numberOfInitialCheckpoints); return; } List<CompletedCheckpoint> lastTryRetrievedCheckpoints = new ArrayList<>(numberOfInitialCheckpoints); List<CompletedCheckpoint> retrievedCheckpoints = new ArrayList<>(numberOfInitialCheckpoints); Exception retrieveException = null; do { LOG.info("Trying to fetch checkpoints from storage.", numberOfInitialCheckpoints); lastTryRetrievedCheckpoints.clear(); lastTryRetrievedCheckpoints.addAll(retrievedCheckpoints); retrievedCheckpoints.clear(); for (Tuple2<RetrievableStateHandle<CompletedCheckpoint>, String> checkpointStateHandle : initialCheckpoints) { CompletedCheckpoint completedCheckpoint; try { completedCheckpoint = retrieveCompletedCheckpoint(checkpointStateHandle); if (completedCheckpoint != null) { retrievedCheckpoints.add(completedCheckpoint); } } catch (Exception e) { LOG.warn("Could not retrieve checkpoint, not adding to list of recovered checkpoints.", e); retrieveException = e; } } } while (retrievedCheckpoints.size() != numberOfInitialCheckpoints && !CompletedCheckpoint.checkpointsMatch(lastTryRetrievedCheckpoints, retrievedCheckpoints)); completedCheckpoints.clear(); completedCheckpoints.addAll(retrievedCheckpoints); if (completedCheckpoints.isEmpty() && numberOfInitialCheckpoints > 0) { throw new FlinkException( "Could not read any of the " + numberOfInitialCheckpoints + " checkpoints from storage.", retrieveException); } else if (completedCheckpoints.size() != numberOfInitialCheckpoints) { LOG.warn( "Could only fetch of checkpoints from storage.", completedCheckpoints.size(), numberOfInitialCheckpoints); } }