Пример #1
0
        def wrapper(*args, **kwargs):
            tries_left = 3
            while tries_left:
                # clear exception state so our re-raise can't reraise something
                # old. This isn't strictly necessary, but feels safer.
                sys.exc_clear()
                try:
                    if not self.transport.isOpen():
                        self.transport.open()
                    st = time.time()

                    str_args = _unpack_guid_secret_in_handle(repr(args))
                    logging.debug("Thrift call: %s.%s(args=%s, kwargs=%s)" %
                                  (str(self.wrapped.__class__), attr, str_args,
                                   repr(kwargs)))

                    ret = res(*args, **kwargs)

                    if ENABLE_SMART_THRIFT_POOL.get(
                    ) and 'OpenSession' == attr and 'http_addr' in repr(ret):
                        coordinator_host = re.search(
                            'http_addr\':\ \'(.*:[0-9]{2,})\', \'', repr(ret))
                        self.coordinator_host = coordinator_host.group(1)

                    log_msg = _unpack_guid_secret_in_handle(repr(ret))

                    # Truncate log message, increase output in DEBUG mode
                    log_limit = 2000 if settings.DEBUG else 1000
                    log_msg = log_msg[:log_limit] + (log_msg[log_limit:]
                                                     and '...')

                    duration = time.time() - st

                    # Log the duration at different levels, depending on how long it took.
                    logmsg = "Thrift call: %s.%s(args=%s, kwargs=%s) returned in %dms: %s" % (
                        str(self.wrapped.__class__), attr, str_args,
                        repr(kwargs), duration * 1000, log_msg)
                    log_if_slow_call(duration=duration, message=logmsg)

                    return ret
                except socket.error, e:
                    pass
                except TTransportException, e:
                    pass
Пример #2
0
    def wrapper(*args, **kwargs):
      tries_left = 3
      while tries_left:
        # clear exception state so our re-raise can't reraise something
        # old. This isn't strictly necessary, but feels safer.
        sys.exc_clear()
        try:
          if not self.transport.isOpen():
            self.transport.open()
          st = time.time()

          str_args = _unpack_guid_secret_in_handle(repr(args))
          logging.debug("Thrift call: %s.%s(args=%s, kwargs=%s)" % (str(self.wrapped.__class__), attr, str_args, repr(kwargs)))

          ret = res(*args, **kwargs)

          if ENABLE_SMART_THRIFT_POOL.get() and 'OpenSession' == attr and 'http_addr' in repr(ret):
            coordinator_host = re.search('http_addr\':\ \'(.*:[0-9]{2,})\', \'', repr(ret))
            self.coordinator_host = coordinator_host.group(1)

          log_msg = _unpack_guid_secret_in_handle(repr(ret))

          # Truncate log message, increase output in DEBUG mode
          log_limit = 2000 if settings.DEBUG else 1000
          log_msg = log_msg[:log_limit] + (log_msg[log_limit:] and '...')

          duration = time.time() - st

          # Log the duration at different levels, depending on how long it took.
          logmsg = "Thrift call: %s.%s(args=%s, kwargs=%s) returned in %dms: %s" % (str(self.wrapped.__class__), attr, str_args, repr(kwargs), duration * 1000, log_msg)
          log_if_slow_call(duration=duration, message=logmsg)

          return ret
        except socket.error, e:
          pass
        except TTransportException, e:
          pass
Пример #3
0
        def wrapper(*args, **kwargs):
            tries_left = 3
            while tries_left:
                # clear exception state so our re-raise can't reraise something
                # old. This isn't strictly necessary, but feels safer.
                # py3 doesn't have this
                if sys.version_info[0] == 2:
                    sys.exc_clear()

                try:
                    if not self.transport.isOpen():
                        self.transport.open()
                    st = time.time()

                    str_args = _unpack_guid_secret_in_handle(repr(args))
                    logging.debug("Thrift call: %s.%s(args=%s, kwargs=%s)" %
                                  (str(self.wrapped.__class__), attr, str_args,
                                   repr(kwargs)))

                    ret = res(*args, **kwargs)

                    if ENABLE_SMART_THRIFT_POOL.get(
                    ) and 'OpenSession' == attr and 'http_addr' in repr(ret):
                        coordinator_host = re.search(
                            'http_addr\':\ \'(.*:[0-9]{2,})\', \'', repr(ret))
                        self.coordinator_host = coordinator_host.group(1)

                    log_msg = _unpack_guid_secret_in_handle(repr(ret))

                    # Truncate log message, increase output in DEBUG mode
                    log_limit = 2000 if settings.DEBUG else 1000
                    log_msg = log_msg[:log_limit] + (log_msg[log_limit:]
                                                     and '...')

                    duration = time.time() - st

                    # Log the duration at different levels, depending on how long it took.
                    logmsg = "Thrift call: %s.%s(args=%s, kwargs=%s) returned in %dms: %s" % (
                        str(self.wrapped.__class__), attr, str_args,
                        repr(kwargs), duration * 1000, log_msg)
                    log_if_slow_call(duration=duration, message=logmsg)

                    return ret
                except (socket.error, socket.timeout,
                        TTransportException) as e:
                    self.transport.close()

                    if isinstance(e, socket.timeout
                                  ) or 'read operation timed out' in str(
                                      e):  # Can come from ssl.SSLError
                        logging.warn(
                            "Not retrying thrift call %s due to socket timeout"
                            % attr)
                        raise
                    else:
                        tries_left -= 1
                        if tries_left:
                            logging.info("Thrift exception; retrying: " +
                                         str(e),
                                         exc_info=0)
                            if 'generic failure: Unable to find a callback: 32775' in str(
                                    e):
                                logging.warn(
                                    "Increase the sasl_max_buffer value in hue.ini"
                                )
                        else:
                            raise
                except Exception as e:
                    logging.exception(
                        "Thrift saw exception (this may be expected).")
                    raise

            logging.warn("Out of retries for thrift call: " + attr)
            raise