2018-07-27 22:11:44 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package statdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2019-01-23 19:58:44 +00:00
|
|
|
"github.com/zeebo/errs"
|
|
|
|
|
2018-11-30 13:40:13 +00:00
|
|
|
"storj.io/storj/pkg/storj"
|
2018-07-27 22:11:44 +01:00
|
|
|
)
|
|
|
|
|
2019-01-23 19:58:44 +00:00
|
|
|
var (
|
|
|
|
// Error is the default errs class
|
|
|
|
Error = errs.Class("statdb error")
|
|
|
|
)
|
|
|
|
|
2019-01-02 17:53:27 +00:00
|
|
|
// DB stores node statistics
|
2018-12-14 20:17:30 +00:00
|
|
|
type DB interface {
|
2019-01-02 17:53:27 +00:00
|
|
|
// Create adds a new stats entry for node.
|
|
|
|
Create(ctx context.Context, nodeID storj.NodeID, initial *NodeStats) (stats *NodeStats, err error)
|
|
|
|
// Get returns node stats.
|
2018-12-19 18:44:03 +00:00
|
|
|
Get(ctx context.Context, nodeID storj.NodeID) (stats *NodeStats, err error)
|
2019-01-02 17:53:27 +00:00
|
|
|
// FindInvalidNodes finds a subset of storagenodes that have stats below provided reputation requirements.
|
|
|
|
FindInvalidNodes(ctx context.Context, nodeIDs storj.NodeIDList, maxStats *NodeStats) (invalid storj.NodeIDList, err error)
|
|
|
|
// Update all parts of single storagenode's stats.
|
|
|
|
Update(ctx context.Context, request *UpdateRequest) (stats *NodeStats, err error)
|
|
|
|
// UpdateUptime updates a single storagenode's uptime stats.
|
2018-12-19 18:44:03 +00:00
|
|
|
UpdateUptime(ctx context.Context, nodeID storj.NodeID, isUp bool) (stats *NodeStats, err error)
|
2019-01-02 17:53:27 +00:00
|
|
|
// UpdateAuditSuccess updates a single storagenode's audit stats.
|
2018-12-19 18:44:03 +00:00
|
|
|
UpdateAuditSuccess(ctx context.Context, nodeID storj.NodeID, auditSuccess bool) (stats *NodeStats, err error)
|
2019-01-02 17:53:27 +00:00
|
|
|
// UpdateBatch for updating multiple storage nodes' stats.
|
|
|
|
UpdateBatch(ctx context.Context, requests []*UpdateRequest) (statslist []*NodeStats, failed []*UpdateRequest, err error)
|
|
|
|
// CreateEntryIfNotExists creates a node stats entry 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
|
|
|
|
2019-01-02 17:53:27 +00:00
|
|
|
// UpdateRequest is used to update a node status.
|
2018-12-14 20:17:30 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-01-02 17:53:27 +00:00
|
|
|
// NodeStats contains statistics abot a node.
|
2018-12-19 18:44:03 +00:00
|
|
|
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
|
|
|
}
|