This checkpoint comparison is ported from CouchDBs source they come from here: https://github.com/apache/couchdb-couch-replicator/blob/master/src/couch_replicator.erl#L863-L906
426171
function compareReplicationLogs(srcDoc, tgtDoc) {
  if (srcDoc.session_id === tgtDoc.session_id) {
    return {
      last_seq: srcDoc.last_seq,
      history: srcDoc.history
    };
  }

  return compareReplicationHistory(srcDoc.history, tgtDoc.history);
}
849701
def _variant_checkpoints(samples):
    
    checkpoints = {}
    checkpoints["vc"] = any([dd.get_variantcaller(d) or d.get("vrn_file") for d in samples])
    checkpoints["sv"] = any([dd.get_svcaller(d) for d in samples])
    checkpoints["jointvc"] = any([(dd.get_jointcaller(d) or "gvcf" in dd.get_tools_on(d))
                                  for d in samples])
    checkpoints["hla"] = any([dd.get_hlacaller(d) for d in samples])
    checkpoints["align"] = any([(dd.get_aligner(d) or dd.get_bam_clean(d)) for d in samples])
    checkpoints["align_split"] = not all([(dd.get_align_split_size(d) is False or
                                           not dd.get_aligner(d))
                                          for d in samples])
    checkpoints["archive"] = any([dd.get_archive(d) for d in samples])
    checkpoints["umi"] = any([dd.get_umi_consensus(d) for d in samples])
    checkpoints["ensemble"] = any([dd.get_ensemble(d) for d in samples])
    checkpoints["cancer"] = any(dd.get_phenotype(d) in ["tumor"] for d in samples)
    return checkpoints
1374028
def checkpoint(self):
        
        if not self._metadata_checkpoint_dir:
            return
        metadata_checkpoint_dir = self._metadata_checkpoint_dir
        if not os.path.exists(metadata_checkpoint_dir):
            os.makedirs(metadata_checkpoint_dir)
        runner_state = {
            "checkpoints": list(
                self.trial_executor.get_checkpoints().values()),
            "runner_data": self.__getstate__(),
            "timestamp": time.time()
        }
        tmp_file_name = os.path.join(metadata_checkpoint_dir,
                                     ".tmp_checkpoint")
        with open(tmp_file_name, "w") as f:
            json.dump(runner_state, f, indent=2, cls=_TuneFunctionEncoder)

        os.rename(
            tmp_file_name,
            os.path.join(metadata_checkpoint_dir,
                         TrialRunner.CKPT_FILE_TMPL.format(self._session_str)))
        return metadata_checkpoint_dir
1356126
private boolean checkPoint(int mx, int my, ControlPoint pt) {
		int dx = (int) Math.abs((10+(width * pt.pos)) - mx);
		int dy = Math.abs((y+barHeight+7)-my);
		
		if ((dx < 5) && (dy < 7)) {
			return true;
		}
		
		return false;
	}
393668
@Override
	public CompletableFuture<Acknowledge> triggerCheckpoint(
			ExecutionAttemptID executionAttemptID,
			long checkpointId,
			long checkpointTimestamp,
			CheckpointOptions checkpointOptions,
			boolean advanceToEndOfEventTime) {
		log.debug("Trigger checkpoint {}@{} for {}.", checkpointId, checkpointTimestamp, executionAttemptID);

		final CheckpointType checkpointType = checkpointOptions.getCheckpointType();
		if (advanceToEndOfEventTime && !(checkpointType.isSynchronous() && checkpointType.isSavepoint())) {
			throw new IllegalArgumentException("Only synchronous savepoints are allowed to advance the watermark to MAX.");
		}

		final Task task = taskSlotTable.getTask(executionAttemptID);

		if (task != null) {
			task.triggerCheckpointBarrier(checkpointId, checkpointTimestamp, checkpointOptions, advanceToEndOfEventTime);

			return CompletableFuture.completedFuture(Acknowledge.get());
		} else {
			final String message = "TaskManager received a checkpoint request for unknown task " + executionAttemptID + '.';

			log.debug(message);
			return FutureUtils.completedExceptionally(new CheckpointException(message));
		}
	}
507269
def count_replica(self, partition):
        """"""
        return sum(1 for b in partition.replicas if b in self.brokers)
