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>
This commit is contained in:
parent
3c42f5b452
commit
fcb35d82cf
2 changed files with 14 additions and 50 deletions
|
@ -1,9 +1,6 @@
|
||||||
package meta
|
package meta
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/gob"
|
|
||||||
|
|
||||||
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||||
v2object "github.com/nspcc-dev/neofs-api-go/v2/object"
|
v2object "github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/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)
|
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 {
|
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)))
|
// put object address to value bucket
|
||||||
if err != nil {
|
if err := valBucket.Put(addrKey, nil); err != nil {
|
||||||
return errors.Wrapf(err, "(%T) could not encode address list", db)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := keyBucket.Put(v, data); err != nil {
|
|
||||||
return errors.Wrapf(err, "(%T) could not put item to header bucket", db)
|
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
|
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 {
|
if err := keyBucket.ForEach(func(k, v []byte) error {
|
||||||
include := matchFunc(string(key), string(cutKeyBytes(k)), fVal)
|
include := matchFunc(string(key), string(cutKeyBytes(k)), fVal)
|
||||||
|
|
||||||
strs, err := decodeAddressList(v)
|
if include {
|
||||||
if err != nil {
|
return keyBucket.Bucket(k).ForEach(func(k, _ []byte) error {
|
||||||
return errors.Wrapf(err, "(%T) could not decode address list", db)
|
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 {
|
return nil
|
||||||
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 a new issue