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

Function shardsHandler

dsort/handler.go:458–504  ·  view source on GitHub ↗

shardsHandler is the handler for the HTTP endpoint /v1/sort/shards. A valid POST to this endpoint results in a new shard being created locally based on the contents of the incoming request body. The shard is then sent to the correct target in the cluster as per HRW.

(managers *ManagerGroup)

Source from the content-addressed store, hash-verified

456// A valid POST to this endpoint results in a new shard being created locally based on the contents
457// of the incoming request body. The shard is then sent to the correct target in the cluster as per HRW.
458func shardsHandler(managers *ManagerGroup) http.HandlerFunc {
459 return func(w http.ResponseWriter, r *http.Request) {
460 if !checkHTTPMethod(w, r, http.MethodPost) {
461 return
462 }
463 apiItems, err := checkRESTItems(w, r, 1, apc.URLPathdSortShards.L)
464 if err != nil {
465 return
466 }
467 managerUUID := apiItems[0]
468 dsortManager, exists := managers.Get(managerUUID)
469 if !exists {
470 s := fmt.Sprintf("invalid request: job %q does not exist", managerUUID)
471 cmn.WriteErrMsg(w, r, s, http.StatusNotFound)
472 return
473 }
474
475 if !dsortManager.inProgress() {
476 cmn.WriteErrMsg(w, r, fmt.Sprintf("no %s process in progress", DSortName))
477 return
478 }
479 if dsortManager.aborted() {
480 cmn.WriteErrMsg(w, r, fmt.Sprintf("%s process was aborted", DSortName))
481 return
482 }
483
484 var (
485 buf, slab = mm.AllocSize(serializationBufSize)
486 tmpMetadata = &CreationPhaseMetadata{}
487 )
488 defer slab.Free(buf)
489
490 if err := tmpMetadata.DecodeMsg(msgp.NewReaderBuf(r.Body, buf)); err != nil {
491 err = fmt.Errorf(cmn.FmtErrUnmarshal, DSortName, "creation phase metadata", "-", err)
492 cmn.WriteErr(w, r, err, http.StatusInternalServerError)
493 return
494 }
495
496 if !dsortManager.inProgress() || dsortManager.aborted() {
497 cmn.WriteErrMsg(w, r, fmt.Sprintf("no %s process", DSortName))
498 return
499 }
500
501 dsortManager.creationPhase.metadata = *tmpMetadata
502 dsortManager.startShardCreation <- struct{}{}
503 }
504}
505
506// recordsHandler is the handler called for the HTTP endpoint /v1/sort/records.
507// A valid POST to this endpoint updates this target's dsortManager.Records with the

Callers 1

SortHandlerFunction · 0.85

Calls 10

WriteErrMsgFunction · 0.92
WriteErrFunction · 0.92
checkHTTPMethodFunction · 0.85
inProgressMethod · 0.80
abortedMethod · 0.80
AllocSizeMethod · 0.80
checkRESTItemsFunction · 0.70
GetMethod · 0.65
FreeMethod · 0.45
DecodeMsgMethod · 0.45

Tested by

no test coverage detected