43055
private CheckpointData queryCheckpointData(Object key) {
		logger.entering(CLASSNAME, "queryCheckpointData", new Object[] {key, SELECT_CHECKPOINTDATA});
		Connection conn = null;
		PreparedStatement statement = null;
		ResultSet rs = null;
		ObjectInputStream objectIn = null;
		CheckpointData data = null;
		try {
			conn = getConnection();
			statement = conn.prepareStatement(SELECT_CHECKPOINTDATA);
			statement.setObject(1, key);
			rs = statement.executeQuery();
			if (rs.next()) {
				byte[] buf = rs.getBytes("obj");
				data = (CheckpointData)deserializeObject(buf);
			}
		} catch (SQLException e) {
			throw new PersistenceException(e);
		} catch (IOException e) {
			throw new PersistenceException(e);
		} catch (ClassNotFoundException e) {
			throw new PersistenceException(e);
		} finally {
			if (objectIn != null) {
				try {
					objectIn.close();
				} catch (IOException e) {
					throw new PersistenceException(e);
				}
			}
			cleanupConnection(conn, rs, statement);
		}
		logger.exiting(CLASSNAME, "queryCheckpointData");
		return data;	
	}
637252
def complete_offset_upload(self, chunk_num):
        # type: (Descriptor, int) -> None
        
        with self._meta_lock:
            self._outstanding_ops -= 1
            # save resume state
            if self.is_resumable:
                # only set resumable completed if all replicas for this
                # chunk are complete
                if blobxfer.util.is_not_empty(self._ase.replica_targets):
                    if chunk_num not in self._replica_counters:
                        # start counter at -1 since we need 1 "extra" for the
                        # primary in addition to the replica targets
                        self._replica_counters[chunk_num] = -1
                    self._replica_counters[chunk_num] += 1
                    if (self._replica_counters[chunk_num] !=
                            len(self._ase.replica_targets)):
                        return
                    else:
                        self._replica_counters.pop(chunk_num)
                self._completed_chunks.set(True, chunk_num)
                completed = self._outstanding_ops == 0
                if not completed and self.must_compute_md5:
                    last_consecutive = (
                        self._completed_chunks.find('0b0')[0] - 1
                    )
                    md5digest = self._md5_cache[last_consecutive]
                else:
                    md5digest = None
                self._resume_mgr.add_or_update_record(
                    self.local_path.absolute_path, self._ase, self._chunk_size,
                    self._total_chunks, self._completed_chunks.int, completed,
                    md5digest,
                )
                # prune md5 cache
                if self.must_compute_md5:
                    if completed:
                        self._md5_cache.clear()
                    elif (len(self._md5_cache) >
                          _MD5_CACHE_RESUME_ENTRIES_GC_THRESHOLD):
                        mkeys = sorted(list(self._md5_cache.keys()))
                        for key in mkeys:
                            if key >= last_consecutive:
                                break
                            self._md5_cache.pop(key)
632077
private void checkPoint(Collidable objectA, Map<Point, Set<Collidable>> acceptedElements, Point point)
    {
        final Set<Collidable> others = acceptedElements.get(point);
        for (final Collidable objectB : others)
        {
            if (objectA != objectB)
            {
                final List<Collision> collisions = objectA.collide(objectB);
                for (final Collision collision : collisions)
                {
                    toNotify.add(new Collided(objectA, objectB, collision));
                }
            }
        }
    }
