code: @Override
      public HiveMetastoreClient createMetastoreClient()
              throws TException
      {
          List<HostAndPort> metastores = new ArrayList<>(addresses);
          Collections.shuffle(metastores.subList(1, metastores.size()));
  
          TException lastException = null;
          for (HostAndPort metastore : metastores) {
              try {
                  HiveMetastoreClient client = clientFactory.create(metastore);
                  if (!isNullOrEmpty(metastoreUsername)) {
                      client.setUGI(metastoreUsername);
                  }
                  return client;
              }
              catch (TException e) {
                  lastException = e;
              }
          }
          throw new TException("Failed connecting to Hive metastore: " + addresses, lastException);
      }
docs: Create a metastore client connected to the Hive metastore.
  <p>
  As per Hive HA metastore behavior, return the first metastore in the list
  list of available metastores (i.e. the default metastore) if a connection
  can be made, else try another of the metastores at random, until either a
  connection succeeds or there are no more fallback metastores.