satellite/satellitedb: outline for batch insert
Part of https://github.com/storj/storj/issues/4727 Change-Id: I1a9ad3b009f363e37f5e68e810074eecb7448db3
This commit is contained in:
parent
05d9c7940d
commit
10d71a8a3c
43
satellite/repair/queue/insertbuffer.go
Normal file
43
satellite/repair/queue/insertbuffer.go
Normal file
@ -0,0 +1,43 @@
|
||||
// Copyright (C) 2022 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package queue
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
// InsertBuffer exposes a synchronous API to buffer a batch of segments
|
||||
// and insert them at once. Not threadsafe. Call Flush() before discarding.
|
||||
//
|
||||
//lint:ignore U1000 unused skeleton code
|
||||
type InsertBuffer struct {
|
||||
queue RepairQueue //nolint
|
||||
batchSize int //nolint
|
||||
batch []*InjuredSegment //nolint
|
||||
// newInsertCallbacks contains callback called when the InjuredSegment
|
||||
// is flushed to the queue and it is determined that it wasn't already queued for repair.
|
||||
// This is made to collect metrics.
|
||||
newInsertCallbacks map[*InjuredSegment]func() //nolint
|
||||
}
|
||||
|
||||
// Insert adds a segment to the batch of the next insert,
|
||||
// and does a synchronous database insert when the batch size is reached.
|
||||
// When it is determined that this segment is newly queued, firstInsertCallback is called.
|
||||
// for the purpose of metrics.
|
||||
//
|
||||
//lint:ignore U1000 skeleton code
|
||||
func (r *InsertBuffer) Insert(
|
||||
ctx context.Context,
|
||||
segment *InjuredSegment,
|
||||
newInsertCallback func(),
|
||||
) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
// Flush inserts the remaining segments into the database.
|
||||
//
|
||||
//lint:ignore U1000 skeleton code
|
||||
func (r *InsertBuffer) Flush(ctx context.Context) (err error) {
|
||||
return err
|
||||
}
|
@ -30,6 +30,8 @@ type InjuredSegment struct {
|
||||
type RepairQueue interface {
|
||||
// Insert adds an injured segment.
|
||||
Insert(ctx context.Context, s *InjuredSegment) (alreadyInserted bool, err error)
|
||||
// InsertBatch adds multiple injured segments
|
||||
InsertBatch(ctx context.Context, segments []*InjuredSegment) (newlyInsertedSegments []*InjuredSegment, err error)
|
||||
// Select gets an injured segment.
|
||||
Select(ctx context.Context) (*InjuredSegment, error)
|
||||
// Delete removes an injured segment.
|
||||
|
@ -87,6 +87,10 @@ func (r *repairQueue) Insert(ctx context.Context, seg *queue.InjuredSegment) (al
|
||||
return alreadyInserted, rows.Err()
|
||||
}
|
||||
|
||||
func (r *repairQueue) InsertBatch(ctx context.Context, segments []*queue.InjuredSegment) (newlyInsertedSegments []*queue.InjuredSegment, err error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (r *repairQueue) Select(ctx context.Context) (seg *queue.InjuredSegment, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user