Dmitrii Stepanov
9bda6e0b8b
All checks were successful
ci/woodpecker/push/pre-commit Pipeline was successful
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package meta
|
|
|
|
import (
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
"go.etcd.io/bbolt"
|
|
)
|
|
|
|
// GetChildren returns parent -> children map.
|
|
// If an object has no children, then map will contain addr -> empty slice value.
|
|
func (db *DB) GetChildren(addresses []oid.Address) (map[oid.Address][]oid.Address, error) {
|
|
db.modeMtx.RLock()
|
|
defer db.modeMtx.RUnlock()
|
|
|
|
if db.mode.NoMetabase() {
|
|
return nil, ErrDegradedMode
|
|
}
|
|
|
|
result := make(map[oid.Address][]oid.Address, len(addresses))
|
|
|
|
buffer := make([]byte, bucketKeySize)
|
|
err := db.boltDB.View(func(tx *bbolt.Tx) error {
|
|
for _, addr := range addresses {
|
|
if _, found := result[addr]; found {
|
|
continue
|
|
}
|
|
|
|
result[addr] = []oid.Address{}
|
|
bkt := tx.Bucket(parentBucketName(addr.Container(), buffer))
|
|
if bkt == nil {
|
|
continue
|
|
}
|
|
|
|
binObjIDs, err := decodeList(bkt.Get(objectKey(addr.Object(), buffer)))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, binObjID := range binObjIDs {
|
|
var id oid.ID
|
|
if err = id.Decode(binObjID); err != nil {
|
|
return err
|
|
}
|
|
var resultAddress oid.Address
|
|
resultAddress.SetContainer(addr.Container())
|
|
resultAddress.SetObject(id)
|
|
result[addr] = append(result[addr], resultAddress)
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return result, nil
|
|
}
|