-
Notifications
You must be signed in to change notification settings - Fork 367
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
Handle StorageID in S3 Gateway #8642
base: master
Are you sure you want to change the base?
Conversation
@@ -211,6 +211,7 @@ type Adapter interface { | |||
|
|||
BlockstoreType() string | |||
BlockstoreMetadata(ctx context.Context) (*BlockstoreMetadata, error) | |||
// GetStorageNamespaceInfo returns the StorageNamespaceInfo for storageID or nil if not found. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment that I promised @guy-har to add for my next OSS PR 🤓
@@ -46,7 +47,7 @@ func TestWriteBlob(t *testing.T) { | |||
reader := bytes.NewReader(data) | |||
adapter := testutil.NewMockAdapter() | |||
objectPointer := block.ObjectPointer{ | |||
StorageID: "", | |||
StorageID: config.SingleBlockstoreID, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit of tidying up, in the area of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a couple comments
pkg/gateway/operations/putobject.go
Outdated
@@ -177,6 +177,12 @@ func handleUploadPart(w http.ResponseWriter, req *http.Request, o *PathOperation | |||
} | |||
} | |||
|
|||
if srcRepo.StorageID != o.Repository.StorageID { | |||
o.Log(req).WithField("copy_source", copySource).WithError(err).Error("copy between different blockstores is not allowed") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are now 4 places where we add copy_source to the logger via copy-pasted code. Why not use a constant or perhaps at the beginning of the code block do copySourceLogger := o.Log(req).WithFIeld(copy_source",copySource) and then use that logger in these 4 places
@@ -46,7 +47,7 @@ func TestWriteBlob(t *testing.T) { | |||
reader := bytes.NewReader(data) | |||
adapter := testutil.NewMockAdapter() | |||
objectPointer := block.ObjectPointer{ | |||
StorageID: "", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also test non blank storage IDs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true!
But that's for a different Issue (opened in a different project).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Mostly worried about missing test coverage.
pkg/catalog/catalog.go
Outdated
@@ -2738,6 +2738,10 @@ func (c *Catalog) CopyEntry(ctx context.Context, srcRepository, srcRef, srcPath, | |||
if err != nil { | |||
return nil, err | |||
} | |||
|
|||
if srcRepo.StorageID != destRepo.StorageID { | |||
return nil, fmt.Errorf("copy between different blockstores is not allowed: %w", graveler.ErrInvalidValue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil, fmt.Errorf("copy between different blockstores is not allowed: %w", graveler.ErrInvalidValue) | |
return nil, fmt.Errorf("%w: cannot copy between different blockstores", graveler.ErrInvalidValue) |
But also note that this error message is quite nasty. Consider using ErrInvalidStorageId, and also mentioning the two storage IDs.
@@ -442,6 +442,7 @@ func handleListMultipartUploads(w http.ResponseWriter, req *http.Request, o *Rep | |||
opts.KeyMarker = &keyMarker | |||
} | |||
mpuResp, err := o.BlockStore.ListMultipartUploads(req.Context(), block.ObjectPointer{ | |||
StorageID: o.Repository.StorageID, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How could TestListMultipartUploads pass without this? I think perhaps still using blank StorageIDs in those tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT code was introduced here with no tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No tests indeed -
For almost the whole gateway/operations
code...
Since it requires a decent amount of work, and it seems to me out of scope for this PR -
How about adding an Issue for adding unit-tests for these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is with adding untested code to the gateway. I am more comfortable with the new code as long as there are no storage IDs anywhere - I guess we can pull this code untested. But not sure of the benefit TBH.
pkg/gateway/operations/putobject.go
Outdated
@@ -177,6 +177,12 @@ func handleUploadPart(w http.ResponseWriter, req *http.Request, o *PathOperation | |||
} | |||
} | |||
|
|||
if srcRepo.StorageID != o.Repository.StorageID { | |||
o.Log(req).WithField("copy_source", copySource).WithError(err).Error("copy between different blockstores is not allowed") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand "WithError(err)" - is there an error?
Also please rephrase the error message as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy-paste 🤦
Nice catch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
;-(
@@ -442,6 +442,7 @@ func handleListMultipartUploads(w http.ResponseWriter, req *http.Request, o *Rep | |||
opts.KeyMarker = &keyMarker | |||
} | |||
mpuResp, err := o.BlockStore.ListMultipartUploads(req.Context(), block.ObjectPointer{ | |||
StorageID: o.Repository.StorageID, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT code was introduced here with no tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arielshaqed thanks for your review,
Your comments were fixed / addressed.
Please note that this is indeed not covered by unit-tests,
But this whole gateway part isn't, and adding tests to it might be a massive task.
It's been manually tested, and I think it's enough in this stage of the project -
But I'm interested in hearing your perspective.
pkg/gateway/operations/putobject.go
Outdated
@@ -177,6 +177,12 @@ func handleUploadPart(w http.ResponseWriter, req *http.Request, o *PathOperation | |||
} | |||
} | |||
|
|||
if srcRepo.StorageID != o.Repository.StorageID { | |||
o.Log(req).WithField("copy_source", copySource).WithError(err).Error("copy between different blockstores is not allowed") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy-paste 🤦
Nice catch.
@@ -442,6 +442,7 @@ func handleListMultipartUploads(w http.ResponseWriter, req *http.Request, o *Rep | |||
opts.KeyMarker = &keyMarker | |||
} | |||
mpuResp, err := o.BlockStore.ListMultipartUploads(req.Context(), block.ObjectPointer{ | |||
StorageID: o.Repository.StorageID, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No tests indeed -
For almost the whole gateway/operations
code...
Since it requires a decent amount of work, and it seems to me out of scope for this PR -
How about adding an Issue for adding unit-tests for these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While review this PR's comments, found out that this tests file has nothing to actually do with putobject
-
It tests write_blob
, hence moved here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This also fixes Catalog.CopyEntry, which is obviously useful. Please make sure to write tests. I do know that the S3 gateway is not unit-tested. But it does have some integration tests in Esti - let's make sure that we at least run those with nonempty StorageIDs!
This is a requirement for releasing code that sets a nonempty StorageID.
@@ -442,6 +442,7 @@ func handleListMultipartUploads(w http.ResponseWriter, req *http.Request, o *Rep | |||
opts.KeyMarker = &keyMarker | |||
} | |||
mpuResp, err := o.BlockStore.ListMultipartUploads(req.Context(), block.ObjectPointer{ | |||
StorageID: o.Repository.StorageID, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is with adding untested code to the gateway. I am more comfortable with the new code as long as there are no storage IDs anywhere - I guess we can pull this code untested. But not sure of the benefit TBH.
Spent some extra time adding unit-tests for the Gateway, but it seems like a task that exceeds the scope of this Issue (and project). Obviously I don't enjoy adding code with no tests covering it, but it should be covered before the project is released. Merging - if you still think there's things that can be done, lmk. |
@nadavsteindler thanks for reviewing - Can you PTAL again? 🙏 |
Closes #8641.
Change Description
Background
Making sure S3 Gateway plays way with
StorageID
.Note that
StorageID
was already added to most of the relevantObjectPointer
objects,So it's mainly about not allowing copy ops between two different
StorageIDs
.Testing Details
AFAIK there's no coverage for the copy part,
So this was tested manually.