@VisibleForTesting
  public boolean runOneWorkerIteration(
      SessionState ss, String user, HiveConf conf, boolean doWait) throws InterruptedException {
    AnalyzeWork req;
    if (doWait) {
      req = workQueue.take();
    } else {
      req = workQueue.poll();
      if (req == null) {
        return false;
      }
    }
    String cmd = null;
    try {
      if (doWait) {
        SessionState.start(ss); // This is the first call, open the session
      }
      TableName tb = req.tableName;
      if (MetaStoreUtils.isDbBeingPlannedFailedOver(rs.getDatabase(tb.getCat(), tb.getDb()))) {
        LOG.info("Skipping table: {} as it belongs to database which is being failed over." + tb.getTable());
        return true;
      }
      cmd = req.buildCommand();
      LOG.debug("Running {} based on {}", cmd, req);
      DriverUtils.runOnDriver(conf, ss, cmd);
    } catch (Exception e) {
      LOG.error("Analyze command failed: " + cmd, e);
      try {
        ss.close();
      } catch (IOException e1) {
        LOG.warn("Failed to close a bad session", e1);
      } finally {
        SessionState.detachSession();
      }
    } finally {
      markAnalyzeDone(req);
    }
    return true;
  }
Whether to only update stats that already exist and are out of date.
ql/src/java/org/apache/hadoop/hive/ql/stats/StatsUpdaterThread.java