2019-10-01 15:34:03 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package satellites
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/storj"
|
2019-10-01 15:34:03 +01:00
|
|
|
)
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// Status refers to the state of the relationship with a satellites.
|
2019-10-01 15:34:03 +01:00
|
|
|
type Status = int
|
|
|
|
|
|
|
|
const (
|
2020-08-11 15:50:01 +01:00
|
|
|
//Unexpected status should not be used for sanity checking.
|
2019-10-01 15:34:03 +01:00
|
|
|
Unexpected Status = 0
|
2020-08-11 15:50:01 +01:00
|
|
|
//Normal status reflects a lack of graceful exit.
|
2019-10-01 15:34:03 +01:00
|
|
|
Normal = 1
|
2020-08-11 15:50:01 +01:00
|
|
|
//Exiting reflects an active graceful exit.
|
2019-10-01 15:34:03 +01:00
|
|
|
Exiting = 2
|
2020-08-11 15:50:01 +01:00
|
|
|
//ExitSucceeded reflects a graceful exit that succeeded.
|
2019-10-01 15:34:03 +01:00
|
|
|
ExitSucceeded = 3
|
2020-08-11 15:50:01 +01:00
|
|
|
//ExitFailed reflects a graceful exit that failed.
|
2019-10-01 15:34:03 +01:00
|
|
|
ExitFailed = 4
|
|
|
|
)
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// ExitProgress contains the status of a graceful exit.
|
2019-10-01 15:34:03 +01:00
|
|
|
type ExitProgress struct {
|
|
|
|
SatelliteID storj.NodeID
|
|
|
|
InitiatedAt *time.Time
|
|
|
|
FinishedAt *time.Time
|
|
|
|
StartingDiskUsage int64
|
|
|
|
BytesDeleted int64
|
|
|
|
CompletionReceipt []byte
|
2020-01-14 17:23:09 +00:00
|
|
|
Status int32
|
2019-10-01 15:34:03 +01:00
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// Satellite contains the satellite and status.
|
2019-10-28 17:59:45 +00:00
|
|
|
type Satellite struct {
|
|
|
|
SatelliteID storj.NodeID
|
|
|
|
AddedAt time.Time
|
|
|
|
Status int32
|
|
|
|
}
|
|
|
|
|
2019-10-01 15:34:03 +01:00
|
|
|
// DB works with satellite database
|
|
|
|
//
|
|
|
|
// architecture: Database
|
|
|
|
type DB interface {
|
2019-10-28 17:59:45 +00:00
|
|
|
// GetSatellite retrieves that satellite by ID
|
|
|
|
GetSatellite(ctx context.Context, satelliteID storj.NodeID) (satellite Satellite, err error)
|
2019-10-01 15:34:03 +01:00
|
|
|
// InitiateGracefulExit updates the database to reflect the beginning of a graceful exit
|
|
|
|
InitiateGracefulExit(ctx context.Context, satelliteID storj.NodeID, intitiatedAt time.Time, startingDiskUsage int64) error
|
2020-01-08 02:33:41 +00:00
|
|
|
// CancelGracefulExit removes that satellite by ID
|
|
|
|
CancelGracefulExit(ctx context.Context, satelliteID storj.NodeID) error
|
2019-10-01 15:34:03 +01:00
|
|
|
// UpdateGracefulExit increments the total bytes deleted during a graceful exit
|
|
|
|
UpdateGracefulExit(ctx context.Context, satelliteID storj.NodeID, bytesDeleted int64) error
|
|
|
|
// CompleteGracefulExit updates the database when a graceful exit is completed or failed
|
|
|
|
CompleteGracefulExit(ctx context.Context, satelliteID storj.NodeID, finishedAt time.Time, exitStatus Status, completionReceipt []byte) error
|
|
|
|
// ListGracefulExits lists all graceful exit records
|
|
|
|
ListGracefulExits(ctx context.Context) ([]ExitProgress, error)
|
|
|
|
}
|