2020-12-03 12:01:21 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2021-05-31 11:03:17 +00:00
|
|
|
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
|
2020-12-03 12:01:21 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
2020-12-08 09:56:14 +00:00
|
|
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
2020-12-03 12:01:21 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2021-01-22 13:21:45 +00:00
|
|
|
type ListContainersPrm struct{}
|
|
|
|
|
|
|
|
type ListContainersRes struct {
|
2021-05-31 11:03:17 +00:00
|
|
|
containers []*cid.ID
|
2021-01-22 13:21:45 +00:00
|
|
|
}
|
|
|
|
|
2021-05-31 11:03:17 +00:00
|
|
|
func (r *ListContainersRes) Containers() []*cid.ID {
|
2021-01-22 13:21:45 +00:00
|
|
|
return r.containers
|
|
|
|
}
|
|
|
|
|
2020-12-03 12:01:21 +00:00
|
|
|
func (s *Shard) List() (*SelectRes, error) {
|
|
|
|
lst, err := s.metaBase.Containers()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("can't list stored containers: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
res := new(SelectRes)
|
|
|
|
filters := object.NewSearchFilters()
|
|
|
|
|
|
|
|
for i := range lst {
|
2020-12-10 13:20:38 +00:00
|
|
|
ids, err := meta.Select(s.metaBase, lst[i], filters) // consider making List in metabase
|
2020-12-03 12:01:21 +00:00
|
|
|
if err != nil {
|
|
|
|
s.log.Debug("can't select all objects",
|
|
|
|
zap.Stringer("cid", lst[i]),
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
res.addrList = append(res.addrList, ids...)
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
2021-01-22 13:21:45 +00:00
|
|
|
|
|
|
|
func (s *Shard) ListContainers(_ *ListContainersPrm) (*ListContainersRes, error) {
|
|
|
|
containers, err := s.metaBase.Containers()
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not get list of containers: %w", err)
|
2021-01-22 13:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &ListContainersRes{
|
|
|
|
containers: containers,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-05-31 11:03:17 +00:00
|
|
|
func ListContainers(s *Shard) ([]*cid.ID, error) {
|
2021-01-22 13:21:45 +00:00
|
|
|
res, err := s.ListContainers(&ListContainersPrm{})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.Containers(), nil
|
|
|
|
}
|