MCPcopy
hub / github.com/minio/minio-go / executeMethod

Method executeMethod

api.go:667–834  ·  view source on GitHub ↗

executeMethod - instantiates a given method, and retries the request upon any error up to maxRetries attempts in a binomially delayed manner using a standard back off algorithm.

(ctx context.Context, method string, metadata requestMetadata)

Source from the content-addressed store, hash-verified

665// request upon any error up to maxRetries attempts in a binomially
666// delayed manner using a standard back off algorithm.
667func (c *Client) executeMethod(ctx context.Context, method string, metadata requestMetadata) (res *http.Response, err error) {
668 if c.IsOffline() {
669 return nil, errors.New(c.endpointURL.String() + " is offline.")
670 }
671
672 var retryable bool // Indicates if request can be retried.
673 var bodySeeker io.Seeker // Extracted seeker from io.Reader.
674 reqRetry := c.maxRetries // Indicates how many times we can retry the request
675
676 if metadata.contentBody != nil {
677 // Check if body is seekable then it is retryable.
678 bodySeeker, retryable = metadata.contentBody.(io.Seeker)
679 switch bodySeeker {
680 case os.Stdin, os.Stdout, os.Stderr:
681 retryable = false
682 }
683 // Retry only when reader is seekable
684 if !retryable {
685 reqRetry = 1
686 }
687
688 // Figure out if the body can be closed - if yes
689 // we will definitely close it upon the function
690 // return.
691 bodyCloser, ok := metadata.contentBody.(io.Closer)
692 if ok {
693 defer bodyCloser.Close()
694 }
695 }
696
697 if metadata.addCrc != nil && metadata.contentLength > 0 {
698 if metadata.trailer == nil {
699 metadata.trailer = make(http.Header, 1)
700 }
701 crc := metadata.addCrc.Hasher()
702 metadata.contentBody = newHashReaderWrapper(metadata.contentBody, crc, func(hash []byte) {
703 // Update trailer when done.
704 metadata.trailer.Set(metadata.addCrc.Key(), base64.StdEncoding.EncodeToString(hash))
705 })
706 metadata.trailer.Set(metadata.addCrc.Key(), base64.StdEncoding.EncodeToString(crc.Sum(nil)))
707 }
708
709 for range c.newRetryTimer(ctx, reqRetry, DefaultRetryUnit, DefaultRetryCap, MaxJitter) {
710 // Retry executes the following function body if request has an
711 // error until maxRetries have been exhausted, retry attempts are
712 // performed after waiting for a given period of time in a
713 // binomial fashion.
714 if retryable {
715 // Seek back to beginning for each attempt.
716 if _, err = bodySeeker.Seek(0, 0); err != nil {
717 // If seek failed, no need to retry.
718 return nil, err
719 }
720 }
721
722 // Instantiate a new request.
723 var req *http.Request
724 req, err = c.newRequest(ctx, method, metadata)

Callers 15

SelectObjectContentMethod · 0.95
GetObjectACLMethod · 0.95
BucketExistsMethod · 0.95
StatObjectMethod · 0.95
appendObjectDoMethod · 0.95
PutObjectLegalHoldMethod · 0.95
GetObjectLegalHoldMethod · 0.95
doMakeBucketMethod · 0.95
RemoveBucketMethod · 0.95
removeObjectMethod · 0.95
removeObjectsIterMethod · 0.95

Calls 15

IsOfflineMethod · 0.95
newRetryTimerMethod · 0.95
newRequestMethod · 0.95
doMethod · 0.95
newHashReaderWrapperFunction · 0.85
ToErrorResponseFunction · 0.85
isS3CodeRetryableFunction · 0.85
isRequestErrorRetryableFunction · 0.85
httpRespToErrorResponseFunction · 0.85
isHTTPStatusRetryableFunction · 0.85
HasherMethod · 0.80
EncodeToStringMethod · 0.80

Tested by

no test coverage detected