satellitedb: do saverollup in batches
Change-Id: I78278a192cba60541eee2986f54a88d5a479bd3e
This commit is contained in:
parent
0ba516d405
commit
6aae21541f
@ -327,6 +327,7 @@ func cmdRun(cmd *cobra.Command, args []string) (err error) {
|
||||
|
||||
db, err := satellitedb.Open(ctx, log.Named("db"), runCfg.Database, satellitedb.Options{
|
||||
ReportedRollupsReadBatchSize: runCfg.Orders.SettlementBatchSize,
|
||||
SaveRollupBatchSize: runCfg.Tally.SaveRollupBatchSize,
|
||||
})
|
||||
if err != nil {
|
||||
return errs.New("Error starting master database on satellite: %+v", err)
|
||||
|
@ -27,7 +27,8 @@ var (
|
||||
|
||||
// Config contains configurable values for the tally service.
|
||||
type Config struct {
|
||||
Interval time.Duration `help:"how frequently the tally service should run" releaseDefault:"1h" devDefault:"30s"`
|
||||
Interval time.Duration `help:"how frequently the tally service should run" releaseDefault:"1h" devDefault:"30s"`
|
||||
SaveRollupBatchSize int `help:"how large of batches SaveRollup should process at a time" default:"1000"`
|
||||
}
|
||||
|
||||
// Service is the tally service for data stored on each storage node
|
||||
|
@ -73,6 +73,9 @@ type Options struct {
|
||||
// How many records to read in a single transaction when asked for all of the
|
||||
// billable bandwidth from the reported serials table.
|
||||
ReportedRollupsReadBatchSize int
|
||||
|
||||
// How many storage node rollups to save in one batch.
|
||||
SaveRollupBatchSize int
|
||||
}
|
||||
|
||||
var _ dbx.DBMethods = &satelliteDB{}
|
||||
|
@ -152,9 +152,26 @@ func (db *StoragenodeAccounting) SaveRollup(ctx context.Context, latestRollup ti
|
||||
if len(stats) == 0 {
|
||||
return Error.New("In SaveRollup with empty nodeData")
|
||||
}
|
||||
err = db.db.WithTx(ctx, func(ctx context.Context, tx *dbx.Tx) error {
|
||||
for _, arsByDate := range stats {
|
||||
for _, ar := range arsByDate {
|
||||
|
||||
batchSize := db.db.opts.SaveRollupBatchSize
|
||||
if batchSize <= 0 {
|
||||
batchSize = 1000
|
||||
}
|
||||
|
||||
var rollups []*accounting.Rollup
|
||||
for _, arsByDate := range stats {
|
||||
for _, ar := range arsByDate {
|
||||
rollups = append(rollups, ar)
|
||||
}
|
||||
}
|
||||
finished := false
|
||||
|
||||
for !finished {
|
||||
err = db.db.WithTx(ctx, func(ctx context.Context, tx *dbx.Tx) error {
|
||||
for i := 0; i < batchSize && len(rollups) > 0; i++ {
|
||||
ar := rollups[0]
|
||||
rollups = rollups[1:]
|
||||
|
||||
nID := dbx.AccountingRollup_NodeId(ar.NodeID.Bytes())
|
||||
start := dbx.AccountingRollup_StartTime(ar.StartTime)
|
||||
put := dbx.AccountingRollup_PutTotal(ar.PutTotal)
|
||||
@ -169,16 +186,24 @@ func (db *StoragenodeAccounting) SaveRollup(ctx context.Context, latestRollup ti
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tx.UpdateNoReturn_AccountingTimestamps_By_Name(ctx,
|
||||
dbx.AccountingTimestamps_Name(accounting.LastRollup),
|
||||
dbx.AccountingTimestamps_Update_Fields{
|
||||
Value: dbx.AccountingTimestamps_Value(latestRollup),
|
||||
},
|
||||
)
|
||||
})
|
||||
return Error.Wrap(err)
|
||||
if len(rollups) == 0 {
|
||||
finished = true
|
||||
return tx.UpdateNoReturn_AccountingTimestamps_By_Name(ctx,
|
||||
dbx.AccountingTimestamps_Name(accounting.LastRollup),
|
||||
dbx.AccountingTimestamps_Update_Fields{
|
||||
Value: dbx.AccountingTimestamps_Value(latestRollup),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return Error.Wrap(err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// LastTimestamp records the greatest last tallied time.
|
||||
|
3
scripts/testdata/satellite-config.yaml.lock
vendored
3
scripts/testdata/satellite-config.yaml.lock
vendored
@ -667,6 +667,9 @@ server.private-address: 127.0.0.1:7778
|
||||
# how frequently the tally service should run
|
||||
# tally.interval: 1h0m0s
|
||||
|
||||
# how large of batches SaveRollup should process at a time
|
||||
# tally.save-rollup-batch-size: 1000
|
||||
|
||||
# address for jaeger agent
|
||||
# tracing.agent-addr: agent.tracing.datasci.storj.io:5775
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user