Skip to content

Commit

Permalink
storagenode/pieces: fix logging when lazy file walker is disabled
Browse files Browse the repository at this point in the history
Log for used space calculation were displayed only when lazy file walker was enabled. Now in both cases we should have start/end log entry.

Fixes #6958

Change-Id: If057033c4a62e8f6533142dcb753f8f883590918
  • Loading branch information
mniewrzal committed Jun 12, 2024
1 parent 7bc4a89 commit 554b80e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 26 deletions.
5 changes: 0 additions & 5 deletions cmd/storagenode/internalcmd/used_space_filewalker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/spf13/cobra"
"github.com/zeebo/errs"
"go.uber.org/zap"

"storj.io/common/process"
"storj.io/storj/storagenode/iopriority"
Expand Down Expand Up @@ -84,17 +83,13 @@ func usedSpaceCmdRun(opts *RunOptions) (err error) {
err = errs.Combine(err, db.Close())
}()

log.Info("used-space-filewalker started")

filewalker := pieces.NewFileWalker(log, db.Pieces(), db.V0PieceInfo(), db.GCFilewalkerProgress())
total, contentSize, err := filewalker.WalkAndComputeSpaceUsedBySatellite(opts.Ctx, req.SatelliteID)
if err != nil {
return err
}
resp := lazyfilewalker.UsedSpaceResponse{PiecesTotal: total, PiecesContentSize: contentSize}

log.Info("used-space-filewalker completed", zap.Int64("piecesTotal", total), zap.Int64("piecesContentSize", contentSize))

// encode the response struct and write it to stdout
return json.NewEncoder(opts.stdout).Encode(resp)
}
42 changes: 22 additions & 20 deletions private/testplanet/storagenode.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,26 +293,28 @@ func (planet *Planet) newStorageNode(ctx context.Context, prefix string, index,
return nil, errs.New("error while trying to issue new api key: %v", err)
}

