2020-12-03 12:01:21 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2023-03-07 13:38:26 +00:00
|
|
|
objectcore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2020-12-03 12:01:21 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2021-11-11 14:27:11 +00:00
|
|
|
// Cursor is a type for continuous object listing.
|
|
|
|
type Cursor = meta.Cursor
|
|
|
|
|
2021-11-17 11:31:31 +00:00
|
|
|
// ErrEndOfListing is returned from object listing with cursor
|
|
|
|
// when storage can't return any more objects after provided
|
|
|
|
// cursor. Use nil cursor object to start listing again.
|
|
|
|
var ErrEndOfListing = meta.ErrEndOfListing
|
|
|
|
|
2021-01-22 13:21:45 +00:00
|
|
|
type ListContainersPrm struct{}
|
|
|
|
|
|
|
|
type ListContainersRes struct {
|
2022-05-31 17:00:41 +00:00
|
|
|
containers []cid.ID
|
2021-01-22 13:21:45 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 11:50:39 +00:00
|
|
|
func (r ListContainersRes) Containers() []cid.ID {
|
2021-01-22 13:21:45 +00:00
|
|
|
return r.containers
|
|
|
|
}
|
|
|
|
|
2021-10-27 13:33:26 +00:00
|
|
|
// ListWithCursorPrm contains parameters for ListWithCursor operation.
|
|
|
|
type ListWithCursorPrm struct {
|
|
|
|
count uint32
|
2021-11-11 14:27:11 +00:00
|
|
|
cursor *Cursor
|
2021-10-27 13:33:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListWithCursorRes contains values returned from ListWithCursor operation.
|
|
|
|
type ListWithCursorRes struct {
|
2022-11-12 13:48:44 +00:00
|
|
|
addrList []objectcore.AddressWithType
|
2021-11-11 14:27:11 +00:00
|
|
|
cursor *Cursor
|
2021-10-27 13:33:26 +00:00
|
|
|
}
|
|
|
|
|
2021-11-12 09:52:19 +00:00
|
|
|
// WithCount sets maximum amount of addresses that ListWithCursor should return.
|
2022-05-20 18:08:59 +00:00
|
|
|
func (p *ListWithCursorPrm) WithCount(count uint32) {
|
2021-10-27 13:33:26 +00:00
|
|
|
p.count = count
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithCursor sets cursor for ListWithCursor operation. For initial request,
|
2021-11-12 09:52:19 +00:00
|
|
|
// ignore this param or use nil value. For consecutive requests, use value
|
2021-10-27 13:33:26 +00:00
|
|
|
// from ListWithCursorRes.
|
2022-05-20 18:08:59 +00:00
|
|
|
func (p *ListWithCursorPrm) WithCursor(cursor *Cursor) {
|
2021-10-27 13:33:26 +00:00
|
|
|
p.cursor = cursor
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddressList returns addresses selected by ListWithCursor operation.
|
2022-11-12 13:48:44 +00:00
|
|
|
func (r ListWithCursorRes) AddressList() []objectcore.AddressWithType {
|
2021-10-27 13:33:26 +00:00
|
|
|
return r.addrList
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cursor returns cursor for consecutive listing requests.
|
2021-11-11 14:27:11 +00:00
|
|
|
func (r ListWithCursorRes) Cursor() *Cursor {
|
2021-10-27 13:33:26 +00:00
|
|
|
return r.cursor
|
|
|
|
}
|
|
|
|
|
2021-09-24 15:04:00 +00:00
|
|
|
// List returns all objects physically stored in the Shard.
|
2022-05-31 11:50:39 +00:00
|
|
|
func (s *Shard) List() (res SelectRes, err error) {
|
2022-12-07 17:42:35 +00:00
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
if s.info.Mode.NoMetabase() {
|
2022-10-26 06:12:09 +00:00
|
|
|
return SelectRes{}, ErrDegradedMode
|
|
|
|
}
|
|
|
|
|
2020-12-03 12:01:21 +00:00
|
|
|
lst, err := s.metaBase.Containers()
|
|
|
|
if err != nil {
|
2022-05-31 11:50:39 +00:00
|
|
|
return res, fmt.Errorf("can't list stored containers: %w", err)
|
2020-12-03 12:01:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
filters := object.NewSearchFilters()
|
2021-09-24 15:04:00 +00:00
|
|
|
filters.AddPhyFilter()
|
2020-12-03 12:01:21 +00:00
|
|
|
|
|
|
|
for i := range lst {
|
2022-07-12 14:42:55 +00:00
|
|
|
var sPrm meta.SelectPrm
|
2022-07-12 14:59:37 +00:00
|
|
|
sPrm.SetContainerID(lst[i])
|
|
|
|
sPrm.SetFilters(filters)
|
2022-07-12 14:42:55 +00:00
|
|
|
|
|
|
|
sRes, err := s.metaBase.Select(sPrm) // consider making List in metabase
|
2020-12-03 12:01:21 +00:00
|
|
|
if err != nil {
|
2023-04-12 14:35:10 +00:00
|
|
|
s.log.Debug(logs.ShardCantSelectAllObjects,
|
2020-12-03 12:01:21 +00:00
|
|
|
zap.Stringer("cid", lst[i]),
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-07-12 14:42:55 +00:00
|
|
|
res.addrList = append(res.addrList, sRes.AddressList()...)
|
2020-12-03 12:01:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
2021-01-22 13:21:45 +00:00
|
|
|
|
2022-05-31 11:50:39 +00:00
|
|
|
func (s *Shard) ListContainers(_ ListContainersPrm) (ListContainersRes, error) {
|
2022-10-26 06:12:09 +00:00
|
|
|
if s.GetMode().NoMetabase() {
|
|
|
|
return ListContainersRes{}, ErrDegradedMode
|
|
|
|
}
|
|
|
|
|
2021-01-22 13:21:45 +00:00
|
|
|
containers, err := s.metaBase.Containers()
|
|
|
|
if err != nil {
|
2022-05-31 11:50:39 +00:00
|
|
|
return ListContainersRes{}, fmt.Errorf("could not get list of containers: %w", err)
|
2021-01-22 13:21:45 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 11:50:39 +00:00
|
|
|
return ListContainersRes{
|
2021-01-22 13:21:45 +00:00
|
|
|
containers: containers,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-10-27 13:33:26 +00:00
|
|
|
// ListWithCursor lists physical objects available in shard starting from
|
|
|
|
// cursor. Includes regular, tombstone and storage group objects. Does not
|
|
|
|
// include inhumed objects. Use cursor value from response for consecutive requests.
|
2021-11-12 09:52:19 +00:00
|
|
|
//
|
|
|
|
// Returns ErrEndOfListing if there are no more objects to return or count
|
|
|
|
// parameter set to zero.
|
2022-05-31 11:50:39 +00:00
|
|
|
func (s *Shard) ListWithCursor(prm ListWithCursorPrm) (ListWithCursorRes, error) {
|
2022-06-29 11:27:36 +00:00
|
|
|
if s.GetMode().NoMetabase() {
|
|
|
|
return ListWithCursorRes{}, ErrDegradedMode
|
|
|
|
}
|
|
|
|
|
2022-05-20 16:48:14 +00:00
|
|
|
var metaPrm meta.ListPrm
|
2022-07-12 14:59:37 +00:00
|
|
|
metaPrm.SetCount(prm.count)
|
|
|
|
metaPrm.SetCursor(prm.cursor)
|
2021-10-27 13:33:26 +00:00
|
|
|
res, err := s.metaBase.ListWithCursor(metaPrm)
|
|
|
|
if err != nil {
|
2022-05-31 11:50:39 +00:00
|
|
|
return ListWithCursorRes{}, fmt.Errorf("could not get list of objects: %w", err)
|
2021-10-27 13:33:26 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 11:50:39 +00:00
|
|
|
return ListWithCursorRes{
|
2021-10-27 13:33:26 +00:00
|
|
|
addrList: res.AddressList(),
|
|
|
|
cursor: res.Cursor(),
|
|
|
|
}, nil
|
|
|
|
}
|