func()

in pkg/discovery/content/reader/reader.go [51:76]


func (r *reader) PreadRemote(buf []byte, offset int64) (int, error) {
	key := r.context.GetString(pcontext.FileChunkCtxKey)
	start := offset
	end := int64(len(buf)) + offset - 1

	log := r.Log().With().Str("operation", "preadremote").Str("key", key).Int64("start", start).Int64("end", end).Logger()

	count, err := r.doP2p(log, key, start, end, operationPreadRemote, buf)
	if err == nil {
		return int(count), nil
	}

	// Could not find a peer that has this file, request origin.
	startTime := time.Now()
	originReq, err := r.originRequest(start, end)
	if err != nil {
		return -1, err
	}

	count32 := int(0)
	defer func() {
		r.metricsRecorder.RecordUpstreamResponse(originReq.URL.Hostname(), key, "pread", time.Since(startTime).Seconds(), int64(count32))
	}()
	count32, err = r.preadRemote(log, originReq, r.defaultHttpClient, buf)
	return count32, err
}