2018-07-27 22:11:44 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package statdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2018-11-30 13:40:13 +00:00
|
|
|
"storj.io/storj/pkg/storj"
|
2018-07-27 22:11:44 +01:00
|
|
|
)
|
|
|
|
|
2018-12-14 20:17:30 +00:00
|
|
|
// DB interface for database operations
|
|
|
|
type DB interface {
|
|
|
|
// Create a db entry for the provided storagenode
|
2018-12-19 18:44:03 +00:00
|
|
|
Create(ctx context.Context, nodeID storj.NodeID, startingStats *NodeStats) (stats *NodeStats, err error)
|
2018-10-08 23:15:54 +01:00
|
|
|
|
2018-12-14 20:17:30 +00:00
|
|
|
// Get a storagenode's stats from the db
|
2018-12-19 18:44:03 +00:00
|
|
|
Get(ctx context.Context, nodeID storj.NodeID) (stats *NodeStats, err error)
|
2018-07-27 22:11:44 +01:00
|
|
|
|
2018-12-19 18:44:03 +00:00
|
|
|
// FindInvalidNodes finds a subset of storagenodes that have stats below provided reputation requirements
|
|
|
|
FindInvalidNodes(ctx context.Context, nodeIDs storj.NodeIDList, maxStats *NodeStats) (invalidIDs storj.NodeIDList, err error)
|
2018-07-27 22:11:44 +01:00
|
|
|
|
2018-12-19 18:44:03 +00:00
|
|
|
// Update all parts of single storagenode's stats in the db
|
|
|
|
Update(ctx context.Context, updateReq *UpdateRequest) (stats *NodeStats, err error)
|
2018-07-27 22:11:44 +01:00
|
|
|
|
2018-12-14 20:17:30 +00:00
|
|
|
// UpdateUptime updates a single storagenode's uptime stats in the db
|
2018-12-19 18:44:03 +00:00
|
|
|
UpdateUptime(ctx context.Context, nodeID storj.NodeID, isUp bool) (stats *NodeStats, err error)
|
2018-07-27 22:11:44 +01:00
|
|
|
|
2018-12-19 18:44:03 +00:00
|
|
|
// UpdateAuditSuccess updates a single storagenode's audit stats in the db
|
|
|
|
UpdateAuditSuccess(ctx context.Context, nodeID storj.NodeID, auditSuccess bool) (stats *NodeStats, err error)
|
2018-07-27 22:11:44 +01:00
|
|
|
|
2019-01-02 10:31:49 +00:00
|
|
|
// UpdateBatch for updating multiple storage nodes' stats in the db
|
2018-12-19 18:44:03 +00:00
|
|
|
UpdateBatch(ctx context.Context, updateReqList []*UpdateRequest) (statsList []*NodeStats, failedUpdateReqs []*UpdateRequest, err error)
|
2018-07-27 22:11:44 +01:00
|
|
|
|
2018-12-14 20:17:30 +00:00
|
|
|
// CreateEntryIfNotExists creates a statdb node entry and saves to statdb if it didn't already exist
|
2018-12-19 18:44:03 +00:00
|
|
|
CreateEntryIfNotExists(ctx context.Context, nodeID storj.NodeID) (stats *NodeStats, err error)
|
2018-12-14 20:17:30 +00:00
|
|
|
}
|
2018-11-26 17:08:29 +00:00
|
|
|
|
2018-12-14 20:17:30 +00:00
|
|
|
// UpdateRequest is a statdb update request message
|
|
|
|
type UpdateRequest struct {
|
2018-12-19 18:44:03 +00:00
|
|
|
NodeID storj.NodeID
|
2018-12-14 20:17:30 +00:00
|
|
|
AuditSuccess bool
|
2018-12-19 18:44:03 +00:00
|
|
|
IsUp bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// NodeStats is a statdb node stats message
|
|
|
|
type NodeStats struct {
|
|
|
|
NodeID storj.NodeID
|
|
|
|
AuditSuccessRatio float64
|
|
|
|
AuditSuccessCount int64
|
|
|
|
AuditCount int64
|
|
|
|
UptimeRatio float64
|
|
|
|
UptimeSuccessCount int64
|
|
|
|
UptimeCount int64
|
2018-11-15 00:03:19 +00:00
|
|
|
}
|