2020-12-10 12:26:40 +00:00
|
|
|
package searchsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-10-05 08:09:53 +00:00
|
|
|
"encoding/hex"
|
|
|
|
"sync"
|
2020-12-10 12:26:40 +00:00
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/client"
|
2020-12-10 12:26:40 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2023-04-04 09:54:21 +00:00
|
|
|
func (exec *execCtx) executeOnContainer(ctx context.Context) {
|
2020-12-10 12:26:40 +00:00
|
|
|
if exec.isLocal() {
|
2023-04-12 14:35:10 +00:00
|
|
|
exec.log.Debug(logs.SearchReturnResultDirectly)
|
2020-12-10 12:26:40 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-01-12 14:55:02 +00:00
|
|
|
lookupDepth := exec.netmapLookupDepth()
|
2020-12-10 12:26:40 +00:00
|
|
|
|
2023-04-13 12:51:36 +00:00
|
|
|
exec.log.Debug(logs.TryingToExecuteInContainer,
|
2021-01-12 14:55:02 +00:00
|
|
|
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 {
|
2023-04-04 09:54:21 +00:00
|
|
|
if exec.processCurrentEpoch(ctx) {
|
2021-01-12 14:55:02 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-04-04 09:54:21 +00:00
|
|
|
func (exec *execCtx) processCurrentEpoch(ctx context.Context) bool {
|
2023-04-13 12:51:36 +00:00
|
|
|
exec.log.Debug(logs.ProcessEpoch,
|
2021-01-12 14:55:02 +00:00
|
|
|
zap.Uint64("number", exec.curProcEpoch),
|
|
|
|
)
|
|
|
|
|
|
|
|
traverser, ok := exec.generateTraverser(exec.containerID())
|
|
|
|
if !ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2023-04-04 09:54:21 +00:00
|
|
|
ctx, cancel := context.WithCancel(ctx)
|
2020-12-10 12:26:40 +00:00
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
for {
|
|
|
|
addrs := traverser.Next()
|
|
|
|
if len(addrs) == 0 {
|
2023-04-13 12:51:36 +00:00
|
|
|
exec.log.Debug(logs.NoMoreNodesAbortPlacementIteration)
|
2020-12-10 12:26:40 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2022-10-05 08:09:53 +00:00
|
|
|
var wg sync.WaitGroup
|
|
|
|
var mtx sync.Mutex
|
2021-09-28 04:46:10 +00:00
|
|
|
|
2022-10-05 08:09:53 +00:00
|
|
|
for i := range addrs {
|
|
|
|
wg.Add(1)
|
|
|
|
go func(i int) {
|
|
|
|
defer wg.Done()
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
2023-04-13 12:51:36 +00:00
|
|
|
exec.log.Debug(logs.InterruptPlacementIterationByContext,
|
2022-10-05 08:09:53 +00:00
|
|
|
zap.String("error", ctx.Err().Error()))
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
|
|
|
var info client.NodeInfo
|
|
|
|
|
|
|
|
client.NodeInfoFromNetmapElement(&info, addrs[i])
|
|
|
|
|
2023-04-13 12:51:36 +00:00
|
|
|
exec.log.Debug(logs.ProcessingNode, zap.String("key", hex.EncodeToString(addrs[i].PublicKey())))
|
2022-10-05 08:09:53 +00:00
|
|
|
|
|
|
|
c, err := exec.svc.clientConstructor.get(info)
|
|
|
|
if err != nil {
|
|
|
|
mtx.Lock()
|
|
|
|
exec.status = statusUndefined
|
|
|
|
exec.err = err
|
|
|
|
mtx.Unlock()
|
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
exec.log.Debug(logs.SearchCouldNotConstructRemoteNodeClient)
|
2022-10-05 08:09:53 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-04-04 09:54:21 +00:00
|
|
|
ids, err := c.searchObjects(ctx, exec, info)
|
2022-10-05 08:09:53 +00:00
|
|
|
if err != nil {
|
2023-04-12 14:35:10 +00:00
|
|
|
exec.log.Debug(logs.SearchRemoteOperationFailed,
|
2022-10-05 08:09:53 +00:00
|
|
|
zap.String("error", err.Error()))
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
mtx.Lock()
|
|
|
|
exec.writeIDList(ids)
|
|
|
|
mtx.Unlock()
|
|
|
|
}(i)
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
2022-10-05 08:09:53 +00:00
|
|
|
|
|
|
|
wg.Wait()
|
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
|
|
|
}
|