2019-09-25 18:12:44 +01:00
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package gracefulexit
import (
"context"
"time"
2019-12-27 11:48:47 +00:00
"storj.io/common/storj"
2021-04-21 13:42:57 +01:00
"storj.io/storj/satellite/metabase"
2019-09-25 18:12:44 +01:00
)
// Progress represents the persisted graceful exit progress record.
type Progress struct {
NodeID storj . NodeID
BytesTransferred int64
PiecesTransferred int64
PiecesFailed int64
UpdatedAt time . Time
}
// TransferQueueItem represents the persisted graceful exit queue record.
type TransferQueueItem struct {
2019-11-13 14:54:50 +00:00
NodeID storj . NodeID
2020-09-03 10:38:54 +01:00
Key metabase . SegmentKey
2019-11-13 14:54:50 +00:00
PieceNum int32
RootPieceID storj . PieceID
DurabilityRatio float64
QueuedAt time . Time
RequestedAt * time . Time
LastFailedAt * time . Time
LastFailedCode * int
FailedCount * int
FinishedAt * time . Time
OrderLimitSendCount int
2019-09-25 18:12:44 +01:00
}
2020-12-05 16:01:42 +00:00
// DB implements CRUD operations for graceful exit service.
2019-09-25 18:12:44 +01:00
//
// architecture: Database
type DB interface {
// IncrementProgress increments transfer stats for a node.
IncrementProgress ( ctx context . Context , nodeID storj . NodeID , bytes int64 , successfulTransfers int64 , failedTransfers int64 ) error
// GetProgress gets a graceful exit progress entry.
GetProgress ( ctx context . Context , nodeID storj . NodeID ) ( * Progress , error )
// Enqueue batch inserts graceful exit transfer queue entries it does not exist.
2021-02-10 18:09:49 +00:00
Enqueue ( ctx context . Context , items [ ] TransferQueueItem , batchSize int ) error
2019-09-25 18:12:44 +01:00
// UpdateTransferQueueItem creates a graceful exit transfer queue entry.
UpdateTransferQueueItem ( ctx context . Context , item TransferQueueItem ) error
// DeleteTransferQueueItem deletes a graceful exit transfer queue entry.
2020-09-03 10:38:54 +01:00
DeleteTransferQueueItem ( ctx context . Context , nodeID storj . NodeID , key metabase . SegmentKey , pieceNum int32 ) error
2019-09-25 18:12:44 +01:00
// DeleteTransferQueueItem deletes a graceful exit transfer queue entries by nodeID.
DeleteTransferQueueItems ( ctx context . Context , nodeID storj . NodeID ) error
2021-01-15 15:34:41 +00:00
// DeleteFinishedTransferQueueItem deletes finished graceful exit transfer queue entries.
2019-09-25 18:12:44 +01:00
DeleteFinishedTransferQueueItems ( ctx context . Context , nodeID storj . NodeID ) error
2021-01-14 15:57:04 +00:00
// DeleteAllFinishedTransferQueueItems deletes all graceful exit transfer
// queue items whose nodes have finished the exit before the indicated time
// returning the total number of deleted items.
2021-02-10 18:09:49 +00:00
DeleteAllFinishedTransferQueueItems ( ctx context . Context , before time . Time , asOfSystemTimeInterval time . Duration , batchSize int ) ( count int64 , err error )
2021-02-17 01:25:25 +00:00
// DeleteFinishedExitProgress deletes exit progress entries for nodes that
// finished exiting before the indicated time, returns number of deleted entries.
2021-02-10 18:09:49 +00:00
DeleteFinishedExitProgress ( ctx context . Context , before time . Time , asOfSystemTimeInterval time . Duration ) ( count int64 , err error )
2021-02-17 01:25:25 +00:00
// GetFinishedExitNodes gets nodes that are marked having finished graceful exit before a given time.
2021-02-10 18:09:49 +00:00
GetFinishedExitNodes ( ctx context . Context , before time . Time , asOfSystemTimeInterval time . Duration ) ( finishedNodes [ ] storj . NodeID , err error )
2019-09-25 18:12:44 +01:00
// GetTransferQueueItem gets a graceful exit transfer queue entry.
2020-09-03 10:38:54 +01:00
GetTransferQueueItem ( ctx context . Context , nodeID storj . NodeID , key metabase . SegmentKey , pieceNum int32 ) ( * TransferQueueItem , error )
2019-10-11 22:18:05 +01:00
// GetIncomplete gets incomplete graceful exit transfer queue entries ordered by durability ratio and queued date ascending.
2019-09-25 18:12:44 +01:00
GetIncomplete ( ctx context . Context , nodeID storj . NodeID , limit int , offset int64 ) ( [ ] * TransferQueueItem , error )
2019-10-11 22:18:05 +01:00
// GetIncompleteNotFailed gets incomplete graceful exit transfer queue entries in the database ordered by durability ratio and queued date ascending.
GetIncompleteNotFailed ( ctx context . Context , nodeID storj . NodeID , limit int , offset int64 ) ( [ ] * TransferQueueItem , error )
// GetIncompleteNotFailed gets incomplete graceful exit transfer queue entries that have failed <= maxFailures times, ordered by durability ratio and queued date ascending.
GetIncompleteFailed ( ctx context . Context , nodeID storj . NodeID , maxFailures int , limit int , offset int64 ) ( [ ] * TransferQueueItem , error )
2019-11-13 14:54:50 +00:00
// IncrementOrderLimitSendCount increments the number of times a node has been sent an order limit for transferring.
2020-09-03 10:38:54 +01:00
IncrementOrderLimitSendCount ( ctx context . Context , nodeID storj . NodeID , key metabase . SegmentKey , pieceNum int32 ) error
2021-01-14 15:57:04 +00:00
// CountFinishedTransferQueueItemsByNode return a map of the nodes which has
// finished the exit before the indicated time but there are at least one item
// left in the transfer queue.
2021-02-10 18:09:49 +00:00
CountFinishedTransferQueueItemsByNode ( ctx context . Context , before time . Time , asOfSystemTimeInterval time . Duration ) ( map [ storj . NodeID ] int64 , error )
2019-09-25 18:12:44 +01:00
}