PreadRemote is like pread but to a remote file.
(buf []byte, offset int64)
| 49 | |
| 50 | // PreadRemote is like pread but to a remote file. |
| 51 | func (r *reader) PreadRemote(buf []byte, offset int64) (int, error) { |
| 52 | key := r.context.GetString(pcontext.FileChunkCtxKey) |
| 53 | start := offset |
| 54 | end := int64(len(buf)) + offset - 1 |
| 55 | |
| 56 | log := r.Log().With().Str("operation", "preadremote").Str("key", key).Int64("start", start).Int64("end", end).Logger() |
| 57 | |
| 58 | count, err := r.doP2p(log, key, start, end, operationPreadRemote, buf) |
| 59 | if err == nil { |
| 60 | return int(count), nil |
| 61 | } |
| 62 | |
| 63 | // Could not find a peer that has this file, request origin. |
| 64 | startTime := time.Now() |
| 65 | originReq, err := r.originRequest(start, end) |
| 66 | if err != nil { |
| 67 | return -1, err |
| 68 | } |
| 69 | |
| 70 | count32 := int(0) |
| 71 | defer func() { |
| 72 | r.metricsRecorder.RecordUpstreamResponse(originReq.URL.Hostname(), key, "pread", time.Since(startTime).Seconds(), int64(count32)) |
| 73 | }() |
| 74 | count32, err = r.preadRemote(log, originReq, r.defaultHttpClient, buf) |
| 75 | return count32, err |
| 76 | } |
| 77 | |
| 78 | // FstatRemote stats a remote file. |
| 79 | func (r *reader) FstatRemote() (int64, error) { |
nothing calls this directly
no test coverage detected