chore: optimize download log (#1944)
Signed-off-by: Jim Ma <majinjing3@gmail.com>
This commit is contained in:
parent
9efbec2e16
commit
56e668bb0d
|
|
@ -397,9 +397,11 @@ func (s *server) recursiveDownload(ctx context.Context, req *dfdaemonv1.DownRequ
|
||||||
|
|
||||||
// only try to cache metadata when cacheRecursiveMetadata is set
|
// only try to cache metadata when cacheRecursiveMetadata is set
|
||||||
if s.cacheRecursiveMetadata > 0 {
|
if s.cacheRecursiveMetadata > 0 {
|
||||||
if err := s.recursiveDownloadWithP2PMetadata(ctx, log, span, traceID, req, stream); err == nil {
|
log.Infof("start to download with p2p metadata")
|
||||||
|
if err = s.recursiveDownloadWithP2PMetadata(ctx, log, span, traceID, req, stream); err == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
log.Warnf("download with p2p metadata failed, fallback to direct metadata")
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.recursiveDownloadWithDirectMetadata(ctx, log, span, traceID, req, stream)
|
return s.recursiveDownloadWithDirectMetadata(ctx, log, span, traceID, req, stream)
|
||||||
|
|
@ -455,6 +457,7 @@ func (s *server) recursiveDownloadWithP2PMetadata(
|
||||||
span.RecordError(err)
|
span.RecordError(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Infof("url entries count: %d", len(listMetadata.URLEntries))
|
||||||
|
|
||||||
loop:
|
loop:
|
||||||
for _, urlEntry := range listMetadata.URLEntries {
|
for _, urlEntry := range listMetadata.URLEntries {
|
||||||
|
|
@ -497,6 +500,7 @@ loop:
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait all sent tasks done or error
|
// wait all sent tasks done or error
|
||||||
|
log.Info("all request sent, wait all tasks processed")
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
if len(downloadErrors()) > 0 {
|
if len(downloadErrors()) > 0 {
|
||||||
// just return first error
|
// just return first error
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ func (lm *ListMetadataClient) Download(request *Request) (*Response, error) {
|
||||||
}
|
}
|
||||||
cost := time.Now().Sub(listStart).Milliseconds()
|
cost := time.Now().Sub(listStart).Milliseconds()
|
||||||
listMilliseconds += cost
|
listMilliseconds += cost
|
||||||
log.Infof("list dir %s cost: %dms", request.URL, cost)
|
log.Infof("list dir %s cost: %dms, entries(include dir): %d", parentReq.URL, cost, len(urlEntries))
|
||||||
|
|
||||||
for _, urlEntry := range urlEntries {
|
for _, urlEntry := range urlEntries {
|
||||||
if urlEntry.IsDir {
|
if urlEntry.IsDir {
|
||||||
|
|
@ -146,18 +146,19 @@ func (lm *ListMetadataClient) Download(request *Request) (*Response, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("list dirs cost: %dms, download cost: %dms", listMilliseconds, time.Now().Sub(start).Milliseconds())
|
|
||||||
|
|
||||||
metadata := ListMetadata{
|
metadata := ListMetadata{
|
||||||
URLEntries: allURLEntries,
|
URLEntries: allURLEntries,
|
||||||
}
|
}
|
||||||
data, _ := json.Marshal(metadata)
|
data, _ := json.Marshal(metadata)
|
||||||
|
|
||||||
|
log.Infof("list dirs cost: %dms, entries: %d, metadata size: %d, download cost: %dms",
|
||||||
|
listMilliseconds, len(allURLEntries), len(data), time.Now().Sub(start).Milliseconds())
|
||||||
return &Response{
|
return &Response{
|
||||||
Status: "OK",
|
Status: "OK",
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
Header: Header(map[string][]string{
|
Header: map[string][]string{
|
||||||
headers.Expires: {request.Header.Get(ListMetadataExpire)},
|
headers.Expires: {request.Header.Get(ListMetadataExpire)},
|
||||||
}),
|
},
|
||||||
Body: io.NopCloser(bytes.NewBuffer(data)),
|
Body: io.NopCloser(bytes.NewBuffer(data)),
|
||||||
ContentLength: int64(len(data)),
|
ContentLength: int64(len(data)),
|
||||||
Validate: func() error {
|
Validate: func() error {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue