private void processScheduledQueryPolicies(ScheduledQueryProgressInfo info) throws MetaException {
    if (info.getState() != QueryState.FAILED && info.getState() != QueryState.TIMED_OUT) {
      return;
    }
    int autoDisableCount = MetastoreConf.getIntVar(conf, ConfVars.SCHEDULED_QUERIES_AUTODISABLE_COUNT);
    int skipCount = MetastoreConf.getIntVar(conf, ConfVars.SCHEDULED_QUERIES_SKIP_OPPORTUNITIES_AFTER_FAILURES);

    int lastN = Math.max(autoDisableCount, skipCount);
    if (lastN <= 0) {
      // disabled
      return;
    }

    boolean commited = false;
    Query query = null;
    try {
      openTransaction();

      MScheduledExecution lastExecution = pm.getObjectById(MScheduledExecution.class, info.getScheduledExecutionId());
      MScheduledQuery schq = lastExecution.getScheduledQuery();

      query = pm.newQuery(MScheduledExecution.class);
      query.setFilter("scheduledQuery == currentSchedule");
      query.setOrdering("scheduledExecutionId descending");
      query.declareParameters("MScheduledQuery currentSchedule");
      query.setRange(0, lastN);
      List<MScheduledExecution> list = (List<MScheduledExecution>) query.execute(schq);

      int failureCount=0;
      for(int i=0;i<list.size();i++) {
        if (list.get(i).getState() != QueryState.FAILED && list.get(i).getState() != QueryState.TIMED_OUT) {
          break;
        }
        failureCount++;
      }

      if (autoDisableCount > 0 && autoDisableCount <= failureCount) {
        LOG.info("Disabling {} after {} consequtive failures", schq.getScheduleKey(), autoDisableCount);
        schq.setEnabled(false);
        int now = (int) (System.currentTimeMillis() / 1000);
        MScheduledExecution execution = new MScheduledExecution();
        execution.setScheduledQuery(schq);
        execution.setState(QueryState.AUTO_DISABLED);
        execution.setStartTime(now);
        execution.setEndTime(now);
        execution.setLastUpdateTime(now);
        execution.setErrorMessage(String.format("Disabling query after {} consequtive failures", autoDisableCount));
        pm.makePersistent(execution);
      }
      if (skipCount > 0) {
        int n = Math.min(skipCount, failureCount) - 1;
        Integer scheduledTime = schq.getNextExecution();
        for (int i = 0; i < n; i++) {
          if (scheduledTime != null) {
            scheduledTime = computeNextExecutionTime(schq.getSchedule(), scheduledTime);
          }
        }
        if (scheduledTime != null) {
          schq.setNextExecution(scheduledTime);
        }
      }
      commited = commitTransaction();
    } catch (InvalidInputException e) {
      throw new MetaException("Unexpected InvalidInputException: " + e.getMessage());
    } finally {
      rollbackAndCleanup(commited, query);
    }
  }
Return true if the current statistics in the Metastore is valid
for the query of the given "txnId" and "queryValidWriteIdList".

Note that a statistics entity is valid iff
the stats is written by the current query or
the conjunction of the following two are true:
~ COLUMN_STATE_ACCURATE(CSA) state is true
~ Isolation-level (snapshot) compliant with the query
@param part                   MPartition of the stats entity
@param queryValidWriteIdList  valid writeId list of the query
@Precondition   "part" should be retrieved from the PARTITIONS table.
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java