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

Handle StorageID in S3 Gateway #8642

Merged
merged 4 commits into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/block/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor Author

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 🤓

GetStorageNamespaceInfo(storageID string) *StorageNamespaceInfo
ResolveNamespace(storageID, storageNamespace, key string, identifierType IdentifierType) (QualifiedKey, error)

Expand Down
4 changes: 4 additions & 0 deletions pkg/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("%w: cannot copy between repos with different StorageIDs", graveler.ErrInvalidStorageID)
}
}

// copy data to a new physical address
Expand Down
1 change: 1 addition & 0 deletions pkg/gateway/operations/listobjects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

StorageNamespace: o.Repository.StorageNamespace,
IdentifierType: block.IdentifierTypeRelative,
}, opts)
Expand Down
6 changes: 6 additions & 0 deletions pkg/gateway/operations/putobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).Error("copy between repos with different StorageIDs is not allowed")
_ = o.EncodeError(w, req, err, gatewayErrors.Codes.ToAPIErr(gatewayErrors.ErrInvalidCopySource))
return
}

src := block.ObjectPointer{
StorageID: srcRepo.StorageID,
StorageNamespace: srcRepo.StorageNamespace,
Expand Down
Copy link
Contributor Author

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.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package operations_test
package upload_test

import (
"bytes"
Expand All @@ -10,6 +10,7 @@ import (

"github.com/treeverse/lakefs/pkg/api/apiutil"
"github.com/treeverse/lakefs/pkg/block"
"github.com/treeverse/lakefs/pkg/config"
"github.com/treeverse/lakefs/pkg/testutil"
"github.com/treeverse/lakefs/pkg/upload"
)
Expand Down Expand Up @@ -46,7 +47,7 @@ func TestWriteBlob(t *testing.T) {
reader := bytes.NewReader(data)
adapter := testutil.NewMockAdapter()
objectPointer := block.ObjectPointer{
StorageID: "",
StorageID: config.SingleBlockstoreID,
StorageNamespace: storageNamespace,
IdentifierType: block.IdentifierTypeRelative,
Identifier: upload.DefaultPathProvider.NewPath(),
Expand Down
Loading