From f5b1e77cf2a85e249b014302a1b165dc9b82f548 Mon Sep 17 00:00:00 2001 From: Cameron Date: Thu, 24 Jan 2019 15:41:22 -0500 Subject: [PATCH] rollup timestamp fix (#1132) * create timestamp if isNew * pass isNil into SaveRollup --- pkg/accounting/db.go | 2 +- pkg/accounting/rollup/rollup.go | 2 +- satellite/satellitedb/accounting.go | 11 ++++++++--- satellite/satellitedb/locked.go | 4 ++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pkg/accounting/db.go b/pkg/accounting/db.go index 29d773ab3..17ae0ca40 100644 --- a/pkg/accounting/db.go +++ b/pkg/accounting/db.go @@ -53,7 +53,7 @@ type DB interface { // GetRawSince r retrieves all raw tallies sinces GetRawSince(ctx context.Context, latestRollup time.Time) ([]*Raw, error) // SaveRollup records raw tallies of at rest data to the database - SaveRollup(ctx context.Context, latestTally time.Time, stats RollupStats) error + SaveRollup(ctx context.Context, latestTally time.Time, isNew bool, stats RollupStats) error // QueryPaymentInfo queries StatDB, Accounting Rollup on nodeID QueryPaymentInfo(ctx context.Context, start time.Time, end time.Time) ([]*CSVRow, error) } diff --git a/pkg/accounting/rollup/rollup.go b/pkg/accounting/rollup/rollup.go index aab270eee..aee3051fb 100644 --- a/pkg/accounting/rollup/rollup.go +++ b/pkg/accounting/rollup/rollup.go @@ -115,5 +115,5 @@ func (r *Rollup) Query(ctx context.Context) error { r.logger.Info("Rollup only found tallies for today") return nil } - return Error.Wrap(r.db.SaveRollup(ctx, latestTally, rollupStats)) + return Error.Wrap(r.db.SaveRollup(ctx, latestTally, isNil, rollupStats)) } diff --git a/satellite/satellitedb/accounting.go b/satellite/satellitedb/accounting.go index 45b773b40..87b47e230 100644 --- a/satellite/satellitedb/accounting.go +++ b/satellite/satellitedb/accounting.go @@ -152,7 +152,7 @@ func (db *accountingDB) GetRawSince(ctx context.Context, latestRollup time.Time) } // SaveRollup records raw tallies of at rest data to the database -func (db *accountingDB) SaveRollup(ctx context.Context, latestRollup time.Time, stats accounting.RollupStats) error { +func (db *accountingDB) SaveRollup(ctx context.Context, latestRollup time.Time, isNew bool, stats accounting.RollupStats) error { if len(stats) == 0 { return Error.New("In SaveRollup with empty nodeData") } @@ -183,8 +183,13 @@ func (db *accountingDB) SaveRollup(ctx context.Context, latestRollup time.Time, } } } - update := dbx.AccountingTimestamps_Update_Fields{Value: dbx.AccountingTimestamps_Value(latestRollup)} - _, err = tx.Update_AccountingTimestamps_By_Name(ctx, dbx.AccountingTimestamps_Name(accounting.LastRollup), update) + if isNew { + update := dbx.AccountingTimestamps_Value(latestRollup) + _, err = tx.Create_AccountingTimestamps(ctx, dbx.AccountingTimestamps_Name(accounting.LastRollup), update) + } else { + update := dbx.AccountingTimestamps_Update_Fields{Value: dbx.AccountingTimestamps_Value(latestRollup)} + _, err = tx.Update_AccountingTimestamps_By_Name(ctx, dbx.AccountingTimestamps_Name(accounting.LastRollup), update) + } return Error.Wrap(err) } diff --git a/satellite/satellitedb/locked.go b/satellite/satellitedb/locked.go index 0d4ae031e..8f0c0c070 100644 --- a/satellite/satellitedb/locked.go +++ b/satellite/satellitedb/locked.go @@ -84,10 +84,10 @@ func (m *lockedAccounting) SaveBWRaw(ctx context.Context, latestBwa time.Time, i } // SaveRollup records raw tallies of at rest data to the database -func (m *lockedAccounting) SaveRollup(ctx context.Context, latestTally time.Time, stats accounting.RollupStats) error { +func (m *lockedAccounting) SaveRollup(ctx context.Context, latestTally time.Time, isNew bool, stats accounting.RollupStats) error { m.Lock() defer m.Unlock() - return m.db.SaveRollup(ctx, latestTally, stats) + return m.db.SaveRollup(ctx, latestTally, isNew, stats) } // BandwidthAgreement returns database for storing bandwidth agreements