Check that the logs are contiguous and non-overlapping
sequences of transactions, in sorted order
@throws IllegalStateException if incorrect
494183
private void checkState()  {
    Preconditions.checkNotNull(logs);
    if (!contiguous)
      return;
    RemoteEditLog prev = null;
    for (RemoteEditLog log : logs) {
      if (prev != null) {
        if (log.getStartTxId() <= prev.getEndTxId()) {
          throw new IllegalStateException("Invalid log manifest:" + this);
        }
      }
      
      prev = log;
    }
  }
906806
CommitLogSegment allocatingFrom()
    {
        CommitLogSegment r = allocatingFrom;
        if (r == null)
        {
            advanceAllocatingFrom(null);
            r = allocatingFrom;
        }
        return r;
    }
344820
@Override
    public long getLowestUncommittedSequenceNumber() {
        StorageOperation first = this.operations.getFirst();
        return first == null ? Operation.NO_SEQUENCE_NUMBER : first.getSequenceNumber();
    }
880574
private boolean setPrevious(byte[] sequence, int start, int length) {
    if (previous == null || previous.length < length) {
      previous = new byte[length];
    }

    System.arraycopy(sequence, start, previous, 0, length);
    previousLength = length;
    return true;
  }
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;
  }
1264313
public void applyLogEntries() {
        // Reject logs we've applied already
        long commitIndex = state.commitIndex();
        long lastApplied = state.lastApplied();

        if (commitIndex == lastApplied) {
            return;
        }

        // If commitIndex > lastApplied: increment lastApplied, apply log[lastApplied] to state machine (§5.3)
        assert commitIndex > lastApplied
                : "commit index: " + commitIndex + " cannot be smaller than last applied: " + lastApplied;

        // Apply all the preceding logs
        RaftLog raftLog = state.log();
        for (long idx = state.lastApplied() + 1; idx <= commitIndex; idx++) {
            LogEntry entry = raftLog.getLogEntry(idx);
            if (entry == null) {
                String msg = "Failed to get log entry at index: " + idx;
                logger.severe(msg);
                throw new AssertionError(msg);
            }

            applyLogEntry(entry);

            // Update the lastApplied index
            state.lastApplied(idx);
        }

        assert status != TERMINATED || commitIndex == raftLog.lastLogOrSnapshotIndex()
                : "commit index: " + commitIndex + " must be equal to " + raftLog.lastLogOrSnapshotIndex() + " on termination.";

        if (state.role() == LEADER || state.role() == FOLLOWER) {
            takeSnapshotIfCommitIndexAdvanced();
        }
    }
544348
@Override
    public boolean isOrderDeterministic() {
        if ( ! super.isOrderDeterministic()) {
            return false;
        }
        IndexScanPlanNode index_scan = getInlineIndexScan();
        if ( ! index_scan.isOrderDeterministic()) {
            m_nondeterminismDetail = index_scan.m_nondeterminismDetail;
            return false;
        }
        return true;
    }
257423
private void validateSegments(List<LogSegment> segments) {
        synchronized (lock) {
            for (int i = 0; i < segments.size() - 1; i++) {
                LogSegment curr = segments.get(i);
                LogSegment next = segments.get(i + 1);
                if (curr.start() + curr.size() != next.start()) {
                    throw new IllegalStateException("The following segments don't validate: " + curr.getFile()
                            .getAbsolutePath() + ", " + next.getFile().getAbsolutePath());
                }
            }
        }
    }
638037
private void checkProgress() throws IOException {
    if (now() - mostRecentlyReadTransactionTime > nothingReadCheckTimeout) {
      // check the journal manager
      detectJournalManager();
      
      // we haven't read anything in a while
      if (segmentExists(mostRecentlyReadTransactionTxId + 1) &&
          mostRecentlyReadTransactionTxId != -1) {
        // unclean shutdown happened, we need to switch to next segment
        currentSegmentTxId = mostRecentlyReadTransactionTxId + 1;
        // indicate that we will reopen new stream
        currentEditLogInputStreamPosition = -1;
        
        LOG.warn("Segment - switching to new log segment with txid: "
            + currentSegmentTxId + ". Previous segment was not closed cleanly.");
      } else {
        LOG.warn("Segment - will reopen segment with txid: "
            + currentSegmentTxId + " at position: "
            + currentEditLogInputStreamPosition);
      }
      // in both cases we want to reopen the stream
      currentEditLogInputStream = null;
    }
  }
625249
@Override
    public void rollLogs() {
        summaryFile = null;

        List<IncidentImpl> incidentCopies;
        synchronized (incidents) {
            incidentCopies = new ArrayList<IncidentImpl>(incidents.values());
        }

        int overage = incidentCopies.size() - 500;
        if (overage > 0) {
            // we have more than 500 incidents: we need to remove least-recently-seen
            // incidents until we're back to 500. We do this daily to prevent unchecked growth
            // in the number of incidents we remember
            List<IncidentImpl> lastSeenIncidents = new ArrayList<IncidentImpl>(incidentCopies);

            // sort the incidents by when they were last seen, rather than when they were added
            Collections.sort(lastSeenIncidents, new Comparator<IncidentImpl>() {
                @Override
                public int compare(IncidentImpl o1, IncidentImpl o2) {
                    // static method on double does the same as Long.compareTo, and we avoid
                    // object allocation or auto-boxing, etc.
                    return Double.compare(o1.getTimeStamp(), o2.getTimeStamp());
                }
            });

            // For each item we're over 500, remove one from the front of the list (least recently seen)
            synchronized (incidents) {
                for (Iterator<IncidentImpl> i = lastSeenIncidents.iterator(); i.hasNext() && overage > 0; overage--) {
                    IncidentImpl impl = i.next();
                    i.remove();

                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "FFDC cleanup -- removing " + impl.key);
                    }
                    // remove the incident from the map, and clean it up (remove the associated files)
                    incidents.remove(impl.key);
                    impl.cleanup();
                }
            }
        }

        for (IncidentImpl incident : incidentCopies) {
            incident.roll();
        }

        logSummary(incidentCopies);
    }
793410
private static BitSet calculateFullStackTraceRequirements(final Collection<LogEntryValue>[][] logEntryValues) {
		BitSet result = new BitSet(logEntryValues.length);
		for (int i = 0; i < logEntryValues.length; ++i) {
			Collection<LogEntryValue> values = logEntryValues[i][Level.ERROR.ordinal()];
			if (values.contains(LogEntryValue.METHOD) || values.contains(LogEntryValue.FILE) || values.contains(LogEntryValue.LINE)) {
				result.set(i);
			}
		}
		return result;
	}
548646
@CanIgnoreReturnValue
  public Ordered containsExactly() {
    return check().about(iterableEntries()).that(actual().entries()).containsExactly();
  }
1246257
private boolean isRecordAlreadyRead(
      final PartitionIdType recordPartition,
      final SequenceOffsetType recordSequenceNumber
  )
  {
    final SequenceOffsetType lastReadOffset = lastReadOffsets.get(recordPartition);

    if (lastReadOffset == null) {
      return false;
    } else {
      return createSequenceNumber(recordSequenceNumber).compareTo(createSequenceNumber(lastReadOffset)) <= 0;
    }
  }
647606
public boolean hasNext() {
        if(_rs == null)
            return false;

        if(_primed)
            return true;

        try {
            _primed = _rs.next();
            return _primed;
        }
        catch(SQLException sql) {
            String msg = "An exception occurred reading from the Iterator.  Cause: " + sql;
            LOGGER.error(msg, sql);
            throw new IllegalStateException(msg, sql);
        }
    }
441335
protected boolean checkNextIndexOffset() {
		if (this.currentSortIndexOffset > this.lastIndexEntryOffset) {
			MemorySegment returnSegment = nextMemorySegment();
			if (returnSegment != null) {
				this.currentSortIndexSegment = returnSegment;
				this.sortIndex.add(this.currentSortIndexSegment);
				this.currentSortIndexOffset = 0;
			} else {
				return false;
			}
		}
		return true;
	}
357691
private boolean toBoundedPrevious() throws FetchException {
        if (!toPrevious()) {
            return false;
        }

        if (mStartBound != null) {
            byte[] currentKey = getCurrentKey();
            if (currentKey == null) {
                return false;
            }
            int result = compareKeysPartially(currentKey, mStartBound);
            if (result <= 0) {
                if (result < 0 || !mInclusiveStart) {
                    // Too far now, reset to first.
                    toBoundedFirst();
                    return false;
                }
            }
        }

        return prefixMatches();
    }
529036
protected synchronized void checkpoint(long forcedLogSequenceNumber)
                    throws ObjectManagerException
    {
        throw new InvalidStateException(this, InternalTransaction.stateTerminated, InternalTransaction.stateNames[InternalTransaction.stateTerminated]);
    }