2020-12-10 12:26:40 +00:00
|
|
|
package searchsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2021-06-22 12:19:30 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/network"
|
2020-12-10 12:26:40 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (exec *execCtx) executeOnContainer() {
|
|
|
|
if exec.isLocal() {
|
|
|
|
exec.log.Debug("return result directly")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-01-12 14:55:02 +00:00
|
|
|
lookupDepth := exec.netmapLookupDepth()
|
2020-12-10 12:26:40 +00:00
|
|
|
|
2021-01-12 14:55:02 +00:00
|
|
|
exec.log.Debug("trying to execute in container...",
|
|
|
|
zap.Uint64("netmap lookup depth", lookupDepth),
|
|
|
|
)
|
|
|
|
|
|
|
|
// initialize epoch number
|
|
|
|
ok := exec.initEpoch()
|
2020-12-10 12:26:40 +00:00
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-01-12 14:55:02 +00:00
|
|
|
for {
|
|
|
|
if exec.processCurrentEpoch() {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
// check the maximum depth has been reached
|
|
|
|
if lookupDepth == 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
lookupDepth--
|
|
|
|
|
|
|
|
// go to the previous epoch
|
|
|
|
exec.curProcEpoch--
|
|
|
|
}
|
|
|
|
|
|
|
|
exec.status = statusOK
|
|
|
|
exec.err = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (exec *execCtx) processCurrentEpoch() bool {
|
|
|
|
exec.log.Debug("process epoch",
|
|
|
|
zap.Uint64("number", exec.curProcEpoch),
|
|
|
|
)
|
|
|
|
|
|
|
|
traverser, ok := exec.generateTraverser(exec.containerID())
|
|
|
|
if !ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
ctx, cancel := context.WithCancel(exec.context())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
for {
|
|
|
|
addrs := traverser.Next()
|
|
|
|
if len(addrs) == 0 {
|
|
|
|
exec.log.Debug("no more nodes, abort placement iteration")
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range addrs {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
exec.log.Debug("interrupt placement iteration by context",
|
|
|
|
zap.String("error", ctx.Err().Error()),
|
|
|
|
)
|
2021-01-12 14:55:02 +00:00
|
|
|
|
|
|
|
return true
|
2020-12-10 12:26:40 +00:00
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: consider parallel execution
|
2021-06-22 12:19:30 +00:00
|
|
|
exec.processNode(ctx, network.GroupFromAddress(addrs[i]))
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-12 14:55:02 +00:00
|
|
|
return false
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|