Evgenii Stratonikov
74e11b3cf3
All checks were successful
DCO action / DCO (pull_request) Successful in 37s
Tests and linters / Run gofumpt (pull_request) Successful in 34s
Vulncheck / Vulncheck (pull_request) Successful in 1m10s
Build / Build Components (pull_request) Successful in 1m55s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m5s
Tests and linters / Staticcheck (pull_request) Successful in 2m19s
Tests and linters / Tests (pull_request) Successful in 2m50s
Tests and linters / Lint (pull_request) Successful in 3m6s
Tests and linters / gopls check (pull_request) Successful in 3m4s
Tests and linters / Tests with -race (pull_request) Successful in 3m24s
Previously, `ln` was only set once, so search has really worked for small number of objects. Fix panic: ``` panic: runtime error: slice bounds out of range [:43690] with capacity 21238 goroutine 6859775 [running]: git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object.(*searchStreamMsgSizeCtrl).Send(0xc001eec8d0, 0xc005734000) git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/transport_splitter.go:173 +0x1f0 git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/search/v2.(*streamWriter).WriteIDs(0xc000520320, {0xc00eb1a000, 0x4fd9c, 0x7fd6475a9a68?}) git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/search/v2/streamer.go:28 +0x155 git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/search.(*uniqueIDWriter).WriteIDs(0xc001386420, {0xc00eb1a000?, 0xc0013ea9c0?, 0x113eef3?}) git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/search/util.go:62 +0x202 git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/search.(*execCtx).writeIDList(0xc00011aa38?, {0xc00eb1a000?, 0xc001eec9f0?, 0xc0008f4380?}) git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/search/exec.go:68 +0x91 git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/search.(*execCtx).executeLocal(0xc0008f4380, {0x176c538, 0xc001eec9f0}) git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/search/local.go:18 +0x16b ``` Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
189 lines
4.2 KiB
Go
189 lines
4.2 KiB
Go
package object
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/util"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/object"
|
|
)
|
|
|
|
type (
|
|
TransportSplitter struct {
|
|
next ServiceServer
|
|
|
|
chunkSize uint64
|
|
addrAmount uint64
|
|
}
|
|
|
|
getStreamMsgSizeCtrl struct {
|
|
util.ServerStream
|
|
|
|
stream GetObjectStream
|
|
|
|
chunkSize int
|
|
}
|
|
|
|
searchStreamMsgSizeCtrl struct {
|
|
util.ServerStream
|
|
|
|
stream SearchStream
|
|
|
|
addrAmount uint64
|
|
}
|
|
|
|
rangeStreamMsgSizeCtrl struct {
|
|
util.ServerStream
|
|
|
|
stream GetObjectRangeStream
|
|
|
|
chunkSize int
|
|
}
|
|
)
|
|
|
|
func (s *getStreamMsgSizeCtrl) Send(resp *object.GetResponse) error {
|
|
body := resp.GetBody()
|
|
|
|
part := body.GetObjectPart()
|
|
|
|
chunkPart, ok := part.(*object.GetObjectPartChunk)
|
|
if !ok {
|
|
return s.stream.Send(resp)
|
|
}
|
|
|
|
var newResp *object.GetResponse
|
|
|
|
for buf := bytes.NewBuffer(chunkPart.GetChunk()); buf.Len() > 0; {
|
|
if newResp == nil {
|
|
newResp = new(object.GetResponse)
|
|
newResp.SetBody(body)
|
|
}
|
|
|
|
chunkPart.SetChunk(buf.Next(s.chunkSize))
|
|
newResp.SetMetaHeader(resp.GetMetaHeader())
|
|
newResp.SetVerificationHeader(resp.GetVerificationHeader())
|
|
|
|
if err := s.stream.Send(newResp); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func NewTransportSplitter(size, amount uint64, next ServiceServer) *TransportSplitter {
|
|
return &TransportSplitter{
|
|
next: next,
|
|
chunkSize: size,
|
|
addrAmount: amount,
|
|
}
|
|
}
|
|
|
|
func (c *TransportSplitter) Get(req *object.GetRequest, stream GetObjectStream) error {
|
|
return c.next.Get(req, &getStreamMsgSizeCtrl{
|
|
ServerStream: stream,
|
|
stream: stream,
|
|
chunkSize: int(c.chunkSize),
|
|
})
|
|
}
|
|
|
|
func (c TransportSplitter) Put(ctx context.Context) (PutObjectStream, error) {
|
|
return c.next.Put(ctx)
|
|
}
|
|
|
|
func (c TransportSplitter) Patch(ctx context.Context) (PatchObjectStream, error) {
|
|
return c.next.Patch(ctx)
|
|
}
|
|
|
|
func (c TransportSplitter) Head(ctx context.Context, request *object.HeadRequest) (*object.HeadResponse, error) {
|
|
return c.next.Head(ctx, request)
|
|
}
|
|
|
|
func (c TransportSplitter) Search(req *object.SearchRequest, stream SearchStream) error {
|
|
return c.next.Search(req, &searchStreamMsgSizeCtrl{
|
|
ServerStream: stream,
|
|
stream: stream,
|
|
addrAmount: c.addrAmount,
|
|
})
|
|
}
|
|
|
|
func (c TransportSplitter) Delete(ctx context.Context, request *object.DeleteRequest) (*object.DeleteResponse, error) {
|
|
return c.next.Delete(ctx, request)
|
|
}
|
|
|
|
func (c TransportSplitter) PutSingle(ctx context.Context, req *object.PutSingleRequest) (*object.PutSingleResponse, error) {
|
|
return c.next.PutSingle(ctx, req)
|
|
}
|
|
|
|
func (s *rangeStreamMsgSizeCtrl) Send(resp *object.GetRangeResponse) error {
|
|
body := resp.GetBody()
|
|
|
|
chunkPart, ok := body.GetRangePart().(*object.GetRangePartChunk)
|
|
if !ok {
|
|
return s.stream.Send(resp)
|
|
}
|
|
|
|
var newResp *object.GetRangeResponse
|
|
|
|
for buf := bytes.NewBuffer(chunkPart.GetChunk()); buf.Len() > 0; {
|
|
if newResp == nil {
|
|
newResp = new(object.GetRangeResponse)
|
|
newResp.SetBody(body)
|
|
}
|
|
|
|
chunkPart.SetChunk(buf.Next(s.chunkSize))
|
|
body.SetRangePart(chunkPart)
|
|
newResp.SetMetaHeader(resp.GetMetaHeader())
|
|
newResp.SetVerificationHeader(resp.GetVerificationHeader())
|
|
|
|
if err := s.stream.Send(newResp); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (c TransportSplitter) GetRange(req *object.GetRangeRequest, stream GetObjectRangeStream) error {
|
|
return c.next.GetRange(req, &rangeStreamMsgSizeCtrl{
|
|
ServerStream: stream,
|
|
stream: stream,
|
|
chunkSize: int(c.chunkSize),
|
|
})
|
|
}
|
|
|
|
func (c TransportSplitter) GetRangeHash(ctx context.Context, request *object.GetRangeHashRequest) (*object.GetRangeHashResponse, error) {
|
|
return c.next.GetRangeHash(ctx, request)
|
|
}
|
|
|
|
func (s *searchStreamMsgSizeCtrl) Send(resp *object.SearchResponse) error {
|
|
body := resp.GetBody()
|
|
ids := body.GetIDList()
|
|
|
|
var newResp *object.SearchResponse
|
|
|
|
for {
|
|
if newResp == nil {
|
|
newResp = new(object.SearchResponse)
|
|
newResp.SetBody(body)
|
|
}
|
|
|
|
cut := min(s.addrAmount, uint64(len(ids)))
|
|
|
|
body.SetIDList(ids[:cut])
|
|
newResp.SetMetaHeader(resp.GetMetaHeader())
|
|
newResp.SetVerificationHeader(resp.GetVerificationHeader())
|
|
|
|
if err := s.stream.Send(newResp); err != nil {
|
|
return err
|
|
}
|
|
|
|
ids = ids[cut:]
|
|
|
|
if len(ids) == 0 {
|
|
break
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|