Should we store current checkpoint as the best
495213
def should_store_best_checkpoint(self, epoch_idx, metrics) -> bool:
        
        if not self.store_best:
            return False

        metric = metrics[self.metric]

        if better(self._current_best_metric_value, metric, self.metric_mode):
            self._current_best_metric_value = metric
            return True

        return False
1362086
private void checkOthers(Collidable objectA, Entry<Point, Set<Collidable>> current, Integer acceptedGroup)
    {
        final Map<Point, Set<Collidable>> acceptedElements = collidables.get(acceptedGroup);
        final Point point = current.getKey();
        if (acceptedElements.containsKey(point))
        {
            checkPoint(objectA, acceptedElements, point);
        }
    }
156762
public void checkpointStart()
  {
    if (_isWhileCheckpoint) {
      throw new IllegalStateException();
    }
    
    _isWhileCheckpoint = true;
    
    long sequence = ++_sequence;
    
    setSequence(sequence);
    
    byte []headerBuffer = _headerBuffer;
    BitsUtil.writeInt16(headerBuffer, 0, CHECKPOINT_START);
    writeImpl(headerBuffer, 0, 2);
    
    _lastCheckpointStart = _index - _startAddress;
  }
33901
@Override
	public void trackCheckpoint(String startToken, String checkpointToken) {
	    tokenMap.put(startToken, checkpointToken);
	}
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);
            }
        }
    }
71265
@Override
  public void checkpoint(Result<Boolean> result)
  {
    if (! _journalStream.saveStart()) {
      result.ok(true);
      return;
    }

    TableWriterService readWrite = _table.getReadWrite();
    
    // long limit = Integer.MAX_VALUE; // 128
    int tailPid = _tailPid.get();
    for (int pid = 1; pid <= tailPid; pid++) {
      Page page = _pages.get(pid);

      if (page != null) {
        page.write(_table, this, readWrite);
      }
    }

    readWrite.fsync(new CheckpointResult(result));
  }
1017417
private KeyValueState<String, CheckPointState> loadCheckpointState(Map conf, TopologyContext ctx) {
        String namespace = ctx.getThisComponentId() + "-" + ctx.getThisTaskId();
        KeyValueState<String, CheckPointState> state =
                (KeyValueState<String, CheckPointState>) StateFactory.getState(namespace, conf, ctx);
        if (state.get(TX_STATE_KEY) == null) {
            CheckPointState txState = new CheckPointState(-1, CheckPointState.State.COMMITTED);
            state.put(TX_STATE_KEY, txState);
            state.commit();
            LOG.debug("Initialized checkpoint spout state with txState {}", txState);
        } else {
            LOG.debug("Got checkpoint spout state {}", state.get(TX_STATE_KEY));
        }
        return state;
    }
1198267
def backtrack_or_continue
      best = nil
      if (@iterations_since_best / @backtracks) >= @backtrack_cutoff * @max_hood_size
        self.backtrack
        best = @best
      else
        best = @current_hood.best
        self.adjust_distributions_using_gradient
      end
      if best[:parameters].nil?
        # this should never happen!
        best = @best
      end
      best
    end
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;
	}
1133039
protected final void waitForCheckpoint(boolean persistent)
                    throws ObjectManagerException
    {
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this,
                        cclass,
                        "waitForCheckpoint");

        checkpointHelper.waitForCheckpoint(persistent);

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this,
                       cclass,
                       "waitForCheckpoint",
                       "persistent=" + persistent + "(boolean)");
    }
1316642
void doImportCheckpoint() throws IOException {
    Collection<URI> checkpointDirs =
      NNStorageConfiguration.getCheckpointDirs(conf, null);
    Collection<URI> checkpointEditsDirs =
        NNStorageConfiguration.getCheckpointEditsDirs(conf, null);

    if (checkpointDirs == null || checkpointDirs.isEmpty()) {
      throw new IOException("Cannot import image from a checkpoint. "
                            + "\"dfs.namenode.checkpoint.dir\" is not set." );
    }
    
    if (checkpointEditsDirs == null || checkpointEditsDirs.isEmpty()) {
      throw new IOException("Cannot import image from a checkpoint. "
                            + "\"dfs.namenode.checkpoint.dir\" is not set." );
    }

    // replace real image with the checkpoint image
    FSImage realImage = namesystem.getFSImage();
    assert realImage == this;
    FSImage ckptImage = new FSImage(conf,
                                    checkpointDirs, checkpointEditsDirs, null);
    ckptImage.setFSNamesystem(namesystem);
    namesystem.dir.fsImage = ckptImage;
    // load from the checkpoint dirs
    try {
      ckptImage.recoverTransitionRead(StartupOption.REGULAR);
    } finally {
      ckptImage.close();
    }
    // return back the real image
    realImage.storage.setStorageInfo(ckptImage.storage);
    realImage.getEditLog().setLastWrittenTxId(ckptImage.getEditLog().getLastWrittenTxId() + 1);

    namesystem.dir.fsImage = realImage;

    // and save it but keep the same checkpointTime
    // parameters
    saveNamespace();
  }
