code: protected AppendResponse appendEntries(AppendRequest request) {
      // Get the last entry index or default to the request log index.
      long lastEntryIndex = request.logIndex();
      if (!request.entries().isEmpty()) {
        lastEntryIndex = request.entries().get(request.entries().size() - 1).getIndex();
      }
  
      // Ensure the commitIndex is not increased beyond the index of the last entry in the request.
      long commitIndex = Math.max(context.getCommitIndex(), Math.min(request.commitIndex(), lastEntryIndex));
  
      // Append entries to the log starting at the last log index.
      for (Entry entry : request.entries()) {
        // If the entry index is greater than the last index and less than the commit index, append the entry.
        // We perform no additional consistency checks here since passive members may only receive committed entries.
        if (context.getLog().lastIndex() < entry.getIndex() && entry.getIndex() <= commitIndex) {
          context.getLog().skip(entry.getIndex() - context.getLog().lastIndex() - 1).append(entry);
          LOGGER.trace("{} - Appended {} to log at index {}", context.getCluster().member().address(), entry, entry.getIndex());
        }
      }
  
      // Update the context commit and global indices.
      long previousCommitIndex = context.getCommitIndex();
      context.setCommitIndex(commitIndex);
      context.setGlobalIndex(request.globalIndex());
  
      if (context.getCommitIndex() > previousCommitIndex) {
        LOGGER.trace("{} - Committed entries up to index {}", context.getCluster().member().address(), commitIndex);
      }
  
      // Apply commits to the state machine in batch.
      context.getStateMachine().applyAll(context.getCommitIndex());
  
      return AppendResponse.builder()
        .withStatus(Response.Status.OK)
        .withTerm(context.getTerm())
        .withSucceeded(true)
        .withLogIndex(context.getLog().lastIndex())
        .build();
    }
docs: Appends entries to the local log.