From f16cf5cccf0f97aee7efa03e5d3538da5681399c Mon Sep 17 00:00:00 2001 From: Qweder93 Date: Sun, 2 Aug 2020 19:21:43 +0300 Subject: [PATCH] storagenode/console & /inspector: added recalculation of disk space info Change-Id: Id003d031a6464ec095c31290fd6a756ead644261 --- storagenode/console/service.go | 23 +++++++++++++++++++---- storagenode/inspector/inspector.go | 13 ++++++++++++- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/storagenode/console/service.go b/storagenode/console/service.go index 3a88d563d..a59e60744 100644 --- a/storagenode/console/service.go +++ b/storagenode/console/service.go @@ -182,10 +182,25 @@ func (s *Service) GetDashboardData(ctx context.Context) (_ *Dashboard, err error return nil, SNOServiceErr.Wrap(err) } - data.DiskSpace = DiskSpaceInfo{ - Used: pieceTotal, - Available: s.allocatedDiskSpace.Int64(), - Trash: trash, + // temporary solution - in case we receive negative amount of free space we recalculate dir disk available space and recalculates used space. + // TODO: find real reason of negative space, garbage collector calculates trash correctly. + if s.allocatedDiskSpace.Int64()-pieceTotal-trash < 0 { + status, err := s.pieceStore.StorageStatus(ctx) + if err != nil { + return nil, SNOServiceErr.Wrap(err) + } + + data.DiskSpace = DiskSpaceInfo{ + Used: s.allocatedDiskSpace.Int64() - status.DiskFree - trash, + Available: s.allocatedDiskSpace.Int64(), + Trash: trash, + } + } else { + data.DiskSpace = DiskSpaceInfo{ + Used: pieceTotal, + Available: s.allocatedDiskSpace.Int64(), + Trash: trash, + } } data.Bandwidth = BandwidthInfo{ diff --git a/storagenode/inspector/inspector.go b/storagenode/inspector/inspector.go index ca5c42317..d1afdd38c 100644 --- a/storagenode/inspector/inspector.go +++ b/storagenode/inspector/inspector.go @@ -89,10 +89,21 @@ func (inspector *Endpoint) retrieveStats(ctx context.Context) (_ *pb.StatSummary egress := usage.Get + usage.GetAudit + usage.GetRepair totalUsedBandwidth := usage.Total() + availableSpace := inspector.pieceStoreConfig.AllocatedDiskSpace.Int64() - piecesContentSize + // temporary solution: in case we receive negative amount of free space we recalculate dir disk available space. + // TODO: find real reason of negative space, garbage collector calculates trash correctly. + if availableSpace < 0 { + status, err := inspector.pieceStore.StorageStatus(ctx) + if err != nil { + return nil, rpcstatus.Error(rpcstatus.Internal, err.Error()) + } + + availableSpace = status.DiskFree + } return &pb.StatSummaryResponse{ UsedSpace: piecesContentSize, - AvailableSpace: inspector.pieceStoreConfig.AllocatedDiskSpace.Int64() - piecesContentSize, + AvailableSpace: availableSpace, UsedIngress: ingress, UsedEgress: egress, UsedBandwidth: totalUsedBandwidth,