forked from TrueCloudLab/frostfs-sdk-go
[#XX] debug: debug
Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
parent
98aabc45a7
commit
4d0deb1df1
2 changed files with 37 additions and 2 deletions
|
@ -84,6 +84,8 @@ type Params struct {
|
|||
// The size of the buffer used by the original payload range reader.
|
||||
// If it's set to <=0, then `DefaultReaderBufferSize` is used.
|
||||
ReaderBufferSize int
|
||||
|
||||
OriginalPayloadSize uint64
|
||||
}
|
||||
|
||||
func New(prm Params) PatchApplier {
|
||||
|
@ -99,7 +101,7 @@ func New(prm Params) PatchApplier {
|
|||
|
||||
hdr: prm.Header,
|
||||
|
||||
originalPayloadSize: prm.Header.PayloadSize(),
|
||||
originalPayloadSize: prm.OriginalPayloadSize,
|
||||
|
||||
readerBuffSize: readerBufferSize,
|
||||
}
|
||||
|
@ -169,6 +171,7 @@ func (p *patcher) Close(ctx context.Context) (PatchRes, error) {
|
|||
}
|
||||
|
||||
func (p *patcher) copyRange(ctx context.Context, rng *objectSDK.Range) error {
|
||||
var totalWritten int
|
||||
rdr := p.rangeProvider.GetRange(ctx, rng)
|
||||
for {
|
||||
buffOrigPayload := make([]byte, p.readerBuffSize)
|
||||
|
@ -178,10 +181,11 @@ func (p *patcher) copyRange(ctx context.Context, rng *objectSDK.Range) error {
|
|||
return fmt.Errorf("read: %w", readErr)
|
||||
}
|
||||
}
|
||||
_, wrErr := p.objectWriter.Write(ctx, buffOrigPayload[:n])
|
||||
wb, wrErr := p.objectWriter.Write(ctx, buffOrigPayload[:n])
|
||||
if wrErr != nil {
|
||||
return fmt.Errorf("write: %w", wrErr)
|
||||
}
|
||||
totalWritten += wb
|
||||
if readErr == io.EOF {
|
||||
break
|
||||
}
|
||||
|
|
|
@ -533,6 +533,37 @@ func TestPatch(t *testing.T) {
|
|||
originalObjectPayload: []byte("abcdefghijklmnop"),
|
||||
patchedPayload: []byte("abcdefgh123lmnop"),
|
||||
},
|
||||
{
|
||||
name: "starting from the same offset",
|
||||
patches: []objectSDK.Patch{
|
||||
{
|
||||
PayloadPatch: &objectSDK.PayloadPatch{
|
||||
Range: rangeWithOffestWithLength(5, 8),
|
||||
Chunk: []byte("12"),
|
||||
},
|
||||
},
|
||||
{
|
||||
PayloadPatch: &objectSDK.PayloadPatch{
|
||||
Range: rangeWithOffestWithLength(13, 0),
|
||||
Chunk: []byte("34"),
|
||||
},
|
||||
},
|
||||
{
|
||||
PayloadPatch: &objectSDK.PayloadPatch{
|
||||
Range: rangeWithOffestWithLength(13, 0),
|
||||
Chunk: []byte("56"),
|
||||
},
|
||||
},
|
||||
{
|
||||
PayloadPatch: &objectSDK.PayloadPatch{
|
||||
Range: rangeWithOffestWithLength(13, 0),
|
||||
Chunk: []byte("78"),
|
||||
},
|
||||
},
|
||||
},
|
||||
originalObjectPayload: []byte("abcdefghabcdefgh"),
|
||||
patchedPayload: []byte("abcdefgh123lmnop"),
|
||||
},
|
||||
{
|
||||
name: "a few patches: various modifiactions",
|
||||
patches: []objectSDK.Patch{
|
||||
|
|
Loading…
Reference in a new issue