MCPcopy
hub / github.com/NVIDIA/aistore / generateShardsWithOrderingFile

Method generateShardsWithOrderingFile

dsort/dsort.go:672–770  ·  view source on GitHub ↗
(maxSize int64)

Source from the content-addressed store, hash-verified

670}
671
672func (m *Manager) generateShardsWithOrderingFile(maxSize int64) ([]*extract.Shard, error) {
673 var (
674 shards = make([]*extract.Shard, 0)
675 externalKeyMap = make(map[string]string)
676 shardsBuilder = make(map[string][]*extract.Shard)
677 )
678
679 if maxSize <= 0 {
680 return nil, errors.New("invalid max size of shard was specified when using external key map")
681 }
682
683 req, err := http.NewRequest(http.MethodGet, m.rs.OrderFileURL, http.NoBody)
684 if err != nil {
685 return nil, err
686 }
687 // is intra-call
688 tsi := m.ctx.t.Snode()
689 req.Header.Set(apc.HdrCallerID, tsi.ID())
690 req.Header.Set(apc.HdrCallerName, tsi.String())
691
692 resp, err := m.client.Do(req) // nolint:bodyclose // closed inside cos.Close
693 if err != nil {
694 return nil, err
695 }
696 defer cos.Close(resp.Body)
697 if resp.StatusCode != http.StatusOK {
698 return nil, fmt.Errorf(
699 "unexpected status code (%d) when requesting order file from %q",
700 resp.StatusCode, m.rs.OrderFileURL,
701 )
702 }
703
704 // TODO: handle very large files > GB - in case the file is very big we
705 // need to save file to the disk and operate on the file directly rather
706 // than keeping everything in memory.
707
708 lineReader := bufio.NewReader(resp.Body)
709
710 for idx := 0; ; idx++ {
711 l, _, err := lineReader.ReadLine()
712 if err == io.EOF {
713 break
714 }
715 if err != nil {
716 return nil, err
717 }
718
719 line := strings.TrimSpace(string(l))
720 if line == "" {
721 continue
722 }
723
724 parts := strings.Split(line, m.rs.OrderFileSep)
725 if len(parts) != 2 {
726 msg := fmt.Sprintf("malformed line (%d) in external key map: %s", idx, line)
727 if err := m.react(m.rs.EKMMalformedLine, msg); err != nil {
728 return nil, err
729 }

Callers 1

Calls 13

reactMethod · 0.95
CloseFunction · 0.92
NewRecordsFunction · 0.92
TotalSizeMethod · 0.80
NewMethod · 0.65
SnodeMethod · 0.65
SetMethod · 0.65
IDMethod · 0.65
StringMethod · 0.65
DoMethod · 0.65
MetadataSizeMethod · 0.65
AllMethod · 0.45

Tested by

no test coverage detected