Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MakeBucket: Retry with correct region #665

Merged
merged 4 commits into from
Apr 26, 2017

Conversation

vadmeste
Copy link
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
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
Member Author

Can this PR be reviewed again ?

api.go Outdated
// Bucket region if set in error response and the error code dictates invalid region,
// 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
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
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
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
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.

@@ -801,7 +801,7 @@ func TestRemovePartiallyUploaded(t *testing.T) {
if err == nil {
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
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
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.

api.go Outdated

// Save the body.
errBodySeeker = bytes.NewReader(errBodyBytes)
res.Body = ioutil.NopCloser(errBodySeeker)
Copy link
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
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
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.

api.go Outdated
// China region.
location = "cn-north-1"
}
if metadata.bucketLocation == "" {
Copy link
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
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
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