2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-10-02 00:25:41 +01:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package queue
|
|
|
|
|
|
|
|
import (
|
2018-12-27 09:56:25 +00:00
|
|
|
"context"
|
2020-09-09 21:52:22 +01:00
|
|
|
"time"
|
2018-12-27 09:56:25 +00:00
|
|
|
|
2021-06-17 16:05:04 +01:00
|
|
|
"storj.io/common/uuid"
|
|
|
|
"storj.io/storj/satellite/metabase"
|
2018-10-02 00:25:41 +01:00
|
|
|
)
|
|
|
|
|
2021-06-17 16:05:04 +01:00
|
|
|
// InjuredSegment contains information about segment which
|
|
|
|
// should be repaired.
|
|
|
|
type InjuredSegment struct {
|
|
|
|
StreamID uuid.UUID
|
|
|
|
Position metabase.SegmentPosition
|
|
|
|
|
|
|
|
SegmentHealth float64
|
|
|
|
AttemptedAt *time.Time
|
|
|
|
UpdatedAt time.Time
|
|
|
|
InsertedAt time.Time
|
|
|
|
}
|
|
|
|
|
2019-01-02 17:53:27 +00:00
|
|
|
// RepairQueue implements queueing for segments that need repairing.
|
2019-04-22 11:35:52 +01:00
|
|
|
// Implementation can be found at satellite/satellitedb/repairqueue.go.
|
2019-09-10 14:24:16 +01:00
|
|
|
//
|
|
|
|
// architecture: Database
|
2018-10-02 00:25:41 +01:00
|
|
|
type RepairQueue interface {
|
2019-04-16 19:14:09 +01:00
|
|
|
// Insert adds an injured segment.
|
2021-06-17 16:05:04 +01:00
|
|
|
Insert(ctx context.Context, s *InjuredSegment) (alreadyInserted bool, err error)
|
2022-04-19 07:37:40 +01:00
|
|
|
// InsertBatch adds multiple injured segments
|
|
|
|
InsertBatch(ctx context.Context, segments []*InjuredSegment) (newlyInsertedSegments []*InjuredSegment, err error)
|
2019-04-16 19:14:09 +01:00
|
|
|
// Select gets an injured segment.
|
2021-06-17 16:05:04 +01:00
|
|
|
Select(ctx context.Context) (*InjuredSegment, error)
|
2019-04-16 19:14:09 +01:00
|
|
|
// Delete removes an injured segment.
|
2021-06-17 16:05:04 +01:00
|
|
|
Delete(ctx context.Context, s *InjuredSegment) error
|
2020-09-09 21:52:22 +01:00
|
|
|
// Clean removes all segments last updated before a certain time
|
|
|
|
Clean(ctx context.Context, before time.Time) (deleted int64, err error)
|
2019-04-16 19:14:09 +01:00
|
|
|
// SelectN lists limit amount of injured segments.
|
2021-06-17 16:05:04 +01:00
|
|
|
SelectN(ctx context.Context, limit int) ([]InjuredSegment, error)
|
2019-07-30 16:21:40 +01:00
|
|
|
// Count counts the number of segments in the repair queue.
|
|
|
|
Count(ctx context.Context) (count int, err error)
|
2020-11-28 16:23:39 +00:00
|
|
|
|
2021-06-17 16:05:04 +01:00
|
|
|
// TestingSetAttemptedTime sets attempted time for a segment.
|
|
|
|
TestingSetAttemptedTime(ctx context.Context, streamID uuid.UUID, position metabase.SegmentPosition, t time.Time) (rowsAffected int64, err error)
|
2018-10-02 00:25:41 +01:00
|
|
|
}
|