2020-10-21 09:24:02 +00:00
|
|
|
package policer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"strings"
|
|
|
|
|
2021-10-16 11:21:03 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/container"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
2020-10-21 09:24:02 +00:00
|
|
|
headsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/head"
|
2020-10-21 11:50:48 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/replicator"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
2022-01-26 12:11:13 +00:00
|
|
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
2020-10-21 09:24:02 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2022-01-26 12:11:13 +00:00
|
|
|
func (p *Policer) processObject(ctx context.Context, addr *addressSDK.Address) {
|
2022-05-12 16:37:46 +00:00
|
|
|
idCnr, _ := addr.ContainerID()
|
|
|
|
|
|
|
|
cnr, err := p.cnrSrc.Get(&idCnr)
|
2020-10-21 09:24:02 +00:00
|
|
|
if err != nil {
|
|
|
|
p.log.Error("could not get container",
|
2022-05-12 16:37:46 +00:00
|
|
|
zap.Stringer("cid", idCnr),
|
2020-10-21 09:24:02 +00:00
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
2022-03-17 08:17:45 +00:00
|
|
|
if container.IsErrNotFound(err) {
|
2021-10-16 11:21:03 +00:00
|
|
|
prm := new(engine.InhumePrm)
|
|
|
|
prm.MarkAsGarbage(addr)
|
|
|
|
_, err := p.jobQueue.localStorage.Inhume(prm)
|
|
|
|
if err != nil {
|
2022-05-12 16:37:46 +00:00
|
|
|
id, _ := addr.ObjectID()
|
2021-10-16 11:21:03 +00:00
|
|
|
p.log.Error("could not inhume object with missing container",
|
2022-05-12 16:37:46 +00:00
|
|
|
zap.Stringer("cid", idCnr),
|
|
|
|
zap.Stringer("oid", id),
|
2021-10-16 11:21:03 +00:00
|
|
|
zap.String("error", err.Error()))
|
|
|
|
}
|
|
|
|
}
|
2020-10-21 09:24:02 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-16 09:43:52 +00:00
|
|
|
policy := cnr.PlacementPolicy()
|
2020-10-21 09:24:02 +00:00
|
|
|
|
|
|
|
nn, err := p.placementBuilder.BuildPlacement(addr, policy)
|
|
|
|
if err != nil {
|
|
|
|
p.log.Error("could not build placement vector for object",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-05 15:51:43 +00:00
|
|
|
replicas := policy.Replicas()
|
2020-10-21 09:24:02 +00:00
|
|
|
|
|
|
|
for i := range nn {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
2020-11-05 15:51:43 +00:00
|
|
|
p.processNodes(ctx, addr, nn[i], replicas[i].Count())
|
2020-10-21 09:24:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-26 12:11:13 +00:00
|
|
|
func (p *Policer) processNodes(ctx context.Context, addr *addressSDK.Address, nodes netmap.Nodes, shortage uint32) {
|
2021-09-24 15:19:54 +00:00
|
|
|
log := p.log.With(
|
|
|
|
zap.Stringer("object", addr),
|
|
|
|
)
|
|
|
|
|
2020-10-21 09:24:02 +00:00
|
|
|
prm := new(headsvc.RemoteHeadPrm).WithObjectAddress(addr)
|
2021-02-19 15:21:46 +00:00
|
|
|
redundantLocalCopy := false
|
2020-10-21 09:24:02 +00:00
|
|
|
|
2021-02-19 15:21:46 +00:00
|
|
|
for i := 0; i < len(nodes); i++ {
|
2020-10-21 09:24:02 +00:00
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
2021-09-06 12:17:14 +00:00
|
|
|
if p.netmapKeys.IsLocalKey(nodes[i].PublicKey()) {
|
2021-02-19 15:21:46 +00:00
|
|
|
if shortage == 0 {
|
2021-02-24 15:17:20 +00:00
|
|
|
// we can call the redundant copy callback
|
|
|
|
// here to slightly improve the performance
|
|
|
|
// instead of readability.
|
2021-02-19 15:21:46 +00:00
|
|
|
redundantLocalCopy = true
|
|
|
|
break
|
|
|
|
} else {
|
|
|
|
shortage--
|
|
|
|
}
|
|
|
|
} else if shortage > 0 {
|
2020-10-21 09:24:02 +00:00
|
|
|
callCtx, cancel := context.WithTimeout(ctx, p.headTimeout)
|
|
|
|
|
2021-09-28 05:32:30 +00:00
|
|
|
_, err := p.remoteHeader.Head(callCtx, prm.WithNodeInfo(nodes[i].NodeInfo))
|
2020-10-21 09:24:02 +00:00
|
|
|
|
|
|
|
cancel()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if strings.Contains(err.Error(), headsvc.ErrNotFound.Error()) {
|
|
|
|
continue
|
|
|
|
} else {
|
2021-12-22 16:19:31 +00:00
|
|
|
log.Debug("could not receive object header",
|
2020-10-21 09:24:02 +00:00
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
2020-12-14 18:03:21 +00:00
|
|
|
|
|
|
|
continue
|
2020-10-21 09:24:02 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
shortage--
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nodes = append(nodes[:i], nodes[i+1:]...)
|
|
|
|
i--
|
|
|
|
}
|
|
|
|
|
|
|
|
if shortage > 0 {
|
2021-12-22 16:19:31 +00:00
|
|
|
log.Debug("shortage of object copies detected",
|
2020-10-21 09:24:02 +00:00
|
|
|
zap.Uint32("shortage", shortage),
|
|
|
|
)
|
2020-10-21 11:50:48 +00:00
|
|
|
|
2021-11-10 11:47:52 +00:00
|
|
|
p.replicator.HandleTask(ctx, new(replicator.Task).
|
2020-10-21 11:50:48 +00:00
|
|
|
WithObjectAddress(addr).
|
|
|
|
WithNodes(nodes).
|
|
|
|
WithCopiesNumber(shortage),
|
|
|
|
)
|
2021-02-19 15:21:46 +00:00
|
|
|
} else if redundantLocalCopy {
|
2021-09-24 15:21:17 +00:00
|
|
|
log.Info("redundant local object copy detected")
|
|
|
|
|
2021-02-19 15:21:46 +00:00
|
|
|
p.cbRedundantCopy(addr)
|
2020-10-21 09:24:02 +00:00
|
|
|
}
|
|
|
|
}
|