Dmitrii Stepanov
1b17258c04
All checks were successful
DCO action / DCO (pull_request) Successful in 1m22s
Vulncheck / Vulncheck (pull_request) Successful in 3m11s
Build / Build Components (1.21) (pull_request) Successful in 3m56s
Build / Build Components (1.20) (pull_request) Successful in 3m59s
Tests and linters / Staticcheck (pull_request) Successful in 5m31s
Tests and linters / gopls check (pull_request) Successful in 5m26s
Tests and linters / Lint (pull_request) Successful in 6m13s
Tests and linters / Tests (1.20) (pull_request) Successful in 8m54s
Tests and linters / Tests (1.21) (pull_request) Successful in 9m13s
Tests and linters / Tests with -race (pull_request) Successful in 9m30s
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
62 lines
1.2 KiB
Go
62 lines
1.2 KiB
Go
package blobstor
|
|
|
|
import (
|
|
"context"
|
|
"sync/atomic"
|
|
"time"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
|
"golang.org/x/sync/errgroup"
|
|
)
|
|
|
|
// DumpInfo returns information about blob stor.
|
|
func (b *BlobStor) DumpInfo() Info {
|
|
b.modeMtx.RLock()
|
|
defer b.modeMtx.RUnlock()
|
|
|
|
sub := make([]SubStorageInfo, len(b.storage))
|
|
for i := range b.storage {
|
|
sub[i].Path = b.storage[i].Storage.Path()
|
|
sub[i].Type = b.storage[i].Storage.Type()
|
|
}
|
|
|
|
return Info{
|
|
SubStorages: sub,
|
|
}
|
|
}
|
|
|
|
// ObjectsCount returns Blobstore's total objects count.
|
|
func (b *BlobStor) ObjectsCount(ctx context.Context) (uint64, error) {
|
|
var err error
|
|
startedAt := time.Now()
|
|
defer func() {
|
|
b.metrics.ObjectsCount(time.Since(startedAt), err == nil)
|
|
}()
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "BlobStor.ObjectsCount")
|
|
defer span.End()
|
|
|
|
b.modeMtx.RLock()
|
|
defer b.modeMtx.RUnlock()
|
|
|
|
var result atomic.Uint64
|
|
|
|
eg, egCtx := errgroup.WithContext(ctx)
|
|
for i := range b.storage {
|
|
i := i
|
|
eg.Go(func() error {
|
|
v, e := b.storage[i].Storage.ObjectsCount(egCtx)
|
|
if e != nil {
|
|
return e
|
|
}
|
|
result.Add(v)
|
|
return nil
|
|
})
|
|
}
|
|
|
|
if err = eg.Wait(); err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return result.Load(), nil
|
|
}
|