return new CheckpointStatsHistory( true, maxSize,
/** * Creates a new snapshot of the available stats. * * @return The latest statistics snapshot. */ public CheckpointStatsSnapshot createSnapshot() { CheckpointStatsSnapshot snapshot = latestSnapshot; // Only create a new snapshot if dirty and no update in progress, // because we don't want to block the coordinator. if (dirty && statsReadWriteLock.tryLock()) { try { // Create a new snapshot snapshot = new CheckpointStatsSnapshot( counts.createSnapshot(), summary.createSnapshot(), history.createSnapshot(), latestRestoredCheckpoint); latestSnapshot = snapshot; dirty = false; } finally { statsReadWriteLock.unlock(); } } return snapshot; }
@Override public Collection<ArchivedJson> archiveJsonWithPath(AccessExecutionGraph graph) throws IOException { CheckpointStatsSnapshot stats = graph.getCheckpointStatsSnapshot(); if (stats == null) { return Collections.emptyList(); } CheckpointStatsHistory history = stats.getHistory(); List<ArchivedJson> archive = new ArrayList<>(history.getCheckpoints().size()); for (AbstractCheckpointStats checkpoint : history.getCheckpoints()) { ResponseBody json = CheckpointStatistics.generateCheckpointStatistics(checkpoint, true); String path = getMessageHeaders().getTargetRestEndpointURL() .replace(':' + JobIDPathParameter.KEY, graph.getJobID().toString()) .replace(':' + CheckpointIdPathParameter.KEY, String.valueOf(checkpoint.getCheckpointId())); archive.add(new ArchivedJson(path, json)); } return archive; } }
private static String createCheckpointStatsJson(AccessExecutionGraph graph) throws IOException { StringWriter writer = new StringWriter(); JsonGenerator gen = JsonFactory.jacksonFactory.createGenerator(writer); CheckpointStatsSnapshot snapshot = graph.getCheckpointStatsSnapshot(); if (snapshot == null) { return "{}"; } gen.writeStartObject(); // Counts writeCounts(gen, snapshot.getCounts()); // Summary writeSummary(gen, snapshot.getSummaryStats()); CheckpointStatsHistory history = snapshot.getHistory(); // Latest writeLatestCheckpoints( gen, history.getLatestCompletedCheckpoint(), history.getLatestSavepoint(), history.getLatestFailedCheckpoint(), snapshot.getLatestRestoredCheckpoint()); // History writeHistory(gen, snapshot.getHistory()); gen.writeEndObject(); gen.close(); return writer.toString(); }
final CheckpointStatistics.CompletedCheckpointStatistics completed = checkpointStatsHistory.getLatestCompletedCheckpoint() != null ? (CheckpointStatistics.CompletedCheckpointStatistics) CheckpointStatistics.generateCheckpointStatistics( checkpointStatsHistory.getLatestCompletedCheckpoint(), false) : null; final CheckpointStatistics.CompletedCheckpointStatistics savepoint = checkpointStatsHistory.getLatestSavepoint() != null ? (CheckpointStatistics.CompletedCheckpointStatistics) CheckpointStatistics.generateCheckpointStatistics( checkpointStatsHistory.getLatestSavepoint(), false) : null; final CheckpointStatistics.FailedCheckpointStatistics failed = checkpointStatsHistory.getLatestFailedCheckpoint() != null ? (CheckpointStatistics.FailedCheckpointStatistics) CheckpointStatistics.generateCheckpointStatistics( checkpointStatsHistory.getLatestFailedCheckpoint(), false) : null; for (AbstractCheckpointStats abstractCheckpointStats : checkpointStatsSnapshot.getHistory().getCheckpoints()) { history.add(CheckpointStatistics.generateCheckpointStatistics(abstractCheckpointStats, false));
this.history = new CheckpointStatsHistory(numRememberedCheckpoints); this.jobVertices = checkNotNull(jobVertices, "JobVertices"); this.jobCheckpointingConfiguration = checkNotNull(jobCheckpointingConfiguration); counts.createSnapshot(), summary.createSnapshot(), history.createSnapshot(), null);
/** * Callback when a checkpoint fails. * * @param failed The failed checkpoint stats. */ private void reportFailedCheckpoint(FailedCheckpointStats failed) { statsReadWriteLock.lock(); try { counts.incrementFailedCheckpoints(); history.replacePendingCheckpointById(failed); dirty = true; } finally { statsReadWriteLock.unlock(); } }
AbstractCheckpointStats checkpoint = snapshot.getHistory().getCheckpointById(checkpointId);
/** * Creates a new pending checkpoint tracker. * * @param checkpointId ID of the checkpoint. * @param triggerTimestamp Trigger timestamp of the checkpoint. * @param props The checkpoint properties. * @return Tracker for statistics gathering. */ PendingCheckpointStats reportPendingCheckpoint( long checkpointId, long triggerTimestamp, CheckpointProperties props) { ConcurrentHashMap<JobVertexID, TaskStateStats> taskStateStats = createEmptyTaskStateStatsMap(); PendingCheckpointStats pending = new PendingCheckpointStats( checkpointId, triggerTimestamp, props, totalSubtaskCount, taskStateStats, new PendingCheckpointStatsCallback()); statsReadWriteLock.lock(); try { counts.incrementInProgressCheckpoints(); history.addInProgressCheckpoint(pending); dirty = true; } finally { statsReadWriteLock.unlock(); } return pending; }
final CheckpointStatistics.CompletedCheckpointStatistics completed = checkpointStatsHistory.getLatestCompletedCheckpoint() != null ? (CheckpointStatistics.CompletedCheckpointStatistics) CheckpointStatistics.generateCheckpointStatistics( checkpointStatsHistory.getLatestCompletedCheckpoint(), false) : null; final CheckpointStatistics.CompletedCheckpointStatistics savepoint = checkpointStatsHistory.getLatestSavepoint() != null ? (CheckpointStatistics.CompletedCheckpointStatistics) CheckpointStatistics.generateCheckpointStatistics( checkpointStatsHistory.getLatestSavepoint(), false) : null; final CheckpointStatistics.FailedCheckpointStatistics failed = checkpointStatsHistory.getLatestFailedCheckpoint() != null ? (CheckpointStatistics.FailedCheckpointStatistics) CheckpointStatistics.generateCheckpointStatistics( checkpointStatsHistory.getLatestFailedCheckpoint(), false) : null; for (AbstractCheckpointStats abstractCheckpointStats : checkpointStatsSnapshot.getHistory().getCheckpoints()) { history.add(CheckpointStatistics.generateCheckpointStatistics(abstractCheckpointStats, false));
private static String createCheckpointStatsJson(AccessExecutionGraph graph) throws IOException { StringWriter writer = new StringWriter(); JsonGenerator gen = JsonFactory.JACKSON_FACTORY.createGenerator(writer); CheckpointStatsSnapshot snapshot = graph.getCheckpointStatsSnapshot(); if (snapshot == null) { return "{}"; } gen.writeStartObject(); // Counts writeCounts(gen, snapshot.getCounts()); // Summary writeSummary(gen, snapshot.getSummaryStats()); CheckpointStatsHistory history = snapshot.getHistory(); // Latest writeLatestCheckpoints( gen, history.getLatestCompletedCheckpoint(), history.getLatestSavepoint(), history.getLatestFailedCheckpoint(), snapshot.getLatestRestoredCheckpoint()); // History writeHistory(gen, snapshot.getHistory()); gen.writeEndObject(); gen.close(); return writer.toString(); }
this.history = new CheckpointStatsHistory(numRememberedCheckpoints); this.jobVertices = checkNotNull(jobVertices, "JobVertices"); this.jobCheckpointingSettings = checkNotNull(jobCheckpointingSettings); counts.createSnapshot(), summary.createSnapshot(), history.createSnapshot(), null);
/** * Callback when a checkpoint fails. * * @param failed The failed checkpoint stats. */ private void reportFailedCheckpoint(FailedCheckpointStats failed) { statsReadWriteLock.lock(); try { counts.incrementFailedCheckpoints(); history.replacePendingCheckpointById(failed); dirty = true; } finally { statsReadWriteLock.unlock(); } }
@Override public String handleRequest(AccessExecutionGraph graph, Map<String, String> params) throws Exception { long checkpointId = parseCheckpointId(params); if (checkpointId == -1) { return "{}"; } CheckpointStatsSnapshot snapshot = graph.getCheckpointStatsSnapshot(); if (snapshot == null) { return "{}"; } AbstractCheckpointStats checkpoint = snapshot.getHistory().getCheckpointById(checkpointId); if (checkpoint != null) { cache.tryAdd(checkpoint); } else { checkpoint = cache.tryGet(checkpointId); if (checkpoint == null) { return "{}"; } } return createCheckpointDetailsJson(checkpoint); }
/** * Creates a new pending checkpoint tracker. * * @param checkpointId ID of the checkpoint. * @param triggerTimestamp Trigger timestamp of the checkpoint. * @param props The checkpoint properties. * @return Tracker for statistics gathering. */ PendingCheckpointStats reportPendingCheckpoint( long checkpointId, long triggerTimestamp, CheckpointProperties props) { ConcurrentHashMap<JobVertexID, TaskStateStats> taskStateStats = createEmptyTaskStateStatsMap(); PendingCheckpointStats pending = new PendingCheckpointStats( checkpointId, triggerTimestamp, props, totalSubtaskCount, taskStateStats, new PendingCheckpointStatsCallback()); statsReadWriteLock.lock(); try { counts.incrementInProgressCheckpoints(); history.addInProgressCheckpoint(pending); dirty = true; } finally { statsReadWriteLock.unlock(); } return pending; }
final CheckpointStatistics.CompletedCheckpointStatistics completed = checkpointStatsHistory.getLatestCompletedCheckpoint() != null ? (CheckpointStatistics.CompletedCheckpointStatistics) CheckpointStatistics.generateCheckpointStatistics( checkpointStatsHistory.getLatestCompletedCheckpoint(), false) : null; final CheckpointStatistics.CompletedCheckpointStatistics savepoint = checkpointStatsHistory.getLatestSavepoint() != null ? (CheckpointStatistics.CompletedCheckpointStatistics) CheckpointStatistics.generateCheckpointStatistics( checkpointStatsHistory.getLatestSavepoint(), false) : null; final CheckpointStatistics.FailedCheckpointStatistics failed = checkpointStatsHistory.getLatestFailedCheckpoint() != null ? (CheckpointStatistics.FailedCheckpointStatistics) CheckpointStatistics.generateCheckpointStatistics( checkpointStatsHistory.getLatestFailedCheckpoint(), false) : null; for (AbstractCheckpointStats abstractCheckpointStats : checkpointStatsSnapshot.getHistory().getCheckpoints()) { history.add(CheckpointStatistics.generateCheckpointStatistics(abstractCheckpointStats, false));
this.history = new CheckpointStatsHistory(numRememberedCheckpoints); this.jobVertices = checkNotNull(jobVertices, "JobVertices"); this.jobCheckpointingConfiguration = checkNotNull(jobCheckpointingConfiguration); counts.createSnapshot(), summary.createSnapshot(), history.createSnapshot(), null);
@Override public Collection<ArchivedJson> archiveJsonWithPath(AccessExecutionGraph graph) throws IOException { CheckpointStatsSnapshot stats = graph.getCheckpointStatsSnapshot(); if (stats == null) { return Collections.emptyList(); } CheckpointStatsHistory history = stats.getHistory(); List<ArchivedJson> archive = new ArrayList<>(history.getCheckpoints().size()); for (AbstractCheckpointStats checkpoint : history.getCheckpoints()) { ResponseBody json = CheckpointStatistics.generateCheckpointStatistics(checkpoint, true); String path = getMessageHeaders().getTargetRestEndpointURL() .replace(':' + JobIDPathParameter.KEY, graph.getJobID().toString()) .replace(':' + CheckpointIdPathParameter.KEY, String.valueOf(checkpoint.getCheckpointId())); archive.add(new ArchivedJson(path, json)); } return archive; } }
/** * Callback when a checkpoint fails. * * @param failed The failed checkpoint stats. */ private void reportFailedCheckpoint(FailedCheckpointStats failed) { statsReadWriteLock.lock(); try { counts.incrementFailedCheckpoints(); history.replacePendingCheckpointById(failed); dirty = true; } finally { statsReadWriteLock.unlock(); } }
@Override public CompletableFuture<String> handleRequest(AccessExecutionGraph graph, Map<String, String> params) { return CompletableFuture.supplyAsync( () -> { long checkpointId = parseCheckpointId(params); if (checkpointId == -1) { return "{}"; } CheckpointStatsSnapshot snapshot = graph.getCheckpointStatsSnapshot(); if (snapshot == null) { return "{}"; } AbstractCheckpointStats checkpoint = snapshot.getHistory().getCheckpointById(checkpointId); if (checkpoint != null) { cache.tryAdd(checkpoint); } else { checkpoint = cache.tryGet(checkpointId); if (checkpoint == null) { return "{}"; } } try { return createCheckpointDetailsJson(checkpoint); } catch (IOException e) { throw new CompletionException(new FlinkException("Could not create checkpoint details json.", e)); } }, executor); }