ae345320fe
It turns out that some DB methods are not passing context to to lower levels even if have context as a parameter. Change-Id: I82f4fc1a47c362687a91364d85e4468057e53134
42 lines
1.1 KiB
Go
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.QueryRowContext(ctx, `SELECT count(*) FROM objects `+db.impl.AsOfSystemInterval(opts.AsOfSystemInterval))
|
|
return Error.Wrap(row.Scan(&result.ObjectCount))
|
|
})
|
|
group.Go(func() error {
|
|
row := db.db.QueryRowContext(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
|
|
}
|