code: protected AppendResponse checkGlobalIndex(AppendRequest request) {
      // If the globalIndex has changed and is not present in the local log, truncate the log.
      // This ensures that if major compaction progressed on any server beyond the entries in this
      // server's log that this server receives all entries after compaction.
      // If the current global index is 0 then do not perform the index check. This ensures that
      // servers don't truncate their logs at startup.
      // Ensure that the globalIndex is updated here to prevent endlessly truncating the log
      // if the AppendRequest is rejected.
      long currentGlobalIndex = context.getGlobalIndex();
      long nextGlobalIndex = request.globalIndex();
      if (currentGlobalIndex > 0 && nextGlobalIndex > currentGlobalIndex && nextGlobalIndex > context.getLog().lastIndex()) {
        context.setGlobalIndex(nextGlobalIndex);
        context.reset();
      }
  
      // If an entry was provided, check the entry against the local log.
      if (request.logIndex() != 0) {
        return checkPreviousEntry(request);
      } else {
        return appendEntries(request);
      }
    }
docs: Checks whether the log needs to be truncated based on the globalIndex.