remove unnecessary containmentDB wrapper (#2027)
This commit is contained in:
parent
ef4849b53b
commit
8b31c4b91f
@ -7,7 +7,6 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/zeebo/errs"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"storj.io/storj/pkg/pb"
|
||||
"storj.io/storj/pkg/storj"
|
||||
@ -37,41 +36,9 @@ type PendingAudit struct {
|
||||
ReverifyCount uint32
|
||||
}
|
||||
|
||||
// DB holds information about pending audits for contained nodes
|
||||
type DB interface {
|
||||
// Containment holds information about pending audits for contained nodes
|
||||
type Containment interface {
|
||||
Get(ctx context.Context, nodeID pb.NodeID) (*PendingAudit, error)
|
||||
IncrementPending(ctx context.Context, pendingAudit *PendingAudit) error
|
||||
Delete(ctx context.Context, nodeID pb.NodeID) (bool, error)
|
||||
}
|
||||
|
||||
// Containment allows the audit verifier to access pending audit info in the db (once it's added to the verifier struct)
|
||||
type Containment struct {
|
||||
log *zap.Logger
|
||||
db DB
|
||||
}
|
||||
|
||||
// NewContainment creates a new containment db
|
||||
func NewContainment(log *zap.Logger, db DB) *Containment {
|
||||
return &Containment{
|
||||
log: log,
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
// Get gets pending audit info from the db
|
||||
func (containment *Containment) Get(ctx context.Context, nodeID pb.NodeID) (*PendingAudit, error) {
|
||||
pendingAudit, err := containment.db.Get(ctx, nodeID)
|
||||
return pendingAudit, ContainError.Wrap(err)
|
||||
}
|
||||
|
||||
// IncrementPending either creates a new entry for a pending audit or updates an existing pending audit's reverify count
|
||||
func (containment *Containment) IncrementPending(ctx context.Context, pending *PendingAudit) error {
|
||||
err := containment.db.IncrementPending(ctx, pending)
|
||||
return ContainError.Wrap(err)
|
||||
}
|
||||
|
||||
// Delete deletes pending audit info from the db
|
||||
func (containment *Containment) Delete(ctx context.Context, nodeID pb.NodeID) (bool, error) {
|
||||
isDeleted, err := containment.db.Delete(ctx, nodeID)
|
||||
return isDeleted, ContainError.Wrap(err)
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ type DB interface {
|
||||
// Orders returns database for orders
|
||||
Orders() orders.DB
|
||||
// Containment returns database for containment
|
||||
Containment() audit.DB
|
||||
Containment() audit.Containment
|
||||
}
|
||||
|
||||
// Config is the global config satellite
|
||||
|
@ -148,6 +148,6 @@ func (db *DB) Orders() orders.DB {
|
||||
}
|
||||
|
||||
// Containment returns database for storing pending audit info
|
||||
func (db *DB) Containment() audit.DB {
|
||||
func (db *DB) Containment() audit.Containment {
|
||||
return &containment{db: db.db}
|
||||
}
|
||||
|
@ -483,16 +483,16 @@ func (m *lockedUsers) Update(ctx context.Context, user *console.User) error {
|
||||
}
|
||||
|
||||
// Containment returns database for containment
|
||||
func (m *locked) Containment() audit.DB {
|
||||
func (m *locked) Containment() audit.Containment {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
return &lockedContainment{m.Locker, m.db.Containment()}
|
||||
}
|
||||
|
||||
// lockedContainment implements locking wrapper for audit.DB
|
||||
// lockedContainment implements locking wrapper for audit.Containment
|
||||
type lockedContainment struct {
|
||||
sync.Locker
|
||||
db audit.DB
|
||||
db audit.Containment
|
||||
}
|
||||
|
||||
func (m *lockedContainment) Delete(ctx context.Context, nodeID storj.NodeID) (bool, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user