-
Notifications
You must be signed in to change notification settings - Fork 50
Engine EC #3534
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
Merged
Merged
Engine EC #3534
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package errors | ||
|
|
||
| import ( | ||
| oid "github.com/nspcc-dev/neofs-sdk-go/object/id" | ||
| ) | ||
|
|
||
| // ObjectID is an object ID as error. | ||
| type ObjectID oid.ID | ||
|
|
||
| // Error returns string-encoded object ID. | ||
| func (x ObjectID) Error() string { | ||
| return oid.ID(x).String() | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package errors_test | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| ierrors "github.com/nspcc-dev/neofs-node/internal/errors" | ||
| oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestErrObjectID(t *testing.T) { | ||
| id := oidtest.ID() | ||
| err := ierrors.ObjectID(id) | ||
|
|
||
| t.Run("errors.As", func(t *testing.T) { | ||
| check := func(t *testing.T, err error) { | ||
| var e ierrors.ObjectID | ||
| require.ErrorAs(t, err, &e) | ||
| require.EqualValues(t, id, e) | ||
| } | ||
|
|
||
| check(t, err) | ||
| check(t, fmt.Errorf("some context: %w, %w", errors.New("any"), err)) | ||
| }) | ||
|
|
||
| require.Implements(t, new(error), err) | ||
| require.EqualError(t, err, id.String()) | ||
carpawell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| package engine | ||
|
|
||
| import ( | ||
| "errors" | ||
| "io" | ||
|
|
||
| iec "github.com/nspcc-dev/neofs-node/internal/ec" | ||
| ierrors "github.com/nspcc-dev/neofs-node/internal/errors" | ||
| meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" | ||
| apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" | ||
| cid "github.com/nspcc-dev/neofs-sdk-go/container/id" | ||
| "github.com/nspcc-dev/neofs-sdk-go/object" | ||
| oid "github.com/nspcc-dev/neofs-sdk-go/object/id" | ||
| "go.uber.org/zap" | ||
| ) | ||
|
|
||
| // GetECPart looks up for object that carries EC part produced within cnr for | ||
| // parent object and indexed by pi in the underlying metabase, checks its | ||
| // availability and reads it from the underlying BLOB storage. The result is a | ||
| // header and a payload stream that must be closed by caller after processing. | ||
| // | ||
| // If write-cache is enabled, GetECPart tries to get the object from it first. | ||
| // | ||
| // If object has expired, GetECPart returns [meta.ErrObjectIsExpired]. | ||
| // | ||
| // If object exists but tombstoned (e.g. via [StorageEngine.Inhume] or stored | ||
| // tombstone object), GetECPart returns [apistatus.ErrObjectAlreadyRemoved]. | ||
| // | ||
| // If object is marked as garbage (e.g. via [StorageEngine.MarkGarbage]), | ||
| // GetECPart returns [apistatus.ErrObjectNotFound]. | ||
| // | ||
| // If object is locked (e.g. via [StorageEngine.Lock] or stored locker object), | ||
| // GetECPart ignores expiration, tombstone and garbage marks. | ||
| func (e *StorageEngine) GetECPart(cnr cid.ID, parent oid.ID, pi iec.PartInfo) (object.Object, io.ReadCloser, error) { | ||
| if e.metrics != nil { | ||
| defer elapsed(e.metrics.AddGetECPartDuration)() | ||
| } | ||
|
|
||
| e.blockMtx.RLock() | ||
| defer e.blockMtx.RUnlock() | ||
| if e.blockErr != nil { | ||
| return object.Object{}, nil, e.blockErr | ||
| } | ||
|
|
||
| // TODO: sync placement with PUT. They should sort shards equally, but now PUT sorts by part ID. | ||
| // https://github.com/nspcc-dev/neofs-node/issues/3537 | ||
| s := e.sortShardsFn(e, oid.NewAddress(cnr, parent)) | ||
|
|
||
| var partID oid.ID | ||
| loop: | ||
| for i := range s { | ||
| obj, rdr, err := s[i].shardIface.GetECPart(cnr, parent, pi) | ||
| switch { | ||
| case err == nil: | ||
| return obj, rdr, nil | ||
| case errors.Is(err, apistatus.ErrObjectAlreadyRemoved): | ||
| return object.Object{}, nil, err | ||
| case errors.Is(err, meta.ErrObjectIsExpired): | ||
| return object.Object{}, nil, apistatus.ErrObjectNotFound // like Get | ||
| case errors.As(err, (*ierrors.ObjectID)(&partID)): | ||
| if partID.IsZero() { | ||
| panic("zero object ID returned as error") | ||
| } | ||
|
|
||
| e.log.Info("EC part's object ID resolved in shard but reading failed, continue bypassing metabase", | ||
| zap.Stringer("container", cnr), zap.Stringer("parent", parent), | ||
| zap.Int("ecRule", pi.RuleIndex), zap.Int("partIdx", pi.Index), | ||
| zap.Stringer("shardID", s[i].shardIface.ID()), zap.Error(err)) | ||
| // TODO: need report error? Same for other places. https://github.com/nspcc-dev/neofs-node/issues/3538 | ||
|
|
||
| s = s[i+1:] | ||
| break loop | ||
| case errors.Is(err, apistatus.ErrObjectNotFound): | ||
| default: | ||
| e.log.Info("failed to get EC part from shard, ignore error", | ||
| zap.Stringer("container", cnr), zap.Stringer("parent", parent), | ||
| zap.Int("ecRule", pi.RuleIndex), zap.Int("partIdx", pi.Index), | ||
| zap.Stringer("shardID", s[i].shardIface.ID()), zap.Error(err)) | ||
| } | ||
| } | ||
|
|
||
| if partID.IsZero() { | ||
| return object.Object{}, nil, apistatus.ErrObjectNotFound | ||
| } | ||
|
|
||
| for i := range s { | ||
| // get an object bypassing the metabase. We can miss deletion or expiration mark. Get behaves like this, so here too. | ||
| obj, rdr, err := s[i].shardIface.GetStream(oid.NewAddress(cnr, partID), true) | ||
| switch { | ||
| case err == nil: | ||
| return *obj, rdr, nil | ||
| case errors.Is(err, apistatus.ErrObjectNotFound): | ||
| default: | ||
| e.log.Info("failed to get EC part from shard bypassing metabase, ignore error", | ||
| zap.Stringer("container", cnr), zap.Stringer("parent", parent), | ||
| zap.Int("ecRule", pi.RuleIndex), zap.Int("partIdx", pi.Index), | ||
| zap.Stringer("partID", partID), | ||
| zap.Stringer("shardID", s[i].shardIface.ID()), zap.Error(err)) | ||
| } | ||
| } | ||
|
|
||
| return object.Object{}, nil, apistatus.ErrObjectNotFound | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this is done only for unwrapping? will there be such real cases? cant it be more descriptive like
UnreadableObject?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.
unwrapping, yes. We often wrap IDs, like
return fmt.Errorf("failed to handled object %s: %w", id, err). In some cases caller may wish to handle the ID specifically. This allows to get it for free w/o additional return statementi wanna keep it as simple as is, so that each use case can give it a special meaning
may be, this is very generic element
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 meant this is used in
enginepkg and returned only byshardpkg, so maybe that is a good place for it. i do understand that it can be used in the future in some other packages. but ok