forked from TrueCloudLab/frostfs-node
Revert commit 0faa40e4 to increase the disk space consumed by the metabase in favor of the speed of index updates. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>support/v0.27
parent
3c42f5b452
commit
fcb35d82cf
|
@ -1,9 +1,6 @@
|
|||
package meta
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
|
||||
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
v2object "github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||
|
@ -64,19 +61,16 @@ func (db *DB) Put(obj *object.Object) error {
|
|||
return errors.Wrapf(err, "(%T) could not create bucket for header key", db)
|
||||
}
|
||||
|
||||
v := nonEmptyKeyBytes([]byte(indices[i].val))
|
||||
v := []byte(indices[i].val)
|
||||
|
||||
strs, err := decodeAddressList(keyBucket.Get(v))
|
||||
// create address bucket for the value
|
||||
valBucket, err := keyBucket.CreateBucketIfNotExists(nonEmptyKeyBytes(v))
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "(%T) could not decode address list", db)
|
||||
return errors.Wrapf(err, "(%T) could not create bucket for header value", db)
|
||||
}
|
||||
|
||||
data, err := encodeAddressList(append(strs, string(addrKey)))
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "(%T) could not encode address list", db)
|
||||
}
|
||||
|
||||
if err := keyBucket.Put(v, data); err != nil {
|
||||
// put object address to value bucket
|
||||
if err := valBucket.Put(addrKey, nil); err != nil {
|
||||
return errors.Wrapf(err, "(%T) could not put item to header bucket", db)
|
||||
}
|
||||
}
|
||||
|
@ -160,30 +154,3 @@ func objectIndices(obj *object.Object, parent bool) []bucketItem {
|
|||
|
||||
return res
|
||||
}
|
||||
|
||||
// FIXME: gob is a temporary solution, use protobuf.
|
||||
func decodeAddressList(data []byte) ([]string, error) {
|
||||
if len(data) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var strs []string
|
||||
|
||||
decoder := gob.NewDecoder(bytes.NewReader(data))
|
||||
if err := decoder.Decode(&strs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return strs, nil
|
||||
}
|
||||
|
||||
func encodeAddressList(l []string) ([]byte, error) {
|
||||
buf := bytes.NewBuffer(nil)
|
||||
encoder := gob.NewEncoder(buf)
|
||||
|
||||
if err := encoder.Encode(l); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
|
|
@ -53,18 +53,15 @@ func (db *DB) selectObjects(tx *bbolt.Tx, fs object.SearchFilters) ([]*object.Ad
|
|||
if err := keyBucket.ForEach(func(k, v []byte) error {
|
||||
include := matchFunc(string(key), string(cutKeyBytes(k)), fVal)
|
||||
|
||||
strs, err := decodeAddressList(v)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "(%T) could not decode address list", db)
|
||||
}
|
||||
if include {
|
||||
return keyBucket.Bucket(k).ForEach(func(k, _ []byte) error {
|
||||
if num := mAddr[string(k)]; num == fNum {
|
||||
// otherwise object does not match current or some previous filter
|
||||
mAddr[string(k)] = fNum + 1
|
||||
}
|
||||
|
||||
for j := range strs {
|
||||
if num := mAddr[strs[j]]; num != fNum {
|
||||
// than object does not match some previous filter
|
||||
continue
|
||||
} else if include {
|
||||
mAddr[strs[j]] = fNum + 1
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue