Skip to content

Commit

Permalink
Merge pull request #4868 from butonic/improve-metadata-client-log
Browse files Browse the repository at this point in the history
improve metadata client errors
  • Loading branch information
butonic authored Sep 26, 2024
2 parents b5c3c67 + fc0d5bf commit e1e8c29
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
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

0 comments on commit e1e8c29

Please sign in to comment.