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

improve metadata client errors #4868

Merged
merged 1 commit into from
Sep 26, 2024
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
5 changes: 5 additions & 0 deletions changelog/unreleased/improve-metadata-client-log.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Improve metadata client errors

We now return a more descripive error message when the metadata client cannot create a space because it already exists.

https://github.com/cs3org/reva/pull/4868
25 changes: 23 additions & 2 deletions pkg/storage/utils/metadata/cs3.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"bytes"
"context"
"errors"
"fmt"
"io"
"net/http"
"os"
Expand Down Expand Up @@ -107,6 +108,27 @@ func (cs3 *CS3) Init(ctx context.Context, spaceid string) (err error) {
if err != nil {
return err
}

lsRes, err := client.ListStorageSpaces(ctx, &provider.ListStorageSpacesRequest{
Filters: []*provider.ListStorageSpacesRequest_Filter{
{
Type: provider.ListStorageSpacesRequest_Filter_TYPE_ID,
Term: &provider.ListStorageSpacesRequest_Filter_Id{
Id: &provider.StorageSpaceId{OpaqueId: spaceid + "!" + spaceid},
},
},
},
})
switch {
case err != nil:
return err
case lsRes.Status.Code == rpc.Code_CODE_OK && len(lsRes.StorageSpaces) > 0:
if len(lsRes.StorageSpaces) > 0 {
cs3.SpaceRoot = lsRes.StorageSpaces[0].Root
return nil
}
}

// FIXME change CS3 api to allow sending a space id
cssr, err := client.CreateStorageSpace(ctx, &provider.CreateStorageSpaceRequest{
Opaque: &types.Opaque{
Expand All @@ -127,8 +149,7 @@ func (cs3 *CS3) Init(ctx context.Context, spaceid string) (err error) {
case cssr.Status.Code == rpc.Code_CODE_OK:
cs3.SpaceRoot = cssr.StorageSpace.Root
case cssr.Status.Code == rpc.Code_CODE_ALREADY_EXISTS:
// TODO make CreateStorageSpace return existing space?
cs3.SpaceRoot = &provider.ResourceId{SpaceId: spaceid, OpaqueId: spaceid}
return errtypes.AlreadyExists(fmt.Sprintf("user %s does not have access to metadata space %s, but it exists", cs3.serviceUser.Id.OpaqueId, spaceid))
default:
return errtypes.NewErrtypeFromStatus(cssr.Status)
}
Expand Down
Loading