[#128] metabase: Implement Delete method
Implement Delete method on DB structure that adds deleted addresses to tombstone index. Do not attach addresses from tombstone index to Select result. Return error from Get method if address is presented in tombstone index. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
2d319aa29c
commit
20ed7c0d61
4 changed files with 105 additions and 9 deletions
31
pkg/local_object_storage/metabase/delete.go
Normal file
31
pkg/local_object_storage/metabase/delete.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package meta
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
"github.com/pkg/errors"
|
||||
"go.etcd.io/bbolt"
|
||||
)
|
||||
|
||||
var tombstoneBucket = []byte("tombstones")
|
||||
|
||||
// Delete marks object as deleted.
|
||||
func (db *DB) Delete(addr *object.Address) error {
|
||||
return db.boltDB.Update(func(tx *bbolt.Tx) error {
|
||||
bucket, err := tx.CreateBucketIfNotExists(tombstoneBucket)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "(%T) could not create tombstone bucket", db)
|
||||
}
|
||||
|
||||
if err := bucket.Put(addressKey(addr), nil); err != nil {
|
||||
return errors.Wrapf(err, "(%T) could not put to tombstone bucket", db)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func objectRemoved(tx *bbolt.Tx, addr []byte) bool {
|
||||
tombstoneBucket := tx.Bucket(tombstoneBucket)
|
||||
|
||||
return tombstoneBucket != nil && tombstoneBucket.Get(addr) != nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue