Exemple #1
0
    def _convert_exception(self, exc, *args, **kwargs):
        """This parses the protocol exceptions to the api interface exceptions.

    This also logs the exception and increments the appropriate error counters.

    Args:
      exc: raw protocol exception.
      *args: additional args from the raising site.
      **kwargs: additional keyword args from the raising site.

    Returns:
      Api interface exceptions - dbexceptions with new args.
    """

        new_args = exc.args + (str(self), ) + args
        if kwargs:
            new_args += tuple(sorted(kwargs.itervalues()))
        new_exc = exc

        if isinstance(exc, gorpc.TimeoutError):
            new_exc = dbexceptions.TimeoutError(new_args)
        elif isinstance(exc, vtgate_utils.VitessError):
            new_exc = exc.convert_to_dbexception(new_args)
        elif isinstance(exc, gorpc.ProgrammingError):
            new_exc = dbexceptions.ProgrammingError(new_args)
        elif isinstance(exc, gorpc.GoRpcError):
            new_exc = dbexceptions.FatalError(new_args)

        keyspace_name = kwargs.get('keyspace', None)
        tablet_type = kwargs.get('tablet_type', None)

        vtgate_utils.log_exception(new_exc,
                                   keyspace=keyspace_name,
                                   tablet_type=tablet_type)
        return new_exc
Exemple #2
0
def convert_exception(exc, *args):
    new_args = exc.args + args
    if isinstance(exc, gorpc.TimeoutError):
        return dbexceptions.TimeoutError(new_args)
    elif isinstance(exc, gorpc.AppError):
        msg = str(exc[0]).lower()
        if msg.startswith('retry'):
            return dbexceptions.RetryError(new_args)
        if msg.startswith('fatal'):
            return dbexceptions.FatalError(new_args)
        if msg.startswith('tx_pool_full'):
            return dbexceptions.TxPoolFull(new_args)
        match = _errno_pattern.search(msg)
        if match:
            mysql_errno = int(match.group(1))
            if mysql_errno == 1062:
                return dbexceptions.IntegrityError(new_args)
            # TODO(sougou/liguo): remove this case once servers are deployed
            elif mysql_errno == 1290 and 'read-only' in msg:
                return dbexceptions.RetryError(new_args)
        return dbexceptions.DatabaseError(new_args)
    elif isinstance(exc, gorpc.ProgrammingError):
        return dbexceptions.ProgrammingError(new_args)
    elif isinstance(exc, gorpc.GoRpcError):
        return dbexceptions.FatalError(new_args)
    return exc
Exemple #3
0
  def _convert_exception(self, exc, *args, **kwargs):
    """This parses the protocol exceptions to the api interface exceptions.

    This also logs the exception and increments the appropriate error counters.

    Args:
      exc: raw protocol exception.
      *args: additional args from the raising site.
      **kwargs: additional keyword args from the raising site.

    Returns:
      Api interface exceptions - dbexceptions with new args.
    """
    kwargs_as_str = vtgate_utils.convert_exception_kwargs(kwargs)
    exc.args += args
    if kwargs_as_str:
      exc.args += kwargs_as_str,
    new_args = (type(exc).__name__,) + exc.args
    if isinstance(exc, gorpc.TimeoutError):
      new_exc = dbexceptions.TimeoutError(new_args)
    elif isinstance(exc, vtgate_utils.VitessError):
      new_exc = exc.convert_to_dbexception(new_args)
    elif isinstance(exc, gorpc.ProgrammingError):
      new_exc = dbexceptions.ProgrammingError(new_args)
    elif isinstance(exc, gorpc.GoRpcError):
      new_exc = dbexceptions.FatalError(new_args)
    else:
      new_exc = exc
    vtgate_utils.log_exception(
        new_exc,
        keyspace=kwargs.get('keyspace'), tablet_type=kwargs.get('tablet_type'))
    return new_exc
Exemple #4
0
def convert_exception(exc, *args, **kwargs):
    """This parses the protocol exceptions to the api interface exceptions.
  This also logs the exception and increments the appropriate error counters.

  Args:
    exc: raw protocol exception.
    args: additional args from the raising site.
    kwargs: additional keyword args from the raising site.

  Returns:
    Api interface exceptions - dbexceptions with new args.
  """

    new_args = exc.args + args
    if kwargs:
        new_args += tuple(kwargs.itervalues())
    new_exc = exc

    if isinstance(exc, gorpc.TimeoutError):
        new_exc = dbexceptions.TimeoutError(new_args)
    elif isinstance(exc, gorpc.AppError):
        new_exc = handle_app_error(new_args)
    elif isinstance(exc, gorpc.ProgrammingError):
        new_exc = dbexceptions.ProgrammingError(new_args)
    elif isinstance(exc, gorpc.GoRpcError):
        new_exc = dbexceptions.FatalError(new_args)

    keyspace = kwargs.get("keyspace", None)
    tablet_type = kwargs.get("tablet_type", None)

    vtgate_utils.log_exception(new_exc,
                               keyspace=keyspace,
                               tablet_type=tablet_type)
    return new_exc
Exemple #5
0
def convert_exception(exc, *args):
    new_args = exc.args + args
    if isinstance(exc, gorpc.TimeoutError):
        return dbexceptions.TimeoutError(new_args)
    elif isinstance(exc, gorpc.AppError):
        return handle_app_error(new_args)
    elif isinstance(exc, gorpc.ProgrammingError):
        return dbexceptions.ProgrammingError(new_args)
    elif isinstance(exc, gorpc.GoRpcError):
        return dbexceptions.FatalError(new_args)
    return exc
Exemple #6
0
def convert_exception(exc, *args):
  new_args = exc.args + args
  if isinstance(exc, gorpc.TimeoutError):
    return dbexceptions.TimeoutError(new_args)
  elif isinstance(exc, TabletError):
    return exc.convert_to_dbexception(new_args)
  elif isinstance(exc, gorpc.ProgrammingError):
    return dbexceptions.ProgrammingError(new_args)
  elif isinstance(exc, gorpc.GoRpcError):
    return dbexceptions.FatalError(new_args)
  return exc
def _convert_exception(exc, *args, **kwargs):
    """This parses the protocol exceptions to the api interface exceptions.

  This also logs the exception and increments the appropriate error counters.

  Args:
    exc: raw protocol exception.
    *args: additional args from the raising site.
    **kwargs: additional keyword args from the raising site.
              They will be converted into a single string, and added as an extra
              arg to the exception.

  Returns:
    Api interface exceptions - dbexceptions with new args.
  """
    kwargs_as_str = vtgate_utils.convert_exception_kwargs(kwargs)
    exc.args += args
    if kwargs_as_str:
        exc.args += kwargs_as_str,
    new_args = (type(exc).__name__, ) + exc.args
    if isinstance(exc, vtgate_utils.VitessError):
        new_exc = exc.convert_to_dbexception(new_args)
    elif isinstance(exc, grpc.RpcError):
        # Most RpcErrors should also implement Call so we can get details.
        if isinstance(exc, grpc.Call):
            code = exc.code()
            details = exc.details()
            if code == grpc.StatusCode.DEADLINE_EXCEEDED:
                new_exc = dbexceptions.TimeoutError(new_args)
            elif code == grpc.StatusCode.UNAVAILABLE:
                if vtgate_utils.throttler_err_re.search(details):
                    return dbexceptions.ThrottledError(new_args)
                else:
                    return dbexceptions.TransientError(new_args)
            elif code == grpc.StatusCode.ALREADY_EXISTS:
                new_exc = _prune_integrity_error(details, new_args)
            elif code == grpc.StatusCode.FAILED_PRECONDITION:
                return dbexceptions.QueryNotServed(details, new_args)
            elif code == grpc.StatusCode.INVALID_ARGUMENT:
                return dbexceptions.ProgrammingError(details, new_args)
            else:
                # Other RPC error that we don't specifically handle.
                new_exc = dbexceptions.DatabaseError(new_args +
                                                     (code, details))
        else:
            # RPC error that doesn't provide code and details.
            # Don't let gRPC-specific errors leak beyond this package.
            new_exc = dbexceptions.DatabaseError(new_args + (exc, ))
    else:
        new_exc = exc
    vtgate_utils.log_exception(new_exc,
                               keyspace=kwargs.get('keyspace'),
                               tablet_type=kwargs.get('tablet_type'))
    return new_exc
Exemple #8
0
def convert_exception(exc, *args):
    """Return an exception object expected by callers."""
    new_args = exc.args + args
    if isinstance(exc, gorpc.TimeoutError):
        return dbexceptions.TimeoutError(new_args)
    elif isinstance(exc, vtgate_utils.VitessError):
        return exc.convert_to_dbexception(new_args)
    elif isinstance(exc, gorpc.ProgrammingError):
        return dbexceptions.ProgrammingError(new_args)
    elif isinstance(exc, gorpc.GoRpcError):
        return dbexceptions.FatalError(new_args)
    return exc
def _convert_exception(exc, *args, **kwargs):
  """This parses the protocol exceptions to the api interface exceptions.

  This also logs the exception and increments the appropriate error counters.

  Args:
    exc: raw protocol exception.
    *args: additional args from the raising site.
    **kwargs: additional keyword args from the raising site.
              They will be converted into a single string, and added as an extra
              arg to the exception.

  Returns:
    Api interface exceptions - dbexceptions with new args.
  """
  kwargs_as_str = vtgate_utils.convert_exception_kwargs(kwargs)
  exc.args += args
  if kwargs_as_str:
    exc.args += kwargs_as_str,
  new_args = (type(exc).__name__,) + exc.args
  if isinstance(exc, vtgate_utils.VitessError):
    new_exc = exc.convert_to_dbexception(new_args)
  elif isinstance(exc, face.ExpirationError):
    # face.ExpirationError is returned by the gRPC library when
    # a request times out. Note it is a subclass of face.AbortionError
    # so we have to test for it before.
    new_exc = dbexceptions.TimeoutError(new_args)
  elif isinstance(exc, face.AbortionError):
    # face.AbortionError is the toplevel error returned by gRPC for any
    # RPC that finishes earlier than expected.
    msg = exc.details
    if exc.code == interfaces.StatusCode.UNAVAILABLE:
      if _throttler_err_pattern.search(msg):
        return dbexceptions.ThrottledError(new_args)
      else:
        return dbexceptions.TransientError(new_args)
    elif exc.code == interfaces.StatusCode.ALREADY_EXISTS:
      new_exc = _prune_integrity_error(msg, new_args)
    elif exc.code == interfaces.StatusCode.FAILED_PRECONDITION:
      return dbexceptions.QueryNotServed(msg, new_args)
    else:
      # Unhandled RPC application error
      new_exc = dbexceptions.DatabaseError(new_args + (msg,))
  else:
    new_exc = exc
  vtgate_utils.log_exception(
      new_exc,
      keyspace=kwargs.get('keyspace'), tablet_type=kwargs.get('tablet_type'))
  return new_exc
Exemple #10
0
def convert_exception(exc, *args):
    new_args = exc.args + args
    if isinstance(exc, gorpc.TimeoutError):
        return dbexceptions.TimeoutError(new_args)
    elif isinstance(exc, gorpc.AppError):
        msg = str(exc[0]).lower()
        match = _errno_pattern.search(msg)
        if match:
            mysql_errno = int(match.group(1))
            return _errno_map.get(mysql_errno,
                                  dbexceptions.DatabaseError)(new_args)
        return dbexceptions.DatabaseError(new_args)
    elif isinstance(exc, gorpc.ProgrammingError):
        return dbexceptions.ProgrammingError(new_args)
    elif isinstance(exc, gorpc.GoRpcError):
        return dbexceptions.FatalError(new_args)
    return exc
Exemple #11
0
def convert_exception(exc, *args):
    new_args = exc.args + args
    vtdb_logger.get_logger().vtgatev2_exception(exc)
    if isinstance(exc, gorpc.TimeoutError):
        return dbexceptions.TimeoutError(new_args)
    elif isinstance(exc, gorpc.AppError):
        msg = str(exc[0]).lower()
        match = _errno_pattern.search(msg)
        if match:
            mysql_errno = int(match.group(1))
            if mysql_errno == 1062:
                return dbexceptions.IntegrityError(new_args)
        return dbexceptions.DatabaseError(new_args)
    elif isinstance(exc, gorpc.ProgrammingError):
        return dbexceptions.ProgrammingError(new_args)
    elif isinstance(exc, gorpc.GoRpcError):
        return dbexceptions.FatalError(new_args)
    return exc
Exemple #12
0
def convert_exception(exc, *args):
    new_args = exc.args + args
    if isinstance(exc, gorpc.TimeoutError):
        return dbexceptions.TimeoutError(new_args)
    elif isinstance(exc, gorpc.AppError):
        msg = str(exc[0]).lower()
        if msg.startswith('request_backlog'):
            return dbexceptions.RequestBacklog(new_args)
        match = _errno_pattern.search(msg)
        if match:
            mysql_errno = int(match.group(1))
            if mysql_errno == 1062:
                return dbexceptions.IntegrityError(new_args)
        return dbexceptions.DatabaseError(new_args)
    elif isinstance(exc, gorpc.ProgrammingError):
        return dbexceptions.ProgrammingError(new_args)
    elif isinstance(exc, gorpc.GoRpcError):
        return dbexceptions.FatalError(new_args)
    return exc