frostfs-node/pkg/local_object_storage/engine/container.go
Dmitrii Stepanov 8a57c78f5f
All checks were successful
Tests and linters / Run gofumpt (pull_request) Successful in 2m38s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m51s
DCO action / DCO (pull_request) Successful in 2m53s
Vulncheck / Vulncheck (pull_request) Successful in 3m44s
Tests and linters / gopls check (pull_request) Successful in 3m53s
Build / Build Components (pull_request) Successful in 4m15s
Tests and linters / Staticcheck (pull_request) Successful in 4m56s
Tests and linters / Tests with -race (pull_request) Successful in 5m5s
Tests and linters / Lint (pull_request) Successful in 5m47s
Tests and linters / Tests (pull_request) Successful in 5m51s
[#1484] engine: Fix engine metrics
1. Add forgotten metrics for client requests
2. Include execIfNotBlocked into metrics

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2024-11-11 12:59:20 +03:00

146 lines
3.7 KiB
Go

package engine
import (
"context"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
"go.uber.org/zap"
)
// ContainerSizePrm groups parameters of ContainerSize operation.
type ContainerSizePrm struct {
cnr cid.ID
}
// ContainerSizeRes resulting values of ContainerSize operation.
type ContainerSizeRes struct {
size uint64
}
// ListContainersPrm groups parameters of ListContainers operation.
type ListContainersPrm struct{}
// ListContainersRes groups the resulting values of ListContainers operation.
type ListContainersRes struct {
containers []cid.ID
}
// SetContainerID sets the identifier of the container to estimate the size.
func (p *ContainerSizePrm) SetContainerID(cnr cid.ID) {
p.cnr = cnr
}
// Size returns calculated estimation of the container size.
func (r ContainerSizeRes) Size() uint64 {
return r.size
}
// Containers returns a list of identifiers of the containers in which local objects are stored.
func (r ListContainersRes) Containers() []cid.ID {
return r.containers
}
// ContainerSize returns the sum of estimation container sizes among all shards.
//
// Returns an error if executions are blocked (see BlockExecution).
func (e *StorageEngine) ContainerSize(prm ContainerSizePrm) (res ContainerSizeRes, err error) {
defer elapsed("ContainerSize", e.metrics.AddMethodDuration)()
err = e.execIfNotBlocked(func() error {
res, err = e.containerSize(prm)
return err
})
return
}
// ContainerSize calls ContainerSize method on engine to calculate sum of estimation container sizes among all shards.
func ContainerSize(e *StorageEngine, id cid.ID) (uint64, error) {
var prm ContainerSizePrm
prm.SetContainerID(id)
res, err := e.ContainerSize(prm)
if err != nil {
return 0, err
}
return res.Size(), nil
}
func (e *StorageEngine) containerSize(prm ContainerSizePrm) (res ContainerSizeRes, err error) {
e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
var csPrm shard.ContainerSizePrm
csPrm.SetContainerID(prm.cnr)
csRes, err := sh.Shard.ContainerSize(csPrm)
if err != nil {
e.reportShardError(sh, "can't get container size", err,
zap.Stringer("container_id", prm.cnr))
return false
}
res.size += csRes.Size()
return false
})
return
}
// ListContainers returns a unique container IDs presented in the engine objects.
//
// Returns an error if executions are blocked (see BlockExecution).
func (e *StorageEngine) ListContainers(ctx context.Context, _ ListContainersPrm) (res ListContainersRes, err error) {
defer elapsed("ListContainers", e.metrics.AddMethodDuration)()
err = e.execIfNotBlocked(func() error {
res, err = e.listContainers(ctx)
return err
})
return
}
// ListContainers calls ListContainers method on engine to get a unique container IDs presented in the engine objects.
func ListContainers(ctx context.Context, e *StorageEngine) ([]cid.ID, error) {
var prm ListContainersPrm
res, err := e.ListContainers(ctx, prm)
if err != nil {
return nil, err
}
return res.Containers(), nil
}
func (e *StorageEngine) listContainers(ctx context.Context) (ListContainersRes, error) {
uniqueIDs := make(map[string]cid.ID)
e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
res, err := sh.Shard.ListContainers(ctx, shard.ListContainersPrm{})
if err != nil {
e.reportShardError(sh, "can't get list of containers", err)
return false
}
for _, cnr := range res.Containers() {
id := cnr.EncodeToString()
if _, ok := uniqueIDs[id]; !ok {
uniqueIDs[id] = cnr
}
}
return false
})
result := make([]cid.ID, 0, len(uniqueIDs))
for _, v := range uniqueIDs {
result = append(result, v)
}
return ListContainersRes{
containers: result,
}, nil
}