1034815
def _resume(self):
        # type: (Descriptor) -> int
        
        if self._resume_mgr is None or self._offset > 0:
            return None
        # check if path exists in resume db
        rr = self._resume_mgr.get_record(self._ase)
        if rr is None:
            logger.debug('no resume record for {}'.format(self._ase.path))
            return None
        # ensure lengths are the same
        if rr.length != self._ase.size:
            logger.warning('resume length mismatch {} -> {}'.format(
                rr.length, self._ase.size))
            return None
        # compute replica factor
        if blobxfer.util.is_not_empty(self._ase.replica_targets):
            replica_factor = 1 + len(self._ase.replica_targets)
        else:
            replica_factor = 1
        # set offsets if completed
        if rr.completed:
            with self._meta_lock:
                logger.debug('{} upload already completed'.format(
                    self._ase.path))
                self._offset = rr.total_chunks * rr.chunk_size
                self._chunk_num = rr.total_chunks
                self._chunk_size = rr.chunk_size
                self._total_chunks = rr.total_chunks
                self._completed_chunks.int = rr.completed_chunks
                self._outstanding_ops = 0
                return self._ase.size * replica_factor
        # encrypted files are not resumable due to hmac requirement
        if self._ase.is_encrypted:
            logger.debug('cannot resume encrypted entity {}'.format(
                self._ase.path))
            return None
        # check if path exists
        if not pathlib.Path(rr.local_path).exists():
            logger.warning('resume from local path {} does not exist'.format(
                rr.local_path))
            return None
        # re-hash from 0 to offset if needed
        _cc = bitstring.BitArray(length=rr.total_chunks)
        _cc.int = rr.completed_chunks
        curr_chunk = _cc.find('0b0')[0]
        del _cc
        _fd_offset = 0
        _end_offset = min((curr_chunk * rr.chunk_size, rr.length))
        if self.md5 is not None and curr_chunk > 0:
            _blocksize = blobxfer.util.MEGABYTE << 2
            logger.debug(
                'integrity checking existing file {} offset {} -> {}'.format(
                    self._ase.path,
                    self.local_path.view.fd_start,
                    self.local_path.view.fd_start + _end_offset)
            )
            with self._hasher_lock:
                with self.local_path.absolute_path.open('rb') as filedesc:
                    filedesc.seek(self.local_path.view.fd_start, 0)
                    while _fd_offset < _end_offset:
                        if (_fd_offset + _blocksize) > _end_offset:
                            _blocksize = _end_offset - _fd_offset
                        _buf = filedesc.read(_blocksize)
                        self.md5.update(_buf)
                        _fd_offset += _blocksize
            del _blocksize
            # compare hashes
            hexdigest = self.md5.hexdigest()
            if rr.md5hexdigest != hexdigest:
                logger.warning(
                    'MD5 mismatch resume={} computed={} for {}'.format(
                        rr.md5hexdigest, hexdigest, self._ase.path))
                # reset hasher
                self.md5 = blobxfer.util.new_md5_hasher()
                return None
        # set values from resume
        with self._meta_lock:
            self._offset = _end_offset
            self._chunk_num = curr_chunk
            self._chunk_size = rr.chunk_size
            self._total_chunks = rr.total_chunks
            self._completed_chunks = bitstring.BitArray(length=rr.total_chunks)
            self._completed_chunks.set(True, range(0, curr_chunk + 1))
            self._outstanding_ops = (
                (rr.total_chunks - curr_chunk) * replica_factor
            )
            logger.debug(
                ('resuming file {} from byte={} chunk={} chunk_size={} '
                 'total_chunks={} outstanding_ops={}').format(
                     self._ase.path, self._offset, self._chunk_num,
                     self._chunk_size, self._total_chunks,
                     self._outstanding_ops))
            return _end_offset * replica_factor
788898
def _checkpoint_and_erase(self, trial):
        

        with warn_if_slow("save_to_disk"):
            trial._checkpoint.value = ray.get(trial.runner.save.remote())

        if len(trial.history) >= trial.keep_checkpoints_num:
            ray.get(trial.runner.delete_checkpoint.remote(trial.history[-1]))
            trial.history.pop()

        trial.history.insert(0, trial._checkpoint.value)
363390
private void checkpoint(IRecordProcessorCheckpointer checkpointer) {
        LOG.info("Checkpointing shard " + kinesisShardId);
        for (int i = 0; i < NUM_RETRIES; i++) {
            try {
                checkpointer.checkpoint();
                break;
            } catch (ShutdownException se) {
                // Ignore checkpoint if the processor instance has been shutdown (fail over).
                LOG.info("Caught shutdown exception, skipping checkpoint.", se);
                break;
            } catch (ThrottlingException e) {
                // Backoff and re-attempt checkpoint upon transient failures
                if (i >= (NUM_RETRIES - 1)) {
                    LOG.error("Checkpoint failed after " + (i + 1) + "attempts.", e);
                    break;
                } else {
                    LOG.info("Transient issue when checkpointing - attempt " + (i + 1) + " of "
                            + NUM_RETRIES, e);
                }
            } catch (InvalidStateException e) {
                // This indicates an issue with the DynamoDB table (check for table, provisioned IOPS).
                LOG.error("Cannot save checkpoint to the DynamoDB table used by the Amazon Kinesis Client Library.", e);
                break;
            }
            try {
                Thread.sleep(BACKOFF_TIME_IN_MILLIS);
            } catch (InterruptedException e) {
                LOG.debug("Interrupted sleep", e);
            }
        }
    }
1332635
void triggerCheckpoint(boolean uncompressed) throws IOException {
    String pref = "Standby: Checkpoint - ";
    LOG.info(pref + "triggering checkpoint manually");

    // check error conditions
    if (uncompressed) {
      throwIOException(pref + " uncompressed option not supported", null);
    }
    if (manualCheckpointLatch.getCount() > 0) {
      throwIOException(pref + "Another manual checkpoint is in progress", null);
    }
    
    // set the manual checkpoint latch
    manualCheckpointLatch = new CountDownLatch(2);
    lastCheckpointTime = delayedScheduledCheckpointTime = 0;
    try {
      manualCheckpointLatch.await();
    } catch (InterruptedException e) {
      throwIOException(pref + "interrupted when performing manual checkpoint",
          e);
    }
    
    // check if checkpoint succeeded
    if (checkpointFailures > 0) {
      throwIOException(pref + "manual checkpoint failed", null);
    }
    LOG.info(pref + "manual checkpoint done");
  }
