2020-11-23 13:30:56 +00:00
|
|
|
package meta
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2020-11-23 13:30:56 +00:00
|
|
|
"go.etcd.io/bbolt"
|
|
|
|
)
|
|
|
|
|
2020-12-08 09:56:14 +00:00
|
|
|
// ToMoveItPrm groups the parameters of ToMoveIt operation.
|
|
|
|
type ToMoveItPrm struct {
|
2022-05-31 17:00:41 +00:00
|
|
|
addr oid.Address
|
2020-12-08 09:56:14 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// ToMoveItRes groups the resulting values of ToMoveIt operation.
|
2020-12-08 09:56:14 +00:00
|
|
|
type ToMoveItRes struct{}
|
|
|
|
|
2022-07-12 14:59:37 +00:00
|
|
|
// SetAddress sets address of the object to move into another shard.
|
|
|
|
func (p *ToMoveItPrm) SetAddress(addr oid.Address) {
|
|
|
|
p.addr = addr
|
2020-12-08 09:56:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DoNotMovePrm groups the parameters of DoNotMove operation.
|
|
|
|
type DoNotMovePrm struct {
|
2022-05-31 17:00:41 +00:00
|
|
|
addr oid.Address
|
2020-12-08 09:56:14 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// DoNotMoveRes groups the resulting values of DoNotMove operation.
|
2020-12-08 09:56:14 +00:00
|
|
|
type DoNotMoveRes struct{}
|
|
|
|
|
2022-07-12 14:59:37 +00:00
|
|
|
// SetAddress sets address of the object to prevent moving into another shard.
|
|
|
|
func (p *DoNotMovePrm) SetAddress(addr oid.Address) {
|
|
|
|
p.addr = addr
|
2020-12-08 09:56:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MovablePrm groups the parameters of Movable operation.
|
|
|
|
type MovablePrm struct{}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// MovableRes groups the resulting values of Movable operation.
|
2020-12-08 09:56:14 +00:00
|
|
|
type MovableRes struct {
|
2022-05-31 17:00:41 +00:00
|
|
|
addrList []oid.Address
|
2020-12-08 09:56:14 +00:00
|
|
|
}
|
|
|
|
|
2021-06-23 13:29:46 +00:00
|
|
|
// AddressList returns resulting addresses of Movable operation.
|
2022-05-20 16:48:14 +00:00
|
|
|
func (p MovableRes) AddressList() []oid.Address {
|
2020-12-08 09:56:14 +00:00
|
|
|
return p.addrList
|
|
|
|
}
|
|
|
|
|
2020-11-23 13:30:56 +00:00
|
|
|
// ToMoveIt marks objects to move it into another shard. This useful for
|
|
|
|
// faster HRW fetching.
|
2022-05-31 11:43:08 +00:00
|
|
|
func (db *DB) ToMoveIt(prm ToMoveItPrm) (res ToMoveItRes, err error) {
|
2022-07-21 13:26:25 +00:00
|
|
|
db.modeMtx.RLock()
|
|
|
|
defer db.modeMtx.RUnlock()
|
|
|
|
|
2022-11-15 12:46:32 +00:00
|
|
|
if db.mode.NoMetabase() {
|
|
|
|
return res, ErrDegradedMode
|
2022-11-15 14:53:23 +00:00
|
|
|
} else if db.mode.ReadOnly() {
|
|
|
|
return res, ErrReadOnlyMode
|
2022-11-15 12:46:32 +00:00
|
|
|
}
|
|
|
|
|
2022-09-08 11:54:21 +00:00
|
|
|
key := make([]byte, addressKeySize)
|
|
|
|
key = addressKey(prm.addr, key)
|
|
|
|
|
2020-12-08 09:56:14 +00:00
|
|
|
err = db.boltDB.Update(func(tx *bbolt.Tx) error {
|
2022-10-26 06:10:18 +00:00
|
|
|
toMoveIt := tx.Bucket(toMoveItBucketName)
|
2022-09-08 11:54:21 +00:00
|
|
|
return toMoveIt.Put(key, zeroValue)
|
2020-11-23 13:30:56 +00:00
|
|
|
})
|
2020-12-08 09:56:14 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-23 13:30:56 +00:00
|
|
|
// DoNotMove removes `MoveIt` mark from the object.
|
2022-05-31 11:43:08 +00:00
|
|
|
func (db *DB) DoNotMove(prm DoNotMovePrm) (res DoNotMoveRes, err error) {
|
2022-07-21 13:26:25 +00:00
|
|
|
db.modeMtx.RLock()
|
|
|
|
defer db.modeMtx.RUnlock()
|
|
|
|
|
2022-11-15 12:46:32 +00:00
|
|
|
if db.mode.NoMetabase() {
|
|
|
|
return res, ErrDegradedMode
|
2022-11-15 14:53:23 +00:00
|
|
|
} else if db.mode.ReadOnly() {
|
|
|
|
return res, ErrReadOnlyMode
|
2022-11-15 12:46:32 +00:00
|
|
|
}
|
|
|
|
|
2022-09-08 11:54:21 +00:00
|
|
|
key := make([]byte, addressKeySize)
|
|
|
|
key = addressKey(prm.addr, key)
|
|
|
|
|
2020-12-08 09:56:14 +00:00
|
|
|
err = db.boltDB.Update(func(tx *bbolt.Tx) error {
|
2020-11-23 13:30:56 +00:00
|
|
|
toMoveIt := tx.Bucket(toMoveItBucketName)
|
2022-09-08 11:54:21 +00:00
|
|
|
return toMoveIt.Delete(key)
|
2020-11-23 13:30:56 +00:00
|
|
|
})
|
2020-12-08 09:56:14 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-23 13:30:56 +00:00
|
|
|
// Movable returns list of marked objects to move into other shard.
|
2022-05-31 11:43:08 +00:00
|
|
|
func (db *DB) Movable(_ MovablePrm) (MovableRes, error) {
|
2022-07-21 13:26:25 +00:00
|
|
|
db.modeMtx.RLock()
|
|
|
|
defer db.modeMtx.RUnlock()
|
|
|
|
|
2022-11-15 12:46:32 +00:00
|
|
|
if db.mode.NoMetabase() {
|
|
|
|
return MovableRes{}, ErrDegradedMode
|
|
|
|
}
|
|
|
|
|
2020-11-23 13:30:56 +00:00
|
|
|
var strAddrs []string
|
|
|
|
|
|
|
|
err := db.boltDB.View(func(tx *bbolt.Tx) error {
|
|
|
|
toMoveIt := tx.Bucket(toMoveItBucketName)
|
|
|
|
return toMoveIt.ForEach(func(k, v []byte) error {
|
|
|
|
strAddrs = append(strAddrs, string(k))
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
})
|
|
|
|
if err != nil {
|
2022-05-31 11:43:08 +00:00
|
|
|
return MovableRes{}, err
|
2020-11-23 13:30:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// we can parse strings to structures in-place, but probably it seems
|
|
|
|
// more efficient to keep bolt db TX code smaller because it might be
|
|
|
|
// bottleneck.
|
2022-05-31 17:00:41 +00:00
|
|
|
addrs := make([]oid.Address, len(strAddrs))
|
2020-11-23 13:30:56 +00:00
|
|
|
|
|
|
|
for i := range strAddrs {
|
2022-05-31 17:00:41 +00:00
|
|
|
err = decodeAddressFromKey(&addrs[i], []byte(strAddrs[i]))
|
2020-11-23 13:30:56 +00:00
|
|
|
if err != nil {
|
2022-05-31 11:43:08 +00:00
|
|
|
return MovableRes{}, fmt.Errorf("can't parse object address %v: %w",
|
2020-11-23 13:30:56 +00:00
|
|
|
strAddrs[i], err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-31 11:43:08 +00:00
|
|
|
return MovableRes{
|
2020-12-08 09:56:14 +00:00
|
|
|
addrList: addrs,
|
|
|
|
}, nil
|
2020-11-23 13:30:56 +00:00
|
|
|
}
|