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

Function ProxyStartSortHandler

dsort/handler.go:41–117  ·  view source on GitHub ↗

PROXY ////// POST /v1/sort

(w http.ResponseWriter, r *http.Request, parsedRS *ParsedRequestSpec)

Source from the content-addressed store, hash-verified

39
40// POST /v1/sort
41func ProxyStartSortHandler(w http.ResponseWriter, r *http.Request, parsedRS *ParsedRequestSpec) {
42 var err error
43 parsedRS.TargetOrderSalt = []byte(time.Now().Format("15:04:05.000000"))
44
45 // TODO: handle case when bucket was removed during dSort job - this should
46 // stop whole operation. Maybe some listeners as we have on smap change?
47 // This would also be helpful for Downloader (in the middle of downloading
48 // large file the bucket can be easily deleted).
49
50 parsedRS.DSorterType, err = determineDSorterType(parsedRS)
51 if err != nil {
52 cmn.WriteErr(w, r, err)
53 return
54 }
55
56 b, err := js.Marshal(parsedRS)
57 if err != nil {
58 s := fmt.Sprintf("unable to marshal RequestSpec: %+v, err: %v", parsedRS, err)
59 cmn.WriteErrMsg(w, r, s, http.StatusInternalServerError)
60 return
61 }
62
63 var (
64 managerUUID = cos.GenUUID()
65 smap = ctx.smapOwner.Get()
66 )
67 checkResponses := func(responses []response) error {
68 for _, resp := range responses {
69 if resp.err == nil {
70 continue
71 }
72 glog.Errorf("[%s] start sort request failed to be broadcast, err: %s",
73 managerUUID, resp.err.Error())
74
75 path := apc.URLPathdSortAbort.Join(managerUUID)
76 broadcastTargets(http.MethodDelete, path, nil, nil, smap)
77
78 s := fmt.Sprintf("failed to execute start sort, err: %s, status: %d",
79 resp.err.Error(), resp.statusCode)
80 cmn.WriteErrMsg(w, r, s, http.StatusInternalServerError)
81 return resp.err
82 }
83
84 return nil
85 }
86
87 // Starting dSort has two phases:
88 // 1. Initialization, ensures that all targets successfully initialized all
89 // structures and are ready to receive requests: start, metrics, abort
90 // 2. Start, where we request targets to start the dSort.
91 //
92 // This prevents bugs where one targets would just start dSort (other did
93 // not have yet initialized) and starts to communicate with other targets
94 // but because they are not ready with their initialization will not recognize
95 // given dSort job. Also bug where we could send abort (which triggers cleanup)
96 // to not yet initialized target.
97
98 if glog.V(4) {

Callers 1

proxyStartSortHandlerMethod · 0.92

Calls 13

WriteErrFunction · 0.92
WriteErrMsgFunction · 0.92
GenUUIDFunction · 0.92
ErrorfFunction · 0.92
VFunction · 0.92
InfofFunction · 0.92
determineDSorterTypeFunction · 0.85
broadcastTargetsFunction · 0.85
MarshalMethod · 0.80
JoinMethod · 0.80
GetMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected