f41d440944
Remove starting up messages from peers. We expect all of them to start, if they don't, then they should return an error why they don't start. The only informative message is when a service is disabled. When doing initial database setup then each migration step isn't informative, hence print only a single line with the final version. Also use shorter log scopes. Change-Id: Ic8b61411df2eeae2a36d600a0c2fbc97a84a5b93
78 lines
2.1 KiB
Go
78 lines
2.1 KiB
Go
// Copyright (C) 2019 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package pieces
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"go.uber.org/zap"
|
|
"golang.org/x/sync/errgroup"
|
|
|
|
"storj.io/common/sync2"
|
|
"storj.io/storj/storagenode/trust"
|
|
)
|
|
|
|
// TrashChore is the chore that periodically empties the trash
|
|
type TrashChore struct {
|
|
log *zap.Logger
|
|
interval time.Duration
|
|
trashExpiryInterval time.Duration
|
|
store *Store
|
|
trust *trust.Pool
|
|
cycle *sync2.Cycle
|
|
started sync2.Fence
|
|
}
|
|
|
|
// NewTrashChore instantiates a new TrashChore. choreInterval is how often this
|
|
// chore runs, and trashExpiryInterval is passed into the EmptyTrash method to
|
|
// determine which trashed pieces should be deleted
|
|
func NewTrashChore(log *zap.Logger, choreInterval, trashExpiryInterval time.Duration, trust *trust.Pool, store *Store) *TrashChore {
|
|
return &TrashChore{
|
|
log: log,
|
|
interval: choreInterval,
|
|
trashExpiryInterval: trashExpiryInterval,
|
|
store: store,
|
|
trust: trust,
|
|
}
|
|
}
|
|
|
|
// Run starts the cycle
|
|
func (chore *TrashChore) Run(ctx context.Context) (err error) {
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
chore.cycle = sync2.NewCycle(chore.interval)
|
|
chore.cycle.Start(ctx, &errgroup.Group{}, func(ctx context.Context) error {
|
|
chore.log.Debug("starting emptying trash")
|
|
|
|
for _, satelliteID := range chore.trust.GetSatellites(ctx) {
|
|
trashedBefore := time.Now().Add(-chore.trashExpiryInterval)
|
|
err := chore.store.EmptyTrash(ctx, satelliteID, trashedBefore)
|
|
if err != nil {
|
|
chore.log.Error("emptying trash failed", zap.Error(err))
|
|
}
|
|
}
|
|
|
|
return nil
|
|
})
|
|
chore.started.Release()
|
|
return err
|
|
}
|
|
|
|
// TriggerWait ensures that the cycle is done at least once and waits for
|
|
// completion. If the cycle is currently running it waits for the previous to
|
|
// complete and then runs.
|
|
func (chore *TrashChore) TriggerWait(ctx context.Context) {
|
|
chore.started.Wait(ctx)
|
|
chore.cycle.TriggerWait()
|
|
}
|
|
|
|
// Close the chore
|
|
func (chore *TrashChore) Close() error {
|
|
if chore.cycle != nil {
|
|
chore.cycle.Close()
|
|
}
|
|
return nil
|
|
}
|