code: private OperationResult applyCommand(Indexed<CommandEntry> entry) {
      // First check to ensure that the session exists.
      RaftSession session = raft.getSessions().getSession(entry.entry().session());
  
      // If the session is null, return an UnknownSessionException. Commands applied to the state machine must
      // have a session. We ensure that session register/unregister entries are not compacted from the log
      // until all associated commands have been cleaned.
      // Note that it's possible for a session to be unknown if a later snapshot has been taken, so we don't want
      // to log warnings here.
      if (session == null) {
        logger.debug("Unknown session: " + entry.entry().session());
        throw new RaftException.UnknownSession("unknown session: " + entry.entry().session());
      }
  
      // Increment the load counter to avoid snapshotting under high load.
      raft.getLoadMonitor().recordEvent();
  
      // Execute the command using the state machine associated with the session.
      return session.getService()
          .executeCommand(
              entry.index(),
              entry.entry().sequenceNumber(),
              entry.entry().timestamp(),
              session,
              entry.entry().operation());
    }
docs: Applies a command entry to the state machine.
  <p>
  Command entries result in commands being executed on the user provided {@link PrimitiveService} and a response
  being sent back to the client by completing the returned future. All command responses are cached in the command's
  {@link RaftSession} for fault tolerance. In the event that the same command is applied to the state machine more
  than once, the original response will be returned.
  <p>
  Command entries are written with a sequence number. The sequence number is used to ensure that commands are applied
  to the state machine in sequential order. If a command entry has a sequence number that is less than the next
  sequence number for the session, that indicates that it is a duplicate of a command that was already applied.
  Otherwise, commands are assumed to have been received in sequential order. The reason for this assumption is
  because leaders always sequence commands as they're written to the log, so no sequence number will be skipped.