MCPcopy Create free account
hub / github.com/MG-RAST/Shock / AsyncIndexer

Function AsyncIndexer

shock-server/node/index.go:15–171  ·  view source on GitHub ↗
(idxType string, nid string, colNum int, ctx context.Context)

Source from the content-addressed store, hash-verified

13)
14
15func AsyncIndexer(idxType string, nid string, colNum int, ctx context.Context) {
16 // use function closure to get current value of err at return time
17 var err error
18 defer func() {
19 locker.IndexLockMgr.Error(nid, idxType, err)
20 }()
21
22 // get node - this is read only
23 var n *Node
24 n, err = Load(nid)
25 if err != nil {
26 return
27 }
28
29 avgSize := int64(0)
30 subsetSize := int64(0)
31 count := int64(0)
32 indexFormat := ""
33 subsetName := ""
34
35 var f *os.File
36 if idxType == "bai" {
37 err = index.CreateBamIndex(n.FilePath())
38 if err != nil {
39 return
40 }
41 indexFormat = "bai"
42 } else if idxType == "column" {
43 idxType = fmt.Sprintf("%s%d", idxType, colNum)
44 f, err = os.Open(n.FilePath())
45 if err != nil {
46 return
47 }
48 defer f.Close()
49 idxer := index.NewColumnIndexer(f)
50 count, indexFormat, err = index.CreateColumnIndex(&idxer, colNum, n.IndexPath()+"/"+idxType+".idx")
51 if err != nil {
52 return
53 }
54 } else if idxType == "subset" {
55 // Utilizing the multipart form parser since we need to upload a file.
56 var params map[string]string
57 var files file.FormFiles
58 params, files, err = request.ParseMultipartForm(ctx.HttpRequest())
59 // clean up temp dir !!
60 defer file.RemoveAllFormFiles(files)
61 if err != nil {
62 return
63 }
64
65 parentIndex, hasParent := params["parent_index"]
66 if !hasParent {
67 err = errors.New("Index type subset requires parent_index param.")
68 return
69 } else if _, has := n.Indexes[parentIndex]; !has {
70 err = fmt.Errorf("Node %s does not have index of type %s.", n.Id, parentIndex)
71 return
72 }

Callers

nothing calls this directly

Calls 11

FilePathMethod · 0.95
IndexPathMethod · 0.95
CreateMethod · 0.95
SetIndexInfoMethod · 0.95
SaveMethod · 0.95
LockNodeMethod · 0.80
UnlockNodeMethod · 0.80
LoadFunction · 0.70
CloseMethod · 0.65
ErrorMethod · 0.45
RemoveMethod · 0.45

Tested by

no test coverage detected