From 2dffaebc6fb253fc36a6f8c1bfdbabc32d9c2f4c Mon Sep 17 00:00:00 2001 From: Ivan Fraixedes Date: Tue, 3 Nov 2020 15:04:24 +0100 Subject: [PATCH] satellite/accounting: Fix and enhance code doc comments Fix and enhance the source code documentation comments for the satellite/accounting packaged. Change-Id: I965742cf378e8b6b80d18bc84a4ff76e9af1e8b7 --- satellite/accounting/live/doc.go | 2 +- satellite/accounting/tally/tally.go | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/satellite/accounting/live/doc.go b/satellite/accounting/live/doc.go index 8f3620cb9..b8e8c0d3b 100644 --- a/satellite/accounting/live/doc.go +++ b/satellite/accounting/live/doc.go @@ -4,6 +4,6 @@ /* Package live provides live accounting functionality. That is, it keeps track of deltas in the amount of storage used by each project relative to the last -tally operation (see pkg/accounting/tally). +tally operation (see satellite/accounting/tally). */ package live diff --git a/satellite/accounting/tally/tally.go b/satellite/accounting/tally/tally.go index 5b56f1779..cebd06e22 100644 --- a/satellite/accounting/tally/tally.go +++ b/satellite/accounting/tally/tally.go @@ -84,6 +84,24 @@ func (service *Service) SetNow(now func() time.Time) { } // Tally calculates data-at-rest usage once. +// +// How live accounting is calculated: +// +// At the beginning of the tally iteration, we get a map containing the current +// project totals from the cache- initialLiveTotals (our current estimation of +// the project totals). At the end of the tally iteration, we have the totals +// from what we saw during the metainfo loop. +// +// However, data which was uploaded during the loop may or may not have been +// seen in the metainfo loop. For this reason, we also read the live accounting +// totals again at the end of the tally iteration- latestLiveTotals. +// +// The difference between latest and initial indicates how much data was +// uploaded during the metainfo loop and is assigned to delta. However, again, +// we aren't certain how much of the delta is accounted for in the metainfo +// totals. For the reason we make an assumption that 50% of the data is +// accounted for. So to calculate the new live accounting totals, we sum the +// metainfo totals and 50% of the deltas. func (service *Service) Tally(ctx context.Context) (err error) { defer mon.Task()(&ctx)(&err) @@ -151,6 +169,9 @@ func (service *Service) Tally(ctx context.Context) (err error) { if delta < 0 { delta = 0 } + + // read the method documentation why the increase passed to this method + // is calculated in this way err = service.liveAccounting.AddProjectStorageUsage(ctx, projectID, -latestLiveTotals[projectID]+tallyTotal+(delta/2)) if err != nil { return Error.Wrap(err)