fff21b330d
Currently the tool verifies: * validity of plain_offset * whether plain_size is smaller than encrypted_size Change-Id: I9ec4fb5ead3356a196392c26ca377fcdb367138e
78 lines
1.7 KiB
Go
78 lines
1.7 KiB
Go
// Copyright (C) 2021 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package verify
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/zeebo/errs"
|
|
"go.uber.org/zap"
|
|
|
|
"storj.io/common/errs2"
|
|
"storj.io/storj/satellite/metabase"
|
|
"storj.io/storj/satellite/metabase/metaloop"
|
|
)
|
|
|
|
// Error is the default error class for the package.
|
|
var Error = errs.Class("verify")
|
|
|
|
// Chore runs different verifications on metabase loop.
|
|
type Chore struct {
|
|
Log *zap.Logger
|
|
|
|
Config Config
|
|
|
|
DB metaloop.MetabaseDB
|
|
}
|
|
|
|
// Config contains configuration for all the services.
|
|
type Config struct {
|
|
ProgressPrintFrequency int64
|
|
Loop metaloop.Config
|
|
}
|
|
|
|
// New creates new verification.
|
|
func New(log *zap.Logger, mdb metaloop.MetabaseDB, config Config) *Chore {
|
|
return &Chore{
|
|
Log: log,
|
|
Config: config,
|
|
DB: mdb,
|
|
}
|
|
}
|
|
|
|
// RunOnce creates a new metaloop and runs the verifications.
|
|
func (chore *Chore) RunOnce(ctx context.Context) error {
|
|
loop := metaloop.New(chore.Config.Loop, chore.DB)
|
|
|
|
var group errs2.Group
|
|
group.Go(func() error {
|
|
progress := &ProgressObserver{
|
|
Log: chore.Log.Named("progress"),
|
|
ProgressPrintFrequency: chore.Config.ProgressPrintFrequency,
|
|
}
|
|
|
|
plainOffset := &SegmentSizes{
|
|
Log: chore.Log.Named("segment-sizes"),
|
|
}
|
|
|
|
err := loop.Join(ctx, progress, plainOffset)
|
|
if err != nil {
|
|
return Error.Wrap(err)
|
|
}
|
|
|
|
progress.Report()
|
|
|
|
return nil
|
|
})
|
|
group.Go(func() error {
|
|
return Error.Wrap(loop.RunOnce(ctx))
|
|
})
|
|
return Error.Wrap(errs.Combine(group.Wait()...))
|
|
}
|
|
|
|
func formatObject(obj metabase.ObjectStream) string {
|
|
return fmt.Sprintf("project:%q bucket:%q key:%q stream:\"%x\"", obj.ProjectID, obj.BucketName, obj.ObjectKey, obj.StreamID[:])
|
|
}
|