2019-01-02 17:53:27 +00:00
|
|
|
// Code generated by lockedgen using 'go generate'. DO NOT EDIT.
|
|
|
|
|
2019-01-11 16:07:26 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2019-01-02 17:53:27 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package satellitedb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
"github.com/skyrings/skyring-common/tools/uuid"
|
|
|
|
|
2019-01-02 17:53:27 +00:00
|
|
|
"storj.io/storj/pkg/accounting"
|
|
|
|
"storj.io/storj/pkg/bwagreement"
|
|
|
|
"storj.io/storj/pkg/datarepair/irreparable"
|
|
|
|
"storj.io/storj/pkg/datarepair/queue"
|
2019-01-15 16:08:45 +00:00
|
|
|
"storj.io/storj/pkg/overlay"
|
2019-01-02 17:53:27 +00:00
|
|
|
"storj.io/storj/pkg/pb"
|
|
|
|
"storj.io/storj/pkg/statdb"
|
|
|
|
"storj.io/storj/pkg/storj"
|
|
|
|
"storj.io/storj/satellite"
|
2019-01-16 20:23:28 +00:00
|
|
|
"storj.io/storj/satellite/console"
|
2019-01-02 17:53:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// locked implements a locking wrapper around satellite.DB.
|
|
|
|
type locked struct {
|
|
|
|
sync.Locker
|
|
|
|
db satellite.DB
|
|
|
|
}
|
|
|
|
|
|
|
|
// newLocked returns database wrapped with locker.
|
|
|
|
func newLocked(db satellite.DB) satellite.DB {
|
|
|
|
return &locked{&sync.Mutex{}, db}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Accounting returns database for storing information about data use
|
|
|
|
func (m *locked) Accounting() accounting.DB {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return &lockedAccounting{m.Locker, m.db.Accounting()}
|
|
|
|
}
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
// lockedAccounting implements locking wrapper for accounting.DB
|
|
|
|
type lockedAccounting struct {
|
|
|
|
sync.Locker
|
|
|
|
db accounting.DB
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetRaw retrieves all raw tallies
|
|
|
|
func (m *lockedAccounting) GetRaw(ctx context.Context) ([]*accounting.Raw, error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.GetRaw(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetRawSince r retrieves all raw tallies sinces
|
|
|
|
func (m *lockedAccounting) GetRawSince(ctx context.Context, latestRollup time.Time) ([]*accounting.Raw, error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.GetRawSince(ctx, latestRollup)
|
|
|
|
}
|
|
|
|
|
|
|
|
// LastRawTime records the latest last tallied time.
|
|
|
|
func (m *lockedAccounting) LastRawTime(ctx context.Context, timestampType string) (time.Time, bool, error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.LastRawTime(ctx, timestampType)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SaveAtRestRaw records raw tallies of at-rest-data.
|
2019-01-18 16:53:23 +00:00
|
|
|
func (m *lockedAccounting) SaveAtRestRaw(ctx context.Context, latestTally time.Time, isNew bool, nodeData map[storj.NodeID]float64) error {
|
2019-01-16 20:23:28 +00:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
2019-01-18 16:53:23 +00:00
|
|
|
return m.db.SaveAtRestRaw(ctx, latestTally, isNew, nodeData)
|
2019-01-16 20:23:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SaveBWRaw records raw sums of agreement values to the database and updates the LastRawTime.
|
2019-01-18 16:53:23 +00:00
|
|
|
func (m *lockedAccounting) SaveBWRaw(ctx context.Context, latestBwa time.Time, isNew bool, bwTotals accounting.BWTally) error {
|
2019-01-16 20:23:28 +00:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
2019-01-18 16:53:23 +00:00
|
|
|
return m.db.SaveBWRaw(ctx, latestBwa, isNew, bwTotals)
|
2019-01-16 20:23:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SaveRollup records raw tallies of at rest data to the database
|
|
|
|
func (m *lockedAccounting) SaveRollup(ctx context.Context, latestTally time.Time, stats accounting.RollupStats) error {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.SaveRollup(ctx, latestTally, stats)
|
|
|
|
}
|
|
|
|
|
2019-01-02 17:53:27 +00:00
|
|
|
// BandwidthAgreement returns database for storing bandwidth agreements
|
|
|
|
func (m *locked) BandwidthAgreement() bwagreement.DB {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return &lockedBandwidthAgreement{m.Locker, m.db.BandwidthAgreement()}
|
|
|
|
}
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
// lockedBandwidthAgreement implements locking wrapper for bwagreement.DB
|
|
|
|
type lockedBandwidthAgreement struct {
|
|
|
|
sync.Locker
|
|
|
|
db bwagreement.DB
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateAgreement adds a new bandwidth agreement.
|
|
|
|
func (m *lockedBandwidthAgreement) CreateAgreement(ctx context.Context, a1 string, a2 bwagreement.Agreement) error {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.CreateAgreement(ctx, a1, a2)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetAgreements gets all bandwidth agreements.
|
|
|
|
func (m *lockedBandwidthAgreement) GetAgreements(ctx context.Context) ([]bwagreement.Agreement, error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.GetAgreements(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetAgreementsSince gets all bandwidth agreements since specific time.
|
|
|
|
func (m *lockedBandwidthAgreement) GetAgreementsSince(ctx context.Context, a1 time.Time) ([]bwagreement.Agreement, error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.GetAgreementsSince(ctx, a1)
|
|
|
|
}
|
|
|
|
|
2019-01-02 17:53:27 +00:00
|
|
|
// Close closes the database
|
|
|
|
func (m *locked) Close() error {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.Close()
|
|
|
|
}
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
// Console returns database for satellite console
|
|
|
|
func (m *locked) Console() console.DB {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return &lockedConsole{m.Locker, m.db.Console()}
|
|
|
|
}
|
|
|
|
|
|
|
|
// lockedConsole implements locking wrapper for console.DB
|
|
|
|
type lockedConsole struct {
|
|
|
|
sync.Locker
|
|
|
|
db console.DB
|
|
|
|
}
|
|
|
|
|
|
|
|
// APIKeys is a getter for APIKeys repository
|
|
|
|
func (m *lockedConsole) APIKeys() console.APIKeys {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return &lockedAPIKeys{m.Locker, m.db.APIKeys()}
|
|
|
|
}
|
|
|
|
|
|
|
|
// lockedAPIKeys implements locking wrapper for console.APIKeys
|
|
|
|
type lockedAPIKeys struct {
|
|
|
|
sync.Locker
|
|
|
|
db console.APIKeys
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create creates and stores new APIKeyInfo
|
|
|
|
func (m *lockedAPIKeys) Create(ctx context.Context, key console.APIKey, info console.APIKeyInfo) (*console.APIKeyInfo, error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.Create(ctx, key, info)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete deletes APIKeyInfo from store
|
|
|
|
func (m *lockedAPIKeys) Delete(ctx context.Context, id uuid.UUID) error {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.Delete(ctx, id)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get retrieves APIKeyInfo with given ID
|
|
|
|
func (m *lockedAPIKeys) Get(ctx context.Context, id uuid.UUID) (*console.APIKeyInfo, error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.Get(ctx, id)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetByKey retrieves APIKeyInfo for given key
|
|
|
|
func (m *lockedAPIKeys) GetByKey(ctx context.Context, key console.APIKey) (*console.APIKeyInfo, error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.GetByKey(ctx, key)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetByProjectID retrieves list of APIKeys for given projectID
|
|
|
|
func (m *lockedAPIKeys) GetByProjectID(ctx context.Context, projectID uuid.UUID) ([]console.APIKeyInfo, error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.GetByProjectID(ctx, projectID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update updates APIKeyInfo in store
|
|
|
|
func (m *lockedAPIKeys) Update(ctx context.Context, key console.APIKeyInfo) error {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.Update(ctx, key)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Buckets is a getter for Buckets repository
|
|
|
|
func (m *lockedConsole) Buckets() console.Buckets {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return &lockedBuckets{m.Locker, m.db.Buckets()}
|
|
|
|
}
|
|
|
|
|
|
|
|
// lockedBuckets implements locking wrapper for console.Buckets
|
|
|
|
type lockedBuckets struct {
|
|
|
|
sync.Locker
|
|
|
|
db console.Buckets
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *lockedBuckets) AttachBucket(ctx context.Context, name string, projectID uuid.UUID) (*console.Bucket, error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.AttachBucket(ctx, name, projectID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *lockedBuckets) DeattachBucket(ctx context.Context, name string) error {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.DeattachBucket(ctx, name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *lockedBuckets) GetBucket(ctx context.Context, name string) (*console.Bucket, error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.GetBucket(ctx, name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *lockedBuckets) ListBuckets(ctx context.Context, projectID uuid.UUID) ([]console.Bucket, error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.ListBuckets(ctx, projectID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close is used to close db connection
|
|
|
|
func (m *lockedConsole) Close() error {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateTables is a method for creating all tables for satellitedb
|
|
|
|
func (m *lockedConsole) CreateTables() error {
|
2019-01-02 17:53:27 +00:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.CreateTables()
|
|
|
|
}
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
// ProjectMembers is a getter for ProjectMembers repository
|
|
|
|
func (m *lockedConsole) ProjectMembers() console.ProjectMembers {
|
2019-01-02 17:53:27 +00:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
2019-01-16 20:23:28 +00:00
|
|
|
return &lockedProjectMembers{m.Locker, m.db.ProjectMembers()}
|
2019-01-02 17:53:27 +00:00
|
|
|
}
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
// lockedProjectMembers implements locking wrapper for console.ProjectMembers
|
|
|
|
type lockedProjectMembers struct {
|
|
|
|
sync.Locker
|
|
|
|
db console.ProjectMembers
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete is a method for deleting project member by memberID and projectID from the database.
|
|
|
|
func (m *lockedProjectMembers) Delete(ctx context.Context, memberID uuid.UUID, projectID uuid.UUID) error {
|
2019-01-02 17:53:27 +00:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
2019-01-16 20:23:28 +00:00
|
|
|
return m.db.Delete(ctx, memberID, projectID)
|
2019-01-02 17:53:27 +00:00
|
|
|
}
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
// GetByMemberID is a method for querying project members from the database by memberID.
|
|
|
|
func (m *lockedProjectMembers) GetByMemberID(ctx context.Context, memberID uuid.UUID) ([]console.ProjectMember, error) {
|
2019-01-02 17:53:27 +00:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
2019-01-16 20:23:28 +00:00
|
|
|
return m.db.GetByMemberID(ctx, memberID)
|
2019-01-02 17:53:27 +00:00
|
|
|
}
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
// GetByProjectID is a method for querying project members from the database by projectID, offset and limit.
|
|
|
|
func (m *lockedProjectMembers) GetByProjectID(ctx context.Context, projectID uuid.UUID, pagination console.Pagination) ([]console.ProjectMember, error) {
|
2019-01-02 17:53:27 +00:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
2019-01-16 20:23:28 +00:00
|
|
|
return m.db.GetByProjectID(ctx, projectID, pagination)
|
2019-01-02 17:53:27 +00:00
|
|
|
}
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
// Insert is a method for inserting project member into the database.
|
|
|
|
func (m *lockedProjectMembers) Insert(ctx context.Context, memberID uuid.UUID, projectID uuid.UUID) (*console.ProjectMember, error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.Insert(ctx, memberID, projectID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Projects is a getter for Projects repository
|
|
|
|
func (m *lockedConsole) Projects() console.Projects {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return &lockedProjects{m.Locker, m.db.Projects()}
|
|
|
|
}
|
|
|
|
|
|
|
|
// lockedProjects implements locking wrapper for console.Projects
|
|
|
|
type lockedProjects struct {
|
2019-01-02 17:53:27 +00:00
|
|
|
sync.Locker
|
2019-01-16 20:23:28 +00:00
|
|
|
db console.Projects
|
2019-01-02 17:53:27 +00:00
|
|
|
}
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
// Delete is a method for deleting project by Id from the database.
|
|
|
|
func (m *lockedProjects) Delete(ctx context.Context, id uuid.UUID) error {
|
2019-01-16 19:30:33 +00:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
2019-01-16 20:23:28 +00:00
|
|
|
return m.db.Delete(ctx, id)
|
2019-01-16 19:30:33 +00:00
|
|
|
}
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
// Get is a method for querying project from the database by id.
|
|
|
|
func (m *lockedProjects) Get(ctx context.Context, id uuid.UUID) (*console.Project, error) {
|
2019-01-16 19:30:33 +00:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
2019-01-16 20:23:28 +00:00
|
|
|
return m.db.Get(ctx, id)
|
2019-01-16 19:30:33 +00:00
|
|
|
}
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
// GetAll is a method for querying all projects from the database.
|
|
|
|
func (m *lockedProjects) GetAll(ctx context.Context) ([]console.Project, error) {
|
2019-01-16 19:30:33 +00:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
2019-01-16 20:23:28 +00:00
|
|
|
return m.db.GetAll(ctx)
|
2019-01-16 19:30:33 +00:00
|
|
|
}
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
// GetByUserID is a method for querying all projects from the database by userID.
|
|
|
|
func (m *lockedProjects) GetByUserID(ctx context.Context, userID uuid.UUID) ([]console.Project, error) {
|
2019-01-02 17:53:27 +00:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
2019-01-16 20:23:28 +00:00
|
|
|
return m.db.GetByUserID(ctx, userID)
|
2019-01-02 17:53:27 +00:00
|
|
|
}
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
// Insert is a method for inserting project into the database.
|
|
|
|
func (m *lockedProjects) Insert(ctx context.Context, project *console.Project) (*console.Project, error) {
|
2019-01-02 17:53:27 +00:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
2019-01-16 20:23:28 +00:00
|
|
|
return m.db.Insert(ctx, project)
|
2019-01-02 17:53:27 +00:00
|
|
|
}
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
// Update is a method for updating project entity.
|
|
|
|
func (m *lockedProjects) Update(ctx context.Context, project *console.Project) error {
|
2019-01-02 17:53:27 +00:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
2019-01-16 20:23:28 +00:00
|
|
|
return m.db.Update(ctx, project)
|
2019-01-02 17:53:27 +00:00
|
|
|
}
|
|
|
|
|
2019-01-17 18:34:13 +00:00
|
|
|
// QueryPaymentInfo queries StatDB, Accounting Rollup on nodeID
|
|
|
|
func (m *lockedAccounting) QueryPaymentInfo(ctx context.Context, start time.Time, end time.Time) ([]*accounting.CSVRow, error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.QueryPaymentInfo(ctx, start, end)
|
|
|
|
}
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
// Users is a getter for Users repository
|
|
|
|
func (m *lockedConsole) Users() console.Users {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return &lockedUsers{m.Locker, m.db.Users()}
|
|
|
|
}
|
|
|
|
|
|
|
|
// lockedUsers implements locking wrapper for console.Users
|
|
|
|
type lockedUsers struct {
|
2019-01-02 17:53:27 +00:00
|
|
|
sync.Locker
|
2019-01-16 20:23:28 +00:00
|
|
|
db console.Users
|
2019-01-02 17:53:27 +00:00
|
|
|
}
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
// Delete is a method for deleting user by Id from the database.
|
|
|
|
func (m *lockedUsers) Delete(ctx context.Context, id uuid.UUID) error {
|
2019-01-02 17:53:27 +00:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
2019-01-16 20:23:28 +00:00
|
|
|
return m.db.Delete(ctx, id)
|
2019-01-02 17:53:27 +00:00
|
|
|
}
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
// Get is a method for querying user from the database by id
|
|
|
|
func (m *lockedUsers) Get(ctx context.Context, id uuid.UUID) (*console.User, error) {
|
2019-01-02 17:53:27 +00:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
2019-01-16 20:23:28 +00:00
|
|
|
return m.db.Get(ctx, id)
|
2019-01-02 17:53:27 +00:00
|
|
|
}
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
// GetByEmail is a method for querying user by email from the database.
|
|
|
|
func (m *lockedUsers) GetByEmail(ctx context.Context, email string) (*console.User, error) {
|
2019-01-02 17:53:27 +00:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
2019-01-16 20:23:28 +00:00
|
|
|
return m.db.GetByEmail(ctx, email)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert is a method for inserting user into the database
|
|
|
|
func (m *lockedUsers) Insert(ctx context.Context, user *console.User) (*console.User, error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.Insert(ctx, user)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update is a method for updating user entity
|
|
|
|
func (m *lockedUsers) Update(ctx context.Context, user *console.User) error {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.Update(ctx, user)
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateTables initializes the database
|
|
|
|
func (m *locked) CreateTables() error {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.CreateTables()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Irreparable returns database for failed repairs
|
|
|
|
func (m *locked) Irreparable() irreparable.DB {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return &lockedIrreparable{m.Locker, m.db.Irreparable()}
|
2019-01-02 17:53:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// lockedIrreparable implements locking wrapper for irreparable.DB
|
|
|
|
type lockedIrreparable struct {
|
|
|
|
sync.Locker
|
|
|
|
db irreparable.DB
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete removes irreparable segment info based on segmentPath.
|
|
|
|
func (m *lockedIrreparable) Delete(ctx context.Context, segmentPath []byte) error {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.Delete(ctx, segmentPath)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get returns irreparable segment info based on segmentPath.
|
|
|
|
func (m *lockedIrreparable) Get(ctx context.Context, segmentPath []byte) (*irreparable.RemoteSegmentInfo, error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.Get(ctx, segmentPath)
|
|
|
|
}
|
|
|
|
|
|
|
|
// IncrementRepairAttempts increments the repair attempts.
|
|
|
|
func (m *lockedIrreparable) IncrementRepairAttempts(ctx context.Context, segmentInfo *irreparable.RemoteSegmentInfo) error {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.IncrementRepairAttempts(ctx, segmentInfo)
|
|
|
|
}
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
// OverlayCache returns database for caching overlay information
|
|
|
|
func (m *locked) OverlayCache() overlay.DB {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return &lockedOverlayCache{m.Locker, m.db.OverlayCache()}
|
|
|
|
}
|
|
|
|
|
2019-01-15 16:08:45 +00:00
|
|
|
// lockedOverlayCache implements locking wrapper for overlay.DB
|
2019-01-02 17:53:27 +00:00
|
|
|
type lockedOverlayCache struct {
|
|
|
|
sync.Locker
|
2019-01-15 16:08:45 +00:00
|
|
|
db overlay.DB
|
2019-01-02 17:53:27 +00:00
|
|
|
}
|
|
|
|
|
2019-01-15 16:08:45 +00:00
|
|
|
// Delete deletes node based on id
|
|
|
|
func (m *lockedOverlayCache) Delete(ctx context.Context, id storj.NodeID) error {
|
2019-01-02 17:53:27 +00:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
2019-01-15 16:08:45 +00:00
|
|
|
return m.db.Delete(ctx, id)
|
2019-01-02 17:53:27 +00:00
|
|
|
}
|
|
|
|
|
2019-01-15 16:08:45 +00:00
|
|
|
// Get looks up the node by nodeID
|
|
|
|
func (m *lockedOverlayCache) Get(ctx context.Context, nodeID storj.NodeID) (*pb.Node, error) {
|
2019-01-02 17:53:27 +00:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
2019-01-15 16:08:45 +00:00
|
|
|
return m.db.Get(ctx, nodeID)
|
2019-01-02 17:53:27 +00:00
|
|
|
}
|
|
|
|
|
2019-01-15 16:08:45 +00:00
|
|
|
// GetAll looks up nodes based on the ids from the overlay cache
|
|
|
|
func (m *lockedOverlayCache) GetAll(ctx context.Context, nodeIDs storj.NodeIDList) ([]*pb.Node, error) {
|
2019-01-02 17:53:27 +00:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
2019-01-15 16:08:45 +00:00
|
|
|
return m.db.GetAll(ctx, nodeIDs)
|
2019-01-02 17:53:27 +00:00
|
|
|
}
|
|
|
|
|
2019-01-15 16:08:45 +00:00
|
|
|
// List lists nodes starting from cursor
|
|
|
|
func (m *lockedOverlayCache) List(ctx context.Context, cursor storj.NodeID, limit int) ([]*pb.Node, error) {
|
2019-01-02 17:53:27 +00:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
2019-01-15 16:08:45 +00:00
|
|
|
return m.db.List(ctx, cursor, limit)
|
2019-01-02 17:53:27 +00:00
|
|
|
}
|
|
|
|
|
2019-01-15 16:08:45 +00:00
|
|
|
// Update updates node information
|
|
|
|
func (m *lockedOverlayCache) Update(ctx context.Context, value *pb.Node) error {
|
2019-01-02 17:53:27 +00:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
2019-01-15 16:08:45 +00:00
|
|
|
return m.db.Update(ctx, value)
|
2019-01-02 17:53:27 +00:00
|
|
|
}
|
|
|
|
|
2019-01-17 18:34:13 +00:00
|
|
|
//GetWalletAddress gets the node's wallet address
|
|
|
|
func (m *lockedOverlayCache) GetWalletAddress(ctx context.Context, id storj.NodeID) (string, error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.GetWalletAddress(ctx, id)
|
|
|
|
}
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
// RepairQueue returns queue for segments that need repairing
|
|
|
|
func (m *locked) RepairQueue() queue.RepairQueue {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return &lockedRepairQueue{m.Locker, m.db.RepairQueue()}
|
|
|
|
}
|
|
|
|
|
2019-01-02 17:53:27 +00:00
|
|
|
// lockedRepairQueue implements locking wrapper for queue.RepairQueue
|
|
|
|
type lockedRepairQueue struct {
|
|
|
|
sync.Locker
|
|
|
|
db queue.RepairQueue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dequeue removes an injured segment.
|
|
|
|
func (m *lockedRepairQueue) Dequeue(ctx context.Context) (pb.InjuredSegment, error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.Dequeue(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enqueue adds an injured segment.
|
|
|
|
func (m *lockedRepairQueue) Enqueue(ctx context.Context, qi *pb.InjuredSegment) error {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.Enqueue(ctx, qi)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Peekqueue lists limit amount of injured segments.
|
|
|
|
func (m *lockedRepairQueue) Peekqueue(ctx context.Context, limit int) ([]pb.InjuredSegment, error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.Peekqueue(ctx, limit)
|
|
|
|
}
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
// StatDB returns database for storing node statistics
|
|
|
|
func (m *locked) StatDB() statdb.DB {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return &lockedStatDB{m.Locker, m.db.StatDB()}
|
|
|
|
}
|
|
|
|
|
2019-01-02 17:53:27 +00:00
|
|
|
// lockedStatDB implements locking wrapper for statdb.DB
|
|
|
|
type lockedStatDB struct {
|
|
|
|
sync.Locker
|
|
|
|
db statdb.DB
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create adds a new stats entry for node.
|
|
|
|
func (m *lockedStatDB) Create(ctx context.Context, nodeID storj.NodeID, initial *statdb.NodeStats) (stats *statdb.NodeStats, err error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.Create(ctx, nodeID, initial)
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateEntryIfNotExists creates a node stats entry if it didn't already exist.
|
|
|
|
func (m *lockedStatDB) CreateEntryIfNotExists(ctx context.Context, nodeID storj.NodeID) (stats *statdb.NodeStats, err error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.CreateEntryIfNotExists(ctx, nodeID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// FindInvalidNodes finds a subset of storagenodes that have stats below provided reputation requirements.
|
|
|
|
func (m *lockedStatDB) FindInvalidNodes(ctx context.Context, nodeIDs storj.NodeIDList, maxStats *statdb.NodeStats) (invalid storj.NodeIDList, err error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.FindInvalidNodes(ctx, nodeIDs, maxStats)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get returns node stats.
|
|
|
|
func (m *lockedStatDB) Get(ctx context.Context, nodeID storj.NodeID) (stats *statdb.NodeStats, err error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.Get(ctx, nodeID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update all parts of single storagenode's stats.
|
|
|
|
func (m *lockedStatDB) Update(ctx context.Context, request *statdb.UpdateRequest) (stats *statdb.NodeStats, err error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.Update(ctx, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateAuditSuccess updates a single storagenode's audit stats.
|
|
|
|
func (m *lockedStatDB) UpdateAuditSuccess(ctx context.Context, nodeID storj.NodeID, auditSuccess bool) (stats *statdb.NodeStats, err error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.UpdateAuditSuccess(ctx, nodeID, auditSuccess)
|
|
|
|
}
|
|
|
|
|
2019-01-09 15:02:03 +00:00
|
|
|
// UpdateBatch for updating multiple storage nodes' stats.
|
2019-01-02 17:53:27 +00:00
|
|
|
func (m *lockedStatDB) UpdateBatch(ctx context.Context, requests []*statdb.UpdateRequest) (statslist []*statdb.NodeStats, failed []*statdb.UpdateRequest, err error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.UpdateBatch(ctx, requests)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateUptime updates a single storagenode's uptime stats.
|
|
|
|
func (m *lockedStatDB) UpdateUptime(ctx context.Context, nodeID storj.NodeID, isUp bool) (stats *statdb.NodeStats, err error) {
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
return m.db.UpdateUptime(ctx, nodeID, isUp)
|
|
|
|
}
|