2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-26 21:49:55 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package accounting
|
|
|
|
|
|
|
|
import (
|
2018-12-12 21:24:08 +00:00
|
|
|
"context"
|
2018-12-14 14:27:21 +00:00
|
|
|
"time"
|
2018-12-12 21:24:08 +00:00
|
|
|
|
2018-12-18 17:18:42 +00:00
|
|
|
"storj.io/storj/pkg/storj"
|
2018-12-07 14:46:42 +00:00
|
|
|
)
|
2018-12-05 14:03:23 +00:00
|
|
|
|
2019-01-16 19:30:33 +00:00
|
|
|
//RollupStats is a convenience alias
|
|
|
|
type RollupStats map[time.Time]map[storj.NodeID]*Rollup
|
|
|
|
|
|
|
|
//Raw mirrors dbx.AccountingRaw, allowing us to use that struct without leaking dbx
|
|
|
|
type Raw struct {
|
|
|
|
ID int64
|
|
|
|
NodeID storj.NodeID
|
|
|
|
IntervalEndTime time.Time
|
|
|
|
DataTotal float64
|
|
|
|
DataType int
|
|
|
|
CreatedAt time.Time
|
|
|
|
}
|
|
|
|
|
|
|
|
//Rollup mirrors dbx.AccountingRollup, allowing us to use that struct without leaking dbx
|
|
|
|
type Rollup struct {
|
|
|
|
ID int64
|
|
|
|
NodeID storj.NodeID
|
|
|
|
StartTime time.Time
|
|
|
|
PutTotal int64
|
|
|
|
GetTotal int64
|
|
|
|
GetAuditTotal int64
|
|
|
|
GetRepairTotal int64
|
|
|
|
PutRepairTotal int64
|
|
|
|
AtRestTotal float64
|
|
|
|
}
|
2019-01-10 11:41:57 +00:00
|
|
|
|
2019-01-02 17:53:27 +00:00
|
|
|
// DB stores information about bandwidth usage
|
2018-12-14 14:27:21 +00:00
|
|
|
type DB interface {
|
2019-02-01 18:50:12 +00:00
|
|
|
// LastTimestamp records the latest last tallied time.
|
|
|
|
LastTimestamp(ctx context.Context, timestampType string) (time.Time, error)
|
|
|
|
// SaveBWRaw records raw sums of agreement values to the database and updates the LastTimestamp.
|
|
|
|
SaveBWRaw(ctx context.Context, tallyEnd time.Time, bwTotals map[storj.NodeID][]int64) error
|
2019-01-02 17:53:27 +00:00
|
|
|
// SaveAtRestRaw records raw tallies of at-rest-data.
|
2019-02-01 18:50:12 +00:00
|
|
|
SaveAtRestRaw(ctx context.Context, latestTally time.Time, nodeData map[storj.NodeID]float64) error
|
2019-01-16 19:30:33 +00:00
|
|
|
// GetRaw retrieves all raw tallies
|
|
|
|
GetRaw(ctx context.Context) ([]*Raw, error)
|
|
|
|
// GetRawSince r retrieves all raw tallies sinces
|
|
|
|
GetRawSince(ctx context.Context, latestRollup time.Time) ([]*Raw, error)
|
|
|
|
// SaveRollup records raw tallies of at rest data to the database
|
2019-02-01 18:50:12 +00:00
|
|
|
SaveRollup(ctx context.Context, latestTally time.Time, stats RollupStats) error
|
2019-01-17 18:34:13 +00:00
|
|
|
// QueryPaymentInfo queries StatDB, Accounting Rollup on nodeID
|
|
|
|
QueryPaymentInfo(ctx context.Context, start time.Time, end time.Time) ([]*CSVRow, error)
|
2018-11-26 21:49:55 +00:00
|
|
|
}
|