コード例 #1
0
  @Override
  public boolean submit(
      QueryExecution queryExecution, Executor executor, SqlQueryManagerStats stats) {
    List<QueryQueue> queues = selectQueues(queryExecution.getQueryInfo().getSession(), executor);

    for (QueryQueue queue : queues) {
      if (!queue.reserve(queryExecution)) {
        // Reject query if we couldn't acquire a permit to enter the queue.
        // The permits will be released when this query fails.
        return false;
      }
    }

    return queues
        .get(0)
        .enqueue(
            createQueuedExecution(
                queryExecution, queues.subList(1, queues.size()), executor, stats));
  }
コード例 #2
0
 public void executeQueue(int timeoutMillis) {
   if (memoryHog == null) memoryHog = new byte[64 * 1024]; // 64K should be enough for everyone
   memoryHog[0] = 42;
   long start = System.currentTimeMillis();
   long fin = (timeoutMillis <= 0 ? -1 : System.currentTimeMillis() + timeoutMillis);
   GoalState current;
   int loopNo = 0;
   while ((current = queue.poll()) != null) {
     //           System.out.println("RUNNING " + current);
     if (loopNo++ == 50) {
       loopNo = 0;
       long freeMemory = computeFreeMemory();
       if (freeMemory < 20 * 1024 * 1024) {
         Runtime.getRuntime().gc();
         freeMemory = computeFreeMemory();
         if (freeMemory < 40 * 1024 * 1024) {
           timeLimitReached();
           break;
         }
       }
     }
     try {
       current.run();
     } catch (RuntimeException e) {
       Bugs.bug(new GoalEvaluationFailed(e, current.goal));
       current.setPruned();
     } catch (AssertionError e) {
       Bugs.bug(new GoalEvaluationFailed(e, current.goal));
       current.setPruned();
     } catch (OutOfMemoryError e) {
       memoryHog = null;
       Runtime.getRuntime().gc();
       Bugs.bug(e);
       timeLimitReached();
       break;
     }
     if (fin > 0 && System.currentTimeMillis() > fin) {
       timeLimitReached();
       break;
     }
   }
   if (unfinishedGoals > 0) System.err.println("ACHTUNG UNFINISHED GOALS ATTACK!!!!!");
   else if (unfinishedGoals < 0) System.err.println("F**K F**K F**K");
   stats.queueRunDone(System.currentTimeMillis() - start);
   //        if (runTimes != null)
   //            runTimes.add(duration);
 }
コード例 #3
0
  @SuppressWarnings("unchecked")
  public <R extends Result> R evaluate(Goal<R> goal, int timeoutMillis) {
    long start = System.currentTimeMillis();
    try {
      queue.clear();
      totalGoals = 0;
      if (unfinishedGoals > 0) System.err.println("unfinishedGoals was > 0");
      unfinishedGoals = 0;
      activeGoalStates.clear();
      toBeDone.clear();
      leaves.clear();
      Result cachedResult = lookupResultInCache(goal, null);
      if (cachedResult != null) {
        stats.cacheHit(goal);
        stats.rootGoalDone(System.currentTimeMillis() - start);
        return (R) cachedResult;
      }
      GoalState state = lookupGoalState(goal);
      executeQueue(timeoutMillis);

      if (unfinishedGoals > 0)
        throw new SomeGoalsNotFinalized()
            .add("unfinished_goals", unfinishedGoals)
            .add("root_goal", goal);
      else if (unfinishedGoals < 0) throw new AssertionError("F**K F**K F**K");
      return (R) state.slot.result();
    } finally {
      stats.rootGoalDone(System.currentTimeMillis() - start);
      //            System.out.println(rootGoalCount + " root goals, executeQueue() " +
      // timeSpentInExecuteQueue
      //                    + ", run() " + timeSpentInRun + ", evaluate() " + timeSpentInEvaluate
      //                    + " including cached " + timeSpentInEvaluateCached + " (in " +
      // cachedRootGoalCount
      //                    + " cached root goals)");
    }
  }
コード例 #4
0
 private void timeLimitReached() {
   System.out.println(" *** ANALYSIS TIMEOUT *** ");
   GoalState current;
   while ((current = queue.poll()) != null) prune(current);
 }
コード例 #5
0
 public void execute(Runnable command) {
   queue.enqueue((GoalState) command);
 }