remove unnecessary containmentDB wrapper (#2027)

This commit is contained in:
Natalie Villasana 2019-05-23 10:37:23 -04:00 committed by GitHub
parent ef4849b53b
commit 8b31c4b91f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 40 deletions

View File

@ -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)
}

View File

@ -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

View File

@ -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}
}

View File

@ -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) {