storj/satellite/metabase/stats.go
Egon Elbre 0df4a27bf7 satellite/metabase: add method to get table statistics
In loop we need to start verifying it's correctness. This allows to
gather these stats.

Change-Id: I146fb50e2b3658b6f3c2682cdc1983e6abd73c29
2021-06-16 18:34:55 +03:00

42 lines
1.1 KiB
Go

// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package metabase
import (
"context"
"time"
"github.com/zeebo/errs"
"storj.io/common/errs2"
)
// GetTableStats contains arguments necessary for getting table statistics.
type GetTableStats struct {
AsOfSystemInterval time.Duration
}
// TableStats contains information about the metabase status.
type TableStats struct {
ObjectCount int64
SegmentCount int64
}
// GetTableStats gathers information about the metabase tables.
func (db *DB) GetTableStats(ctx context.Context, opts GetTableStats) (result TableStats, err error) {
defer mon.Task()(&ctx)(&err)
var group errs2.Group
group.Go(func() error {
row := db.db.QueryRow(ctx, `SELECT count(*) FROM objects `+db.impl.AsOfSystemInterval(opts.AsOfSystemInterval))
return Error.Wrap(row.Scan(&result.ObjectCount))
})
group.Go(func() error {
row := db.db.QueryRow(ctx, `SELECT count(*) FROM segments `+db.impl.AsOfSystemInterval(opts.AsOfSystemInterval))
return Error.Wrap(row.Scan(&result.SegmentCount))
})
err = errs.Combine(group.Wait()...)
return result, err
}