2021-01-22 11:36:16 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
2023-12-27 15:58:36 +00:00
|
|
|
"context"
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2023-12-27 15:58:36 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
2023-03-07 13:38:26 +00:00
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
2023-12-27 15:58:36 +00:00
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
|
|
"go.opentelemetry.io/otel/trace"
|
2021-01-22 11:36:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ContainerSizePrm struct {
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr cid.ID
|
2021-01-22 11:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ContainerSizeRes struct {
|
|
|
|
size uint64
|
|
|
|
}
|
|
|
|
|
2022-07-13 12:43:04 +00:00
|
|
|
func (p *ContainerSizePrm) SetContainerID(cnr cid.ID) {
|
|
|
|
p.cnr = cnr
|
2021-01-22 11:36:16 +00:00
|
|
|
}
|
|
|
|
|
2022-05-20 18:08:59 +00:00
|
|
|
func (r ContainerSizeRes) Size() uint64 {
|
2021-01-22 11:36:16 +00:00
|
|
|
return r.size
|
|
|
|
}
|
|
|
|
|
2022-05-31 11:50:39 +00:00
|
|
|
func (s *Shard) ContainerSize(prm ContainerSizePrm) (ContainerSizeRes, error) {
|
2022-10-26 06:12:09 +00:00
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
|
|
return ContainerSizeRes{}, ErrDegradedMode
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
size, err := s.metaBase.ContainerSize(prm.cnr)
|
2021-01-22 11:36:16 +00:00
|
|
|
if err != nil {
|
2022-05-31 11:50:39 +00:00
|
|
|
return ContainerSizeRes{}, fmt.Errorf("could not get container size: %w", err)
|
2021-01-22 11:36:16 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 11:50:39 +00:00
|
|
|
return ContainerSizeRes{
|
2021-01-22 11:36:16 +00:00
|
|
|
size: size,
|
|
|
|
}, nil
|
|
|
|
}
|
2023-12-27 15:58:36 +00:00
|
|
|
|
|
|
|
func (s *Shard) DeleteContainerSize(ctx context.Context, id cid.ID) error {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Shard.DeleteContainerSize",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("shard_id", s.ID().String()),
|
|
|
|
attribute.Stringer("container_id", id),
|
|
|
|
))
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
if s.info.Mode.ReadOnly() {
|
|
|
|
return ErrReadOnlyMode
|
|
|
|
}
|
|
|
|
|
|
|
|
if s.info.Mode.NoMetabase() {
|
|
|
|
return ErrDegradedMode
|
|
|
|
}
|
|
|
|
|
|
|
|
return s.metaBase.DeleteContainerSize(ctx, id)
|
|
|
|
}
|