コード例 #1
0
  def _wait_until_fetchable(self, cursor, report, timeout_unix_time, should_cancel):
    """Wait up until timeout_unix_time until the query results can be fetched (if it's
    a SELECT query) or until it has finished executing (if it's a different query type
    like DML). If the timeout expires we either cancel the query or report the timeout.
    Return True in the first case or False in the second (timeout) case."""
    # Loop until the query gets to the right state or a timeout expires.
    sleep_secs = 0.1
    secs_since_log = 0
    # True if we incremented num_queries_started_running_or_cancelled for this query.
    started_running_or_cancelled = False
    while True:
      query_state = cursor.status()
      # Check if the query got past the PENDING/INITIALIZED states, either because
      # it's executing or hit an error.
      if (not started_running_or_cancelled and query_state not in ('PENDING_STATE',
                                                      'INITIALIZED_STATE')):
        started_running_or_cancelled = True
        increment(self._metrics[NUM_QUERIES_STARTED_RUNNING_OR_CANCELLED])
      # Return if we're ready to fetch results (in the FINISHED state) or we are in
      # another terminal state like EXCEPTION.
      if query_state not in ('PENDING_STATE', 'INITIALIZED_STATE', 'RUNNING_STATE'):
        return True

      if time() > timeout_unix_time:
        if not should_cancel:
          fetch_and_set_profile(cursor, report)
        self._cancel(cursor, report)
        if not started_running_or_cancelled:
          increment(self._metrics[NUM_QUERIES_STARTED_RUNNING_OR_CANCELLED])
        return False
      if secs_since_log > 5:
        secs_since_log = 0
        LOG.debug("Waiting for query to execute")
      sleep(sleep_secs)
      secs_since_log += sleep_secs
コード例 #2
0
  def _wait_until_fetchable(self, cursor, report, timeout_unix_time):
    """Wait up until timeout_unix_time until the query results can be fetched (if it's
    a SELECT query) or until it has finished executing (if it's a different query type
    like DML). If the timeout expires raises a QueryTimeout exception."""
    # Loop until the query gets to the right state or a timeout expires.
    sleep_secs = 0.1
    secs_since_log = 0
    # True if we incremented num_queries_started_running_or_cancelled for this query.
    started_running_or_cancelled = False
    while True:
      query_state = cursor.status()
      # Check if the query got past the PENDING/INITIALIZED states, either because
      # it's executing or hit an error.
      if (not started_running_or_cancelled and query_state not in ('PENDING_STATE',
                                                      'INITIALIZED_STATE')):
        started_running_or_cancelled = True
        increment(self._metrics[NUM_QUERIES_STARTED_RUNNING_OR_CANCELLED])
      # Return if we're ready to fetch results (in the FINISHED state) or we are in
      # another terminal state like EXCEPTION.
      if query_state not in ('PENDING_STATE', 'INITIALIZED_STATE', 'RUNNING_STATE'):
        return

      if time() > timeout_unix_time:
        if not started_running_or_cancelled:
          increment(self._metrics[NUM_QUERIES_STARTED_RUNNING_OR_CANCELLED])
        raise QueryTimeout()
      if secs_since_log > 5:
        secs_since_log = 0
        LOG.debug("Waiting for query to execute")
      sleep(sleep_secs)
      secs_since_log += sleep_secs
コード例 #3
0
 def update_from_query_report(self, report):
   LOG.debug("Updating runtime stats (Query Runner PID: {0})".format(self.proc.pid))
   increment(self._metrics[NUM_QUERIES_FINISHED])
   if report.not_enough_memory:
     increment(self._metrics[NUM_QUERIES_EXCEEDED_MEM_LIMIT])
   if report.ac_rejected:
     increment(self._metrics[NUM_QUERIES_AC_REJECTED])
   if report.ac_timedout:
     increment(self._metrics[NUM_QUERIES_AC_TIMEDOUT])
   if report.was_cancelled:
     increment(self._metrics[NUM_QUERIES_CANCELLED])
コード例 #4
0
 def update_from_query_report(self, report):
   LOG.debug("Updating runtime stats (Query Runner PID: {0})".format(self.proc.pid))
   increment(self._metrics[NUM_QUERIES_FINISHED])
   if report.not_enough_memory:
     increment(self._metrics[NUM_QUERIES_EXCEEDED_MEM_LIMIT])
   if report.ac_rejected:
     increment(self._metrics[NUM_QUERIES_AC_REJECTED])
   if report.ac_timedout:
     increment(self._metrics[NUM_QUERIES_AC_TIMEDOUT])
   if report.was_cancelled:
     increment(self._metrics[NUM_QUERIES_CANCELLED])
コード例 #5
0
 def _wait_until_reserved(self, req):
     while True:
         with self._available.get_lock():
             if req <= self._available.value:
                 self._available.value -= req
                 LOG.debug(
                     "Reserved %s MB; %s MB available; %s MB overcommitted",
                     req, self._available.value, self.overcommitted_mem_mb)
                 reservation_id = self._next_reservation_id.value
                 increment(self._next_reservation_id)
                 if self.overcommitted_mem_mb > 0:
                     self._last_overcommitted_reservation_id.value = reservation_id
                 return reservation_id
         sleep(0.1)
コード例 #6
0
 def increment_metric(self, name):
   """Increment the current value of the metric called 'name'."""
   increment(self._metrics[name])
コード例 #7
0
 def increment_metric(self, name):
   """Increment the current value of the metric called 'name'."""
   increment(self._metrics[name])