frostfs-node/pkg/local_object_storage/blobstor/info.go
Evgenii Stratonikov f8c6e05e1c
All checks were successful
Tests and linters / Run gofumpt (pull_request) Successful in 1m56s
DCO action / DCO (pull_request) Successful in 2m15s
Vulncheck / Vulncheck (pull_request) Successful in 2m24s
Tests and linters / Tests (1.22) (pull_request) Successful in 2m54s
Build / Build Components (1.22) (pull_request) Successful in 2m53s
Build / Build Components (1.23) (pull_request) Successful in 2m52s
Tests and linters / Lint (pull_request) Successful in 3m24s
Pre-commit hooks / Pre-commit (pull_request) Successful in 3m3s
Tests and linters / Tests (1.23) (pull_request) Successful in 3m22s
Tests and linters / Staticcheck (pull_request) Successful in 3m25s
Tests and linters / gopls check (pull_request) Successful in 4m0s
Tests and linters / Tests with -race (pull_request) Successful in 4m12s
[#1341] .golangci.yml: Replace exportloopref with copyloopvar
exportloopref is deprecated.
gopatch:
```
@@
var index, value identifier
var slice expression
@@
for index, value := range slice {
...
-value := value
...
}

@@
var index, value identifier
var slice expression
@@
for index, value := range slice {
...
-index := index
...
}

@@
var value identifier
var channel expression
@@
for value := range channel {
...
-value := value
...
}
```

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-08-28 15:00:05 +03:00

61 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 {
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
}