func()

in lib/backend/hdfsbackend/webhdfs/client.go [228:264]


func (c *client) Open(path string, dst io.Writer) error {
	v := c.values()
	v.Set("op", "OPEN")
	v.Set("buffersize", strconv.FormatInt(int64(c.config.BufferSize), 10))

	var resp *http.Response
	var nnErr error
	for _, nn := range c.namenodes {
		// We retry 400s here because experience has shown the datanode this
		// request gets redirected to is sometimes invalid, and will return a 400
		// error. By retrying the request, we hope to eventually get redirected
		// to a valid datanode.
		resp, nnErr = httputil.Get(
			getURL(nn, path, v),
			httputil.SendRetry(
				httputil.RetryBackoff(c.nameNodeBackOff()),
				httputil.RetryCodes(http.StatusBadRequest)))
		if nnErr != nil {
			if retryable(nnErr) {
				continue
			}
			if httputil.IsNotFound(nnErr) {
				return backenderrors.ErrBlobNotFound
			}
			return nnErr
		}
		defer resp.Body.Close()
		if n, err := io.Copy(dst, resp.Body); err != nil {
			return fmt.Errorf("copy response: %s", err)
		} else if n != resp.ContentLength {
			return fmt.Errorf(
				"transferred bytes %d does not match content length %d", n, resp.ContentLength)
		}
		return nil
	}
	return allNameNodesFailedError{nnErr}
}