frostfs-node/pkg/local_object_storage/metabase/db.go
Leonard Lyubich 1db01725c9 [#131] metabase: Implement indexing by object properties
Process parent objects in Put method. Headers of parent object are stored as
regular leaf objects in metabase from now. Build indexes for ROOT, LEAF and
CHILDFREE properties.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2020-11-03 18:42:32 +03:00

36 lines
894 B
Go

package meta
import (
"github.com/nspcc-dev/neofs-api-go/pkg/object"
v2object "github.com/nspcc-dev/neofs-api-go/v2/object"
"go.etcd.io/bbolt"
)
// DB represents local metabase of storage node.
type DB struct {
boltDB *bbolt.DB
matchers map[object.SearchMatchType]func(string, string, string) bool
}
// NewDB creates, initializes and returns DB instance.
func NewDB(boltDB *bbolt.DB) *DB {
return &DB{
boltDB: boltDB,
matchers: map[object.SearchMatchType]func(string, string, string) bool{
object.MatchStringEqual: stringEqualMatcher,
},
}
}
func stringEqualMatcher(key, objVal, filterVal string) bool {
switch key {
default:
return objVal == filterVal
case
v2object.FilterPropertyRoot,
v2object.FilterPropertyChildfree,
v2object.FilterPropertyLeaf:
return (filterVal == v2object.BooleanPropertyValueTrue) == (objVal == v2object.BooleanPropertyValueTrue)
}
}