Skip to content

Commit

Permalink
satellite/metabase: split out CommitInlineSegment for db adapters
Browse files Browse the repository at this point in the history
Change-Id: I6d1e8fed09d73002a8aa0fefd2a3bda3a4713dd5
  • Loading branch information
thepaul authored and Storj Robot committed May 6, 2024
1 parent d7f7d1c commit 094d27b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions satellite/metabase/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Adapter interface {
IterateLoopSegments(ctx context.Context, aliasCache *NodeAliasCache, opts IterateLoopSegments, fn func(context.Context, LoopSegmentsIterator) error) error
PendingObjectExists(ctx context.Context, opts BeginSegment) (exists bool, err error)
CommitPendingObjectSegment(ctx context.Context, opts CommitSegment, aliasPieces AliasPieces) error
CommitInlineSegment(ctx context.Context, opts CommitInlineSegment) error
TestingBeginObjectExactVersion(ctx context.Context, opts BeginObjectExactVersion, object *Object) error

GetTableStats(ctx context.Context, opts GetTableStats) (result TableStats, err error)
Expand Down
26 changes: 21 additions & 5 deletions satellite/metabase/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,22 @@ func (db *DB) CommitInlineSegment(ctx context.Context, opts CommitInlineSegment)
return ErrInvalidRequest.New("PlainOffset negative")
}

_, err = db.db.ExecContext(ctx, `
err = db.ChooseAdapter(opts.ProjectID).CommitInlineSegment(ctx, opts)
if err != nil {
if ErrPendingObjectMissing.Has(err) {
return err
}
return Error.New("unable to insert segment: %w", err)
}
mon.Meter("segment_commit").Mark(1)
mon.IntVal("segment_commit_encrypted_size").Observe(int64(len(opts.InlineData)))

return nil
}

// CommitInlineSegment commits inline segment to the database.
func (p *PostgresAdapter) CommitInlineSegment(ctx context.Context, opts CommitInlineSegment) (err error) {
_, err = p.db.ExecContext(ctx, `
INSERT INTO segments (
stream_id, position, expires_at,
root_piece_id, encrypted_key_nonce, encrypted_key,
Expand Down Expand Up @@ -609,13 +624,14 @@ func (db *DB) CommitInlineSegment(ctx context.Context, opts CommitInlineSegment)
if code := pgerrcode.FromError(err); code == pgxerrcode.NotNullViolation {
return ErrPendingObjectMissing.New("")
}
return Error.New("unable to insert segment: %w", err)
}

mon.Meter("segment_commit").Mark(1)
mon.IntVal("segment_commit_encrypted_size").Observe(int64(len(opts.InlineData)))
return Error.Wrap(err)
}

return nil
// CommitInlineSegment commits inline segment to the database.
func (s *SpannerAdapter) CommitInlineSegment(ctx context.Context, opts CommitInlineSegment) error {
panic("implement me")
}

// CommitObject contains arguments necessary for committing an object.
Expand Down

0 comments on commit 094d27b

Please sign in to comment.