MCPcopy Create free account
hub / github.com/Azure/peerd / PreadRemote

Method PreadRemote

pkg/discovery/content/reader/reader.go:51–76  ·  view source on GitHub ↗

PreadRemote is like pread but to a remote file.

(buf []byte, offset int64)

Source from the content-addressed store, hash-verified

49
50// PreadRemote is like pread but to a remote file.
51func (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.
79func (r *reader) FstatRemote() (int64, error) {

Callers

nothing calls this directly

Calls 5

LogMethod · 0.95
doP2pMethod · 0.95
originRequestMethod · 0.95
preadRemoteMethod · 0.95

Tested by

no test coverage detected