2020-09-30 08:39:45 +00:00
|
|
|
package object
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/util"
|
2024-11-07 14:32:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/object"
|
2020-09-30 08:39:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
TransportSplitter struct {
|
2020-12-02 23:45:25 +00:00
|
|
|
next ServiceServer
|
2020-09-30 08:39:45 +00:00
|
|
|
|
|
|
|
chunkSize uint64
|
|
|
|
addrAmount uint64
|
|
|
|
}
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
getStreamMsgSizeCtrl struct {
|
|
|
|
util.ServerStream
|
|
|
|
|
|
|
|
stream GetObjectStream
|
|
|
|
|
2020-09-30 08:39:45 +00:00
|
|
|
chunkSize int
|
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
searchStreamMsgSizeCtrl struct {
|
|
|
|
util.ServerStream
|
|
|
|
|
|
|
|
stream SearchStream
|
|
|
|
|
2020-09-30 08:39:45 +00:00
|
|
|
addrAmount uint64
|
|
|
|
}
|
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
rangeStreamMsgSizeCtrl struct {
|
|
|
|
util.ServerStream
|
|
|
|
|
|
|
|
stream GetObjectRangeStream
|
|
|
|
|
2020-09-30 08:39:45 +00:00
|
|
|
chunkSize int
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
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 {
|
2020-09-30 08:39:45 +00:00
|
|
|
return &TransportSplitter{
|
|
|
|
next: next,
|
|
|
|
chunkSize: size,
|
|
|
|
addrAmount: amount,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
func (c *TransportSplitter) Get(req *object.GetRequest, stream GetObjectStream) error {
|
|
|
|
return c.next.Get(req, &getStreamMsgSizeCtrl{
|
|
|
|
ServerStream: stream,
|
|
|
|
stream: stream,
|
|
|
|
chunkSize: int(c.chunkSize),
|
|
|
|
})
|
2020-09-30 08:39:45 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 11:23:53 +00:00
|
|
|
func (c TransportSplitter) Put() (PutObjectStream, error) {
|
|
|
|
return c.next.Put()
|
2020-09-30 08:39:45 +00:00
|
|
|
}
|
|
|
|
|
2024-08-12 14:11:10 +00:00
|
|
|
func (c TransportSplitter) Patch() (PatchObjectStream, error) {
|
2024-08-12 10:01:57 +00:00
|
|
|
return c.next.Patch()
|
|
|
|
}
|
|
|
|
|
2020-09-30 08:39:45 +00:00
|
|
|
func (c TransportSplitter) Head(ctx context.Context, request *object.HeadRequest) (*object.HeadResponse, error) {
|
|
|
|
return c.next.Head(ctx, request)
|
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
func (c TransportSplitter) Search(req *object.SearchRequest, stream SearchStream) error {
|
|
|
|
return c.next.Search(req, &searchStreamMsgSizeCtrl{
|
|
|
|
ServerStream: stream,
|
|
|
|
stream: stream,
|
|
|
|
addrAmount: c.addrAmount,
|
|
|
|
})
|
2020-09-30 08:39:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c TransportSplitter) Delete(ctx context.Context, request *object.DeleteRequest) (*object.DeleteResponse, error) {
|
|
|
|
return c.next.Delete(ctx, request)
|
|
|
|
}
|
|
|
|
|
2023-07-03 08:36:20 +00:00
|
|
|
func (c TransportSplitter) PutSingle(ctx context.Context, req *object.PutSingleRequest) (*object.PutSingleResponse, error) {
|
|
|
|
return c.next.PutSingle(ctx, req)
|
|
|
|
}
|
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
func (s *rangeStreamMsgSizeCtrl) Send(resp *object.GetRangeResponse) error {
|
|
|
|
body := resp.GetBody()
|
2020-09-30 08:39:45 +00:00
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
chunkPart, ok := body.GetRangePart().(*object.GetRangePartChunk)
|
|
|
|
if !ok {
|
|
|
|
return s.stream.Send(resp)
|
|
|
|
}
|
2020-09-30 08:39:45 +00:00
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
var newResp *object.GetRangeResponse
|
2020-09-30 08:39:45 +00:00
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
for buf := bytes.NewBuffer(chunkPart.GetChunk()); buf.Len() > 0; {
|
|
|
|
if newResp == nil {
|
|
|
|
newResp = new(object.GetRangeResponse)
|
|
|
|
newResp.SetBody(body)
|
2020-09-30 08:39:45 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
chunkPart.SetChunk(buf.Next(s.chunkSize))
|
|
|
|
body.SetRangePart(chunkPart)
|
|
|
|
newResp.SetMetaHeader(resp.GetMetaHeader())
|
|
|
|
newResp.SetVerificationHeader(resp.GetVerificationHeader())
|
2020-09-30 08:39:45 +00:00
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
if err := s.stream.Send(newResp); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-09-30 08:39:45 +00:00
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-09-30 08:39:45 +00:00
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
func (c TransportSplitter) GetRange(req *object.GetRangeRequest, stream GetObjectRangeStream) error {
|
|
|
|
return c.next.GetRange(req, &rangeStreamMsgSizeCtrl{
|
|
|
|
ServerStream: stream,
|
|
|
|
stream: stream,
|
|
|
|
chunkSize: int(c.chunkSize),
|
|
|
|
})
|
|
|
|
}
|
2020-09-30 08:39:45 +00:00
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
func (c TransportSplitter) GetRangeHash(ctx context.Context, request *object.GetRangeHashRequest) (*object.GetRangeHashResponse, error) {
|
|
|
|
return c.next.GetRangeHash(ctx, request)
|
2020-09-30 08:39:45 +00:00
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
func (s *searchStreamMsgSizeCtrl) Send(resp *object.SearchResponse) error {
|
|
|
|
body := resp.GetBody()
|
|
|
|
ids := body.GetIDList()
|
2020-09-30 08:39:45 +00:00
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
var newResp *object.SearchResponse
|
2020-09-30 08:39:45 +00:00
|
|
|
|
2022-01-10 09:19:08 +00:00
|
|
|
for ln := uint64(len(ids)); ; {
|
2020-12-10 12:26:40 +00:00
|
|
|
if newResp == nil {
|
|
|
|
newResp = new(object.SearchResponse)
|
|
|
|
newResp.SetBody(body)
|
|
|
|
}
|
2020-09-30 08:39:45 +00:00
|
|
|
|
2024-04-10 11:16:18 +00:00
|
|
|
cut := min(s.addrAmount, ln)
|
2020-12-10 12:26:40 +00:00
|
|
|
|
|
|
|
body.SetIDList(ids[:cut])
|
|
|
|
newResp.SetMetaHeader(resp.GetMetaHeader())
|
|
|
|
newResp.SetVerificationHeader(resp.GetVerificationHeader())
|
2020-09-30 08:39:45 +00:00
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
if err := s.stream.Send(newResp); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-09-30 08:39:45 +00:00
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
ids = ids[cut:]
|
2022-01-10 09:19:08 +00:00
|
|
|
|
|
|
|
if len(ids) == 0 {
|
|
|
|
break
|
|
|
|
}
|
2020-09-30 08:39:45 +00:00
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
return nil
|
2020-09-30 08:39:45 +00:00
|
|
|
}
|