410180
@Override
	public CheckpointData getCheckpointData(CheckpointDataKey key) {
		logger.entering(CLASSNAME, "getCheckpointData", key==null ? "<null>" : key);
		CheckpointData checkpointData = queryCheckpointData(key.getCommaSeparatedKey());
		logger.exiting(CLASSNAME, "getCheckpointData", checkpointData==null ? "<null>" : checkpointData);
		return checkpointData;
	}
1084807
public void checkpoint(ObjectEnvelope mod) throws PersistenceBrokerException
    {
        mod.doInsert();
        mod.setModificationState(StateOldClean.getInstance());
    }
1294572
def checkpoint(self):
        """"""
        # thin and write new samples
        for fn in [self.checkpoint_file, self.backup_file]:
            with self.io(fn, "a") as fp:
                # write the current number of iterations
                fp.write_niterations(self.niterations)
                thin_interval = self.get_thin_interval()
                # thin samples on disk if it changed
                if thin_interval > 1:
                    # if this is the first time writing, set the file's
                    # thinned_by
                    if fp.last_iteration() == 0:
                        fp.thinned_by = thin_interval
                    else:
                        # check if we need to thin the current samples on disk
                        thin_by = thin_interval // fp.thinned_by
                        if thin_by > 1:
                            logging.info("Thinning samples in %s by a factor "
                                         "of %i", fn, int(thin_by))
                            fp.thin(thin_by)
                fp_lastiter = fp.last_iteration()
            logging.info("Writing samples to %s with thin interval %i", fn,
                         thin_interval)
            self.write_results(fn)
        # see if we had anything to write after thinning; if not, don't try
        # to compute anything
        with self.io(self.checkpoint_file, "r") as fp:
            nsamples_written = fp.last_iteration() - fp_lastiter
        if nsamples_written == 0:
            logging.info("No samples written due to thinning")
        else:
            # check for burn in, compute the acls
            self.acls = None
            if self.burn_in is not None:
                logging.info("Updating burn in")
                self.burn_in.evaluate(self.checkpoint_file)
                burn_in_index = self.burn_in.burn_in_index
                logging.info("Is burned in: %r", self.burn_in.is_burned_in)
                if self.burn_in.is_burned_in:
                    logging.info("Burn-in iteration: %i",
                                 int(self.burn_in.burn_in_iteration))
            else:
                burn_in_index = 0
            # Compute acls; the burn_in test may have calculated an acl and
            # saved it, in which case we don't need to do it again.
            if self.acls is None:
                logging.info("Computing acls")
                self.acls = self.compute_acl(self.checkpoint_file,
                                             start_index=burn_in_index)
            logging.info("ACT: %s", str(numpy.array(self.acts.values()).max()))
            # write
            for fn in [self.checkpoint_file, self.backup_file]:
                with self.io(fn, "a") as fp:
                    if self.burn_in is not None:
                        fp.write_burn_in(self.burn_in)
                    if self.acls is not None:
                        fp.write_acls(self.acls)
                    # write effective number of samples
                    fp.write_effective_nsamples(self.effective_nsamples)
        # check validity
        logging.info("Validating checkpoint and backup files")
        checkpoint_valid = validate_checkpoint_files(
            self.checkpoint_file, self.backup_file)
        if not checkpoint_valid:
            raise IOError("error writing to checkpoint file")
        elif self.checkpoint_signal:
            # kill myself with the specified signal
            logging.info("Exiting with SIG{}".format(self.checkpoint_signal))
            kill_cmd="os.kill(os.getpid(), signal.SIG{})".format(
                self.checkpoint_signal)
            exec(kill_cmd)
        # clear the in-memory chain to save memory
        logging.info("Clearing samples from memory")
        self.clear_samples()
924057
private function storeCurrentItem() : void
    {
        $key = $this->iterator->key();

        if ($key === null) {
            return;
        }

        $this->items[$key] = $this->iterator->current();
    }
786139
protected final void suggestCheckpoint(boolean persistent)
                    throws ObjectManagerException
    {
        if (trace.isEntryEnabled())
            trace.entry(this,
                        cclass,
                        "suggestCheckpoint",
                        new Object[] { new Boolean(persistent) });

        // During restart checkpointHelper is not running so don't suggest a checkpoint.
        // A checkpoint is forced at startup once it is safe to do so.
        if (checkpointHelper != null)
            checkpointHelper.suggestCheckpoint(persistent);

        if (trace.isEntryEnabled())
            trace.exit(this,
                       cclass,
                       "suggestCheckpoint");
    }
315256
def should_recover(self):
        
        return (self.checkpoint_freq > 0
                and (self.num_failures < self.max_failures
                     or self.max_failures < 0))