340256
def restore_checkpoint(ckpt_dir, saver, sess, must_restore=False):
  """"""
  ckpt = tf.train.get_checkpoint_state(ckpt_dir)
  if must_restore and not ckpt:
    raise ValueError("No checkpoint found in %s" % ckpt_dir)
  if not ckpt:
    return 0

  path = ckpt.model_checkpoint_path
  tf.logging.info("Restoring checkpoint %s", path)
  saver.restore(sess, path)
  step = int(path.split("-")[-1])
  return step
1367318
def actor_checkpoint_info(self, actor_id):
        
        self._check_connected()
        message = self._execute_command(
            actor_id,
            "RAY.TABLE_LOOKUP",
            ray.gcs_utils.TablePrefix.ACTOR_CHECKPOINT_ID,
            "",
            actor_id.binary(),
        )
        if message is None:
            return None
        gcs_entry = ray.gcs_utils.GcsTableEntry.GetRootAsGcsTableEntry(
            message, 0)
        entry = (
            ray.gcs_utils.ActorCheckpointIdData.GetRootAsActorCheckpointIdData(
                gcs_entry.Entries(0), 0))
        checkpoint_ids_str = entry.CheckpointIds()
        num_checkpoints = len(checkpoint_ids_str) // ID_SIZE
        assert len(checkpoint_ids_str) % ID_SIZE == 0
        checkpoint_ids = [
            ray.ActorCheckpointID(
                checkpoint_ids_str[(i * ID_SIZE):((i + 1) * ID_SIZE)])
            for i in range(num_checkpoints)
        ]
        return {
            "ActorID": ray.utils.binary_to_hex(entry.ActorId()),
            "CheckpointIds": checkpoint_ids,
            "Timestamps": [
                entry.Timestamps(i) for i in range(num_checkpoints)
            ],
        }
681595
private void maybeCheckpoint() {
    if (mShutdownInitiated) {
      return;
    }
    long nextSequenceNumber = mJournalReader.getNextSequenceNumber();
    if (nextSequenceNumber - mNextSequenceNumberToCheckpoint < mCheckpointPeriodEntries) {
      return;
    }
    try {
      mNextSequenceNumberToCheckpoint = mJournal.getNextSequenceNumberToCheckpoint();
    } catch (IOException e) {
      LOG.warn("{}: Failed to get the next sequence number to checkpoint with error {}.",
          mMaster.getName(), e.getMessage());
      return;
    }
    if (nextSequenceNumber - mNextSequenceNumberToCheckpoint < mCheckpointPeriodEntries) {
      return;
    }

    writeCheckpoint(nextSequenceNumber);
  }
85059
CheckpointStatsHistory createSnapshot() {
		if (readOnly) {
			throw new UnsupportedOperationException("Can't create a snapshot of a read-only history.");
		}

		List<AbstractCheckpointStats> checkpointsHistory;
		Map<Long, AbstractCheckpointStats> checkpointsById;

		checkpointsById = new HashMap<>(checkpointsArray.length);

		if (maxSize == 0) {
			checkpointsHistory = Collections.emptyList();
		} else {
			AbstractCheckpointStats[] newCheckpointsArray = new AbstractCheckpointStats[checkpointsArray.length];

			System.arraycopy(checkpointsArray, nextPos, newCheckpointsArray, 0, checkpointsArray.length - nextPos);
			System.arraycopy(checkpointsArray, 0, newCheckpointsArray, checkpointsArray.length - nextPos, nextPos);

			checkpointsHistory = Arrays.asList(newCheckpointsArray);

			// reverse the order such that we start with the youngest checkpoint
			Collections.reverse(checkpointsHistory);

			for (AbstractCheckpointStats checkpoint : checkpointsHistory) {
				checkpointsById.put(checkpoint.getCheckpointId(), checkpoint);
			}
		}

		if (latestCompletedCheckpoint != null) {
			checkpointsById.put(latestCompletedCheckpoint.getCheckpointId(), latestCompletedCheckpoint);
		}

		if (latestFailedCheckpoint != null) {
			checkpointsById.put(latestFailedCheckpoint.getCheckpointId(), latestFailedCheckpoint);
		}

		if (latestSavepoint != null) {
			checkpointsById.put(latestSavepoint.getCheckpointId(), latestSavepoint);
		}

		return new CheckpointStatsHistory(
			true,
			maxSize,
			null,
			checkpointsHistory,
			checkpointsById,
			latestCompletedCheckpoint,
			latestFailedCheckpoint,
			latestSavepoint);
	}