2020-10-29 12:03:55 +00:00
|
|
|
package meta
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"go.etcd.io/bbolt"
|
2020-11-09 10:24:48 +00:00
|
|
|
"go.uber.org/zap"
|
2020-10-29 12:03:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var tombstoneBucket = []byte("tombstones")
|
|
|
|
|
|
|
|
// Delete marks object as deleted.
|
|
|
|
func (db *DB) Delete(addr *object.Address) error {
|
2020-11-09 10:09:09 +00:00
|
|
|
return db.delete(addr)
|
|
|
|
}
|
|
|
|
|
|
|
|
func objectRemoved(tx *bbolt.Tx, addr []byte) bool {
|
|
|
|
tombstoneBucket := tx.Bucket(tombstoneBucket)
|
|
|
|
|
|
|
|
return tombstoneBucket != nil && tombstoneBucket.Get(addr) != nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteObjects marks list of objects as deleted.
|
|
|
|
func (db *DB) DeleteObjects(list ...*object.Address) {
|
|
|
|
if err := db.delete(list...); err != nil {
|
2020-11-09 10:24:48 +00:00
|
|
|
db.log.Error("could not delete object list",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
2020-11-09 10:09:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (db *DB) delete(list ...*object.Address) error {
|
2020-10-29 12:03:55 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2020-11-09 10:09:09 +00:00
|
|
|
for i := range list {
|
|
|
|
if err := bucket.Put(addressKey(list[i]), nil); err != nil {
|
|
|
|
return errors.Wrapf(err, "(%T) could not put to tombstone bucket", db)
|
|
|
|
}
|
2020-10-29 12:03:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|