2021-06-07 10:20:06 +01:00
|
|
|
// 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 {
|
2021-07-28 14:44:22 +01:00
|
|
|
row := db.db.QueryRowContext(ctx, `SELECT count(*) FROM objects `+db.impl.AsOfSystemInterval(opts.AsOfSystemInterval))
|
2021-06-07 10:20:06 +01:00
|
|
|
return Error.Wrap(row.Scan(&result.ObjectCount))
|
|
|
|
})
|
|
|
|
group.Go(func() error {
|
2021-07-28 14:44:22 +01:00
|
|
|
row := db.db.QueryRowContext(ctx, `SELECT count(*) FROM segments `+db.impl.AsOfSystemInterval(opts.AsOfSystemInterval))
|
2021-06-07 10:20:06 +01:00
|
|
|
return Error.Wrap(row.Scan(&result.SegmentCount))
|
|
|
|
})
|
|
|
|
err = errs.Combine(group.Wait()...)
|
|
|
|
return result, err
|
|
|
|
}
|