{
// set up the used space lazyfilewalker filewalker
cmd := internalcmd.NewUsedSpaceFilewalkerCmd()
cmd.Logger = log.Named("used-space-filewalker")
cmd.Ctx = ctx
peer.Storage2.LazyFileWalker.TestingSetUsedSpaceCmd(cmd)
}
{
// set up the GC lazyfilewalker filewalker
cmd := internalcmd.NewGCFilewalkerCmd()
cmd.Logger = log.Named("gc-filewalker")
cmd.Ctx = ctx
peer.Storage2.LazyFileWalker.TestingSetGCCmd(cmd)
}
{
// set up the trash cleanup lazyfilewalker filewalker
cmd := internalcmd.NewTrashFilewalkerCmd()
cmd.Logger = log.Named("trash-filewalker")
cmd.Ctx = ctx
peer.Storage2.LazyFileWalker.TestingSetTrashCleanupCmd(cmd)
if config.Pieces.EnableLazyFilewalker {
{
// set up the used space lazyfilewalker filewalker
cmd := internalcmd.NewUsedSpaceFilewalkerCmd()
cmd.Logger = log.Named("used-space-filewalker")
cmd.Ctx = ctx
peer.Storage2.LazyFileWalker.TestingSetUsedSpaceCmd(cmd)
}
{
// set up the GC lazyfilewalker filewalker
cmd := internalcmd.NewGCFilewalkerCmd()
cmd.Logger = log.Named("gc-filewalker")
cmd.Ctx = ctx
peer.Storage2.LazyFileWalker.TestingSetGCCmd(cmd)
}
{
// set up the trash cleanup lazyfilewalker filewalker
cmd := internalcmd.NewTrashFilewalkerCmd()
cmd.Logger = log.Named("trash-filewalker")
cmd.Ctx = ctx
peer.Storage2.LazyFileWalker.TestingSetTrashCleanupCmd(cmd)
}
}

return &StorageNode{
Expand Down
14 changes: 13 additions & 1 deletion storagenode/pieces/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,22 +702,34 @@ func (store *Store) SpaceUsedTotalAndBySatellite(ctx context.Context) (piecesTot
var satPiecesTotal int64
var satPiecesContentSize int64

log := store.log.With(zap.Stringer("Satellite ID", satelliteID))

log.Info("used-space-filewalker started")

failover := true
if store.config.EnableLazyFilewalker && store.lazyFilewalker != nil {
satPiecesTotal, satPiecesContentSize, err = store.lazyFilewalker.WalkAndComputeSpaceUsedBySatellite(ctx, satelliteID)
if err != nil {
store.log.Error("failed to lazywalk space used by satellite", zap.Error(err), zap.Stringer("Satellite ID", satelliteID))
log.Error("used-space-filewalker failed", zap.Bool("Lazy File Walker", true), zap.Error(err))
} else {
failover = false
}
}

if failover {
satPiecesTotal, satPiecesContentSize, err = store.Filewalker.WalkAndComputeSpaceUsedBySatellite(ctx, satelliteID)
if err != nil {
log.Error("used-space-filewalker failed", zap.Bool("Lazy File Walker", false), zap.Error(err))
}
}

if err != nil {
group.Add(err)
} else {
log.Info("used-space-filewalker completed",
zap.Bool("Lazy File Walker", !failover),
zap.Int64("Total Pieces Size", satPiecesTotal),
zap.Int64("Total Pieces Content Size", satPiecesContentSize))
}

piecesTotal += satPiecesTotal
Expand Down
25 changes: 25 additions & 0 deletions storagenode/pieces/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"storj.io/common/testcontext"
"storj.io/common/testrand"
"storj.io/storj/cmd/storagenode/internalcmd"
"storj.io/storj/private/testplanet"
"storj.io/storj/storagenode"
"storj.io/storj/storagenode/blobstore"
"storj.io/storj/storagenode/blobstore/filestore"
Expand Down Expand Up @@ -948,6 +949,30 @@ func TestEmptyTrash_lazyFilewalker(t *testing.T) {
})
}

func TestSpaceUsedTotalAndBySatellite(t *testing.T) {
for _, enabled := range []bool{false, true} {
testplanet.Run(t, testplanet.Config{
SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 1,
Reconfigure: testplanet.Reconfigure{
StorageNode: func(index int, config *storagenode.Config) {
config.Pieces.EnableLazyFilewalker = enabled
},
},
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
err := planet.Uplinks[0].Upload(ctx, planet.Satellites[0], "bucket", "object", testrand.Bytes(5*memory.KiB))
require.NoError(t, err)

satelliteID := planet.Satellites[0].ID()
totalPiecesSize, totalContentSize, bySatellite, err := planet.StorageNodes[0].Storage2.Store.SpaceUsedTotalAndBySatellite(ctx)
require.NoError(t, err)
require.EqualValues(t, 8192, totalPiecesSize)
require.EqualValues(t, 7680, totalContentSize)
require.EqualValues(t, 8192, bySatellite[satelliteID].Total)
require.EqualValues(t, 7680, bySatellite[satelliteID].ContentSize)
})
}
}

func storeSinglePiece(ctx *testcontext.Context, t testing.TB, store *pieces.Store, satelliteID storj.NodeID, pieceID storj.PieceID, data []byte) {
writer, err := store.Writer(ctx, satelliteID, pieceID, pb.PieceHashAlgorithm_SHA256)
require.NoError(t, err)
Expand Down

3 comments on commit 554b80e

@storjrobot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Storj Community Forum (official). There might be relevant details there:

https://forum.storj.io/t/filewalker-not-running-when-disabling-lazyfilewalker/26717/13

@storjrobot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Storj Community Forum (official). There might be relevant details there:

https://forum.storj.io/t/error-filewalker-failed-to-get-progress-from-database/26654/43

@storjrobot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Storj Community Forum (official). There might be relevant details there:

https://forum.storj.io/t/disk-usage-discrepancy/24715/1059

Please sign in to comment.