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.
|
// The size of the buffer used by the original payload range reader.
|
||||||
// If it's set to <=0, then `DefaultReaderBufferSize` is used.
|
// If it's set to <=0, then `DefaultReaderBufferSize` is used.
|
||||||
ReaderBufferSize int
|
ReaderBufferSize int
|
||||||
|
|
||||||
|
OriginalPayloadSize uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(prm Params) PatchApplier {
|
func New(prm Params) PatchApplier {
|
||||||
|
@ -99,7 +101,7 @@ func New(prm Params) PatchApplier {
|
||||||
|
|
||||||
hdr: prm.Header,
|
hdr: prm.Header,
|
||||||
|
|
||||||
originalPayloadSize: prm.Header.PayloadSize(),
|
originalPayloadSize: prm.OriginalPayloadSize,
|
||||||
|
|
||||||
readerBuffSize: readerBufferSize,
|
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 {
|
func (p *patcher) copyRange(ctx context.Context, rng *objectSDK.Range) error {
|
||||||
|
var totalWritten int
|
||||||
rdr := p.rangeProvider.GetRange(ctx, rng)
|
rdr := p.rangeProvider.GetRange(ctx, rng)
|
||||||
for {
|
for {
|
||||||
buffOrigPayload := make([]byte, p.readerBuffSize)
|
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)
|
return fmt.Errorf("read: %w", readErr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_, wrErr := p.objectWriter.Write(ctx, buffOrigPayload[:n])
|
wb, wrErr := p.objectWriter.Write(ctx, buffOrigPayload[:n])
|
||||||
if wrErr != nil {
|
if wrErr != nil {
|
||||||
return fmt.Errorf("write: %w", wrErr)
|
return fmt.Errorf("write: %w", wrErr)
|
||||||
}
|
}
|
||||||
|
totalWritten += wb
|
||||||
if readErr == io.EOF {
|
if readErr == io.EOF {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -533,6 +533,37 @@ func TestPatch(t *testing.T) {
|
||||||
originalObjectPayload: []byte("abcdefghijklmnop"),
|
originalObjectPayload: []byte("abcdefghijklmnop"),
|
||||||
patchedPayload: []byte("abcdefgh123lmnop"),
|
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",
|
name: "a few patches: various modifiactions",
|
||||||
patches: []objectSDK.Patch{
|
patches: []objectSDK.Patch{
|
||||||
|
|
Loading…
Reference in a new issue