forked from TrueCloudLab/frostfs-node
[#904] metabase: Return if object was actuall inserted
This requires to count metrics properly. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
c1a80235db
commit
57171907e3
3 changed files with 68 additions and 12 deletions
|
@ -36,7 +36,9 @@ type PutPrm struct {
|
|||
}
|
||||
|
||||
// PutRes groups the resulting values of Put operation.
|
||||
type PutRes struct{}
|
||||
type PutRes struct {
|
||||
Inserted bool
|
||||
}
|
||||
|
||||
// SetObject is a Put option to set object to save.
|
||||
func (p *PutPrm) SetObject(obj *objectSDK.Object) {
|
||||
|
@ -85,7 +87,9 @@ func (db *DB) Put(ctx context.Context, prm PutPrm) (res PutRes, err error) {
|
|||
currEpoch := db.epochState.CurrentEpoch()
|
||||
|
||||
err = db.boltDB.Batch(func(tx *bbolt.Tx) error {
|
||||
return db.put(tx, prm.obj, prm.id, nil, currEpoch)
|
||||
var e error
|
||||
res, e = db.put(tx, prm.obj, prm.id, nil, currEpoch)
|
||||
return e
|
||||
})
|
||||
if err == nil {
|
||||
success = true
|
||||
|
@ -102,10 +106,10 @@ func (db *DB) put(tx *bbolt.Tx,
|
|||
id []byte,
|
||||
si *objectSDK.SplitInfo,
|
||||
currEpoch uint64,
|
||||
) error {
|
||||
) (PutRes, error) {
|
||||
cnr, ok := obj.ContainerID()
|
||||
if !ok {
|
||||
return errors.New("missing container in object")
|
||||
return PutRes{}, errors.New("missing container in object")
|
||||
}
|
||||
|
||||
isParent := si != nil
|
||||
|
@ -116,14 +120,14 @@ func (db *DB) put(tx *bbolt.Tx,
|
|||
if errors.As(err, &splitInfoError) {
|
||||
exists = true // object exists, however it is virtual
|
||||
} else if err != nil {
|
||||
return err // return any error besides SplitInfoError
|
||||
return PutRes{}, err // return any error besides SplitInfoError
|
||||
}
|
||||
|
||||
if exists {
|
||||
return db.updateObj(tx, obj, id, si, isParent)
|
||||
return PutRes{}, db.updateObj(tx, obj, id, si, isParent)
|
||||
}
|
||||
|
||||
return db.insertObject(tx, obj, id, si, isParent, cnr, currEpoch)
|
||||
return PutRes{Inserted: true}, db.insertObject(tx, obj, id, si, isParent, cnr, currEpoch)
|
||||
}
|
||||
|
||||
func (db *DB) updateObj(tx *bbolt.Tx, obj *objectSDK.Object, id []byte, si *objectSDK.SplitInfo, isParent bool) error {
|
||||
|
@ -153,7 +157,7 @@ func (db *DB) insertObject(tx *bbolt.Tx, obj *objectSDK.Object, id []byte, si *o
|
|||
return err
|
||||
}
|
||||
|
||||
err = db.put(tx, par, id, parentSI, currEpoch)
|
||||
_, err = db.put(tx, par, id, parentSI, currEpoch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue