satellite/metainfo: reduce database hits for segment creation

Change-Id: I48a748b48daefa95f1dfbf6a0d75e65a568ee36a
This commit is contained in:
JT Olio 2023-12-01 13:44:17 -05:00 committed by Storj Robot
parent 5d492a9e01
commit 591971b4dc
3 changed files with 27 additions and 14 deletions

View File

@ -224,6 +224,8 @@ type BeginSegment struct {
RootPieceID storj.PieceID RootPieceID storj.PieceID
Pieces Pieces Pieces Pieces
ObjectExistsChecked bool
} }
// BeginSegment verifies, whether a new segment upload can be started. // BeginSegment verifies, whether a new segment upload can be started.
@ -242,8 +244,10 @@ func (db *DB) BeginSegment(ctx context.Context, opts BeginSegment) (err error) {
return ErrInvalidRequest.New("RootPieceID missing") return ErrInvalidRequest.New("RootPieceID missing")
} }
// NOTE: this isn't strictly necessary, since we can also fail this in CommitSegment. if !opts.ObjectExistsChecked {
// however, we should prevent creating segements for non-partial objects. // NOTE: Find a way to safely remove this. This isn't strictly necessary,
// since we can also fail this in CommitSegment.
// We should prevent creating segements for non-partial objects.
// Verify that object exists and is partial. // Verify that object exists and is partial.
var exists bool var exists bool
@ -261,6 +265,7 @@ func (db *DB) BeginSegment(ctx context.Context, opts BeginSegment) (err error) {
if !exists { if !exists {
return ErrPendingObjectMissing.New("") return ErrPendingObjectMissing.New("")
} }
}
mon.Meter("segment_begin").Mark(1) mon.Meter("segment_begin").Mark(1)

View File

@ -226,11 +226,13 @@ func (endpoint *Endpoint) Batch(ctx context.Context, req *pb.BatchRequest) (resp
case *pb.BatchRequestItem_SegmentBegin: case *pb.BatchRequestItem_SegmentBegin:
singleRequest.SegmentBegin.Header = req.Header singleRequest.SegmentBegin.Header = req.Header
justCreatedObject := false
if singleRequest.SegmentBegin.StreamId.IsZero() && !lastStreamID.IsZero() { if singleRequest.SegmentBegin.StreamId.IsZero() && !lastStreamID.IsZero() {
singleRequest.SegmentBegin.StreamId = lastStreamID singleRequest.SegmentBegin.StreamId = lastStreamID
justCreatedObject = true
} }
response, err := endpoint.BeginSegment(ctx, singleRequest.SegmentBegin) response, err := endpoint.beginSegment(ctx, singleRequest.SegmentBegin, justCreatedObject)
if err != nil { if err != nil {
return resp, err return resp, err
} }

View File

@ -31,6 +31,11 @@ func calculateSpaceUsed(segmentSize int64, numberOfPieces int, rs storj.Redundan
// BeginSegment begins segment uploading. // BeginSegment begins segment uploading.
func (endpoint *Endpoint) BeginSegment(ctx context.Context, req *pb.SegmentBeginRequest) (resp *pb.SegmentBeginResponse, err error) { func (endpoint *Endpoint) BeginSegment(ctx context.Context, req *pb.SegmentBeginRequest) (resp *pb.SegmentBeginResponse, err error) {
defer mon.Task()(&ctx)(&err) defer mon.Task()(&ctx)(&err)
return endpoint.beginSegment(ctx, req, false)
}
func (endpoint *Endpoint) beginSegment(ctx context.Context, req *pb.SegmentBeginRequest, objectJustCreated bool) (resp *pb.SegmentBeginResponse, err error) {
defer mon.Task()(&ctx)(&err)
endpoint.versionCollector.collect(req.Header.UserAgent, mon.Func().ShortName()) endpoint.versionCollector.collect(req.Header.UserAgent, mon.Func().ShortName())
@ -123,6 +128,7 @@ func (endpoint *Endpoint) BeginSegment(ctx context.Context, req *pb.SegmentBegin
}, },
RootPieceID: rootPieceID, RootPieceID: rootPieceID,
Pieces: pieces, Pieces: pieces,
ObjectExistsChecked: objectJustCreated,
}) })
if err != nil { if err != nil {
return nil, endpoint.convertMetabaseErr(err) return nil, endpoint.convertMetabaseErr(err)