Skip to content

MakeBucket: Retry with correct region#665

Merged
harshavardhana merged 4 commits into
minio:masterfrom
vadmeste:error_resp_has_headers
Apr 26, 2017
Merged

MakeBucket: Retry with correct region#665
harshavardhana merged 4 commits into
minio:masterfrom
vadmeste:error_resp_has_headers

Conversation

@vadmeste
Copy link
Copy Markdown
Member

The main purpose if this PR is to be able to find x-amz-bucket-region
when S3 server returns InvalidRegion error. That would help clients
to retry creating bucket with the correct region.

@harshavardhana harshavardhana changed the title API: Add headers to ErrorResponse api: Add headers to ErrorResponse Apr 25, 2017
Copy link
Copy Markdown
Member

@harshavardhana harshavardhana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed this change needs fix the MakeBucket behavior.

@vadmeste vadmeste force-pushed the error_resp_has_headers branch from f903f0d to e519f9f Compare April 25, 2017 19:27
@vadmeste vadmeste changed the title api: Add headers to ErrorResponse [WIP] MakeBucket: Retry with correct region Apr 25, 2017
@vadmeste vadmeste force-pushed the error_resp_has_headers branch from e519f9f to cadf71b Compare April 25, 2017 19:44
If MakeBucket is called with the wrong region, fetch the server's correct
region from the S3 API response headers and retries sending the create
bucket request with the new region.
@vadmeste vadmeste force-pushed the error_resp_has_headers branch from cadf71b to 864e52b Compare April 25, 2017 20:20
@vadmeste vadmeste changed the title [WIP] MakeBucket: Retry with correct region MakeBucket: Retry with correct region Apr 25, 2017
@vadmeste
Copy link
Copy Markdown
Member Author

Can this PR be reviewed again ?

Comment thread api.go Outdated
// we can retry the request with the new region.
if errResponse.Code == "InvalidRegion" && errResponse.Region != "" {
c.bucketLocCache.Set(metadata.bucketName, errResponse.Region)
if errResponse.Code == "InvalidRegion" && errResponse.Headers.Get("x-amz-bucket-region") != "" {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do this, set the Region properly and remove Headers from errorResponse structure. Let me send a PR to this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a chance for this to go into an infinite loop, we just want to do this once.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do this, set the Region properly and remove Headers from errorResponse structure.

My aim was to make the code reflects exactly the spec even if it looks more longer, the reason is that the code will be easier to read and be compared with the S3 spec. Also we are not the creator of the spec and any optimization could bring new problems.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Region is there because it does exist in some operations on AWS S3, so we can re-purpose making it more cleaner and use it as part of region retry. I sent a PR which retains Headers but extracts the value and sets it properly for errorResponse instead of spilling the code.

Comment thread api_functional_v4_test.go
t.Fatal("Error: PutObject should fail.")
}
if err.Error() != "Proactively closed to be verified later." {
if err.Error() != "proactively closed to be verified later" {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did this change @vadmeste ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test was failing without this change, 'proactively closed to be verified later' message should be the same as returned by the go routine created just above.

Comment thread api.go

// Save the body.
errBodySeeker = bytes.NewReader(errBodyBytes)
res.Body = ioutil.NopCloser(errBodySeeker)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? there seems like something similar is done above.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? there seems like something similar is done above.

Yes, this is needed. You can see just above that httpRespToErrorResponse() is reading from res.Body so this change puts back res.Body

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but this is wrong see below

               // Save the body back again.
                errBodySeeker.Seek(0, 0) // Seek back to starting point.
                res.Body = ioutil.NopCloser(errBodySeeker)

We seek back.

Comment thread api.go Outdated
// China region.
location = "cn-north-1"
}
if metadata.bucketLocation == "" {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary anymore?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary anymore?

No, we don't need this anymore since you brought back makeBucketRequest(), I'll update

@vadmeste vadmeste force-pushed the error_resp_has_headers branch from 12133d7 to 15837c2 Compare April 26, 2017 11:23
Copy link
Copy Markdown
Member

@harshavardhana harshavardhana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more comment..

@vadmeste vadmeste force-pushed the error_resp_has_headers branch from 15837c2 to f302102 Compare April 26, 2017 18:05
@harshavardhana harshavardhana merged commit 5297a81 into minio:master Apr 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants