2020-11-19 13:52:37 +00:00
|
|
|
package blobstor
|
|
|
|
|
2024-03-12 14:36:26 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"sync/atomic"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
|
|
|
"golang.org/x/sync/errgroup"
|
|
|
|
)
|
|
|
|
|
2021-06-23 13:29:46 +00:00
|
|
|
// DumpInfo returns information about blob stor.
|
2022-10-05 12:41:36 +00:00
|
|
|
func (b *BlobStor) DumpInfo() Info {
|
2022-11-15 12:33:48 +00:00
|
|
|
b.modeMtx.RLock()
|
|
|
|
defer b.modeMtx.RUnlock()
|
|
|
|
|
2022-10-05 12:41:36 +00:00
|
|
|
sub := make([]SubStorageInfo, len(b.storage))
|
2022-07-11 12:34:17 +00:00
|
|
|
for i := range b.storage {
|
2022-10-05 12:41:36 +00:00
|
|
|
sub[i].Path = b.storage[i].Storage.Path()
|
|
|
|
sub[i].Type = b.storage[i].Storage.Type()
|
|
|
|
}
|
|
|
|
|
|
|
|
return Info{
|
|
|
|
SubStorages: sub,
|
2022-07-11 12:34:17 +00:00
|
|
|
}
|
2020-11-19 13:52:37 +00:00
|
|
|
}
|
2024-03-12 14:36:26 +00:00
|
|
|
|
|
|
|
// 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 {
|
|
|
|
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
|
|
|
|
}
|