forked from nspcc-dev/neofs-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 2
Move transformer implementation from frostfs-node #19
Open
fyrchik
wants to merge
12
commits into
TrueCloudLab:master
Choose a base branch
from
fyrchik:move-transformer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c2ea143
[#19] object: Move transformer implementation from node
fyrchik 1e1c836
[#19] transformer: Cover with unit-tests
fyrchik 2af5889
[#19] transformer: Simplify `AccessIdentifiers`
fyrchik fb807e8
[#19] transformer: Make `writeChunk` non-recursive
fyrchik 51bad6d
[#19] transformer: Merge formatter and payload splitter
fyrchik 4917a71
[#19] transformer: Move `EpochSource` to other types
fyrchik 43987aa
[#19] transformer/test: Add helper functions
fyrchik f102456
[#19] transformer/test: Check owner ID and payload hash for parts
fyrchik bf7e56c
[#19] transformer: Do not reuse memory of sent objects
fyrchik 51fedb5
[#19] transformer: Add a target which sends parts to a channel
fyrchik fe394bc
[#19] transformer: Optimize payload hashers a bit
fyrchik e7ee4e1
[#19] transformer: Do not allocate intermeate slice for hashers
fyrchik 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,44 @@ | ||
| package transformer | ||
|
|
||
| import ( | ||
| objectSDK "github.com/TrueCloudLab/frostfs-sdk-go/object" | ||
| "github.com/nspcc-dev/neo-go/pkg/util/slice" | ||
| ) | ||
|
|
||
| type chanTarget struct { | ||
| header *objectSDK.Object | ||
| payload []byte | ||
| ch chan<- *objectSDK.Object | ||
| } | ||
|
|
||
| // NewChannelTarget returns ObjectTarget which writes | ||
| // object parts to a provided channel. | ||
| func NewChannelTarget(ch chan<- *objectSDK.Object) ObjectTarget { | ||
| return &chanTarget{ | ||
| ch: ch, | ||
| } | ||
| } | ||
|
|
||
| // WriteHeader implements the ObjectTarget interface. | ||
| func (c *chanTarget) WriteHeader(object *objectSDK.Object) error { | ||
| c.header = object | ||
| return nil | ||
| } | ||
|
|
||
| // Write implements the ObjectTarget interface. | ||
| func (c *chanTarget) Write(p []byte) (n int, err error) { | ||
| c.payload = append(c.payload, p...) | ||
| return len(p), nil | ||
| } | ||
|
|
||
| // Close implements the ObjectTarget interface. | ||
| func (c *chanTarget) Close() (*AccessIdentifiers, error) { | ||
| if len(c.payload) != 0 { | ||
| c.header.SetPayload(slice.Copy(c.payload)) | ||
| } | ||
| c.ch <- c.header | ||
|
|
||
| c.header = nil | ||
| c.payload = nil | ||
| return new(AccessIdentifiers), nil | ||
| } |
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,55 @@ | ||
| package transformer | ||
|
|
||
| import ( | ||
| "crypto/rand" | ||
| "testing" | ||
|
|
||
| cidtest "github.com/TrueCloudLab/frostfs-sdk-go/container/id/test" | ||
| objectSDK "github.com/TrueCloudLab/frostfs-sdk-go/object" | ||
| "github.com/TrueCloudLab/frostfs-sdk-go/version" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestChannelTarget(t *testing.T) { | ||
| const maxSize = 100 | ||
|
|
||
| ch := make(chan *objectSDK.Object, 10) | ||
| tt := new(testTarget) | ||
|
|
||
| chTarget, _ := newPayloadSizeLimiter(maxSize, NewChannelTarget(ch)) | ||
| testTarget, _ := newPayloadSizeLimiter(maxSize, tt) | ||
|
|
||
| ver := version.Current() | ||
| cnr := cidtest.ID() | ||
| hdr := objectSDK.New() | ||
| hdr.SetContainerID(cnr) | ||
| hdr.SetType(objectSDK.TypeRegular) | ||
| hdr.SetVersion(&ver) | ||
|
|
||
| payload := make([]byte, maxSize*2+maxSize/2) | ||
| _, _ = rand.Read(payload) | ||
|
|
||
| expectedIDs := writeObject(t, testTarget, hdr, payload) | ||
| actualIDs := writeObject(t, chTarget, hdr, payload) | ||
| _ = expectedIDs | ||
| _ = actualIDs | ||
| //require.Equal(t, expectedIDs, actualIDs) | ||
|
|
||
| for i := range tt.objects { | ||
| select { | ||
| case obj := <-ch: | ||
| // Because of the split ID objects can be different. | ||
| // However, payload and attributes must be the same. | ||
| require.Equal(t, tt.objects[i].Payload(), obj.Payload()) | ||
| require.Equal(t, tt.objects[i].Attributes(), obj.Attributes()) | ||
| default: | ||
| require.FailNow(t, "received less parts than expected") | ||
| } | ||
| } | ||
|
|
||
| select { | ||
| case <-ch: | ||
| require.FailNow(t, "received more parts than expected") | ||
| default: | ||
| } | ||
| } |
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,38 @@ | ||
| package transformer | ||
|
|
||
| import ( | ||
| "crypto/sha256" | ||
| "hash" | ||
|
|
||
| "github.com/TrueCloudLab/frostfs-sdk-go/checksum" | ||
| objectSDK "github.com/TrueCloudLab/frostfs-sdk-go/object" | ||
| "github.com/TrueCloudLab/tzhash/tz" | ||
| ) | ||
|
|
||
| type payloadChecksumHasher struct { | ||
| hasher hash.Hash | ||
| typ checksum.Type | ||
| } | ||
|
|
||
| func (h payloadChecksumHasher) writeChecksum(obj *objectSDK.Object) { | ||
| switch h.typ { | ||
| case checksum.SHA256: | ||
| csSHA := [sha256.Size]byte{} | ||
| h.hasher.Sum(csSHA[:0]) | ||
|
|
||
| var cs checksum.Checksum | ||
| cs.SetSHA256(csSHA) | ||
|
|
||
| obj.SetPayloadChecksum(cs) | ||
| case checksum.TZ: | ||
| csTZ := [tz.Size]byte{} | ||
| h.hasher.Sum(csTZ[:0]) | ||
|
|
||
| var cs checksum.Checksum | ||
| cs.SetTillichZemor(csTZ) | ||
|
|
||
| obj.SetPayloadHomomorphicHash(cs) | ||
| default: | ||
| panic("unreachable") | ||
| } | ||
| } | ||
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.
Too tricky i think.