code: protected boolean updateTermAndLeader(long term, int leader) {
      // If the request indicates a term that is greater than the current term or no leader has been
      // set for the current term, update leader and term.
      if (term > context.getTerm() || (term == context.getTerm() && context.getLeader() == null && leader != 0)) {
        context.setTerm(term);
        context.setLeader(leader);
  
        // Reset the current cluster configuration to the last committed configuration when a leader change occurs.
        context.getClusterState().reset();
        return true;
      }
      return false;
    }
docs: Updates the term and leader.