@Override
  public void tryBeLeader(Configuration conf, String hostName)
      throws LeaderException {
    String leaderHost = MetastoreConf.getVar(conf,
        MetastoreConf.ConfVars.METASTORE_HOUSEKEEPING_LEADER_HOSTNAME);
    this.enforceMutex = conf.getBoolean(HIVE_TXN_ENFORCE_AUX_MUTEX, true);
    // For the sake of backward compatibility, when the current HMS becomes the leader when no
    // leader is specified.
    if (leaderHost == null || leaderHost.isEmpty()) {
      LOG.info(MetastoreConf.ConfVars.METASTORE_HOUSEKEEPING_LEADER_HOSTNAME + " is empty. Start all the " +
          "housekeeping threads.");
      isLeader = true;
    } else {
      LOG.info(MetastoreConf.ConfVars.METASTORE_HOUSEKEEPING_LEADER_HOSTNAME + " is set to " + leaderHost);
      isLeader = leaderHost.trim().equals(hostName);
    }

    if (isLeader) {
      listeners.forEach(listener -> {
        try {
          listener.takeLeadership(this);
        } catch (Exception e) {
          LOG.warn("Error while notifying the listener: " + listener, e);
        }
      });
    }
  }
URL based leader election via metastore.housekeeping.leader.hostname.
If the value is empty, means no election happening and all instances are leaders,
otherwise the instance matching the configured hostname will be selected as a leader.
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/leader/StaticLeaderElection.java