2020-12-10 12:26:40 +00:00
|
|
|
package searchsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-10-05 08:09:53 +00:00
|
|
|
"encoding/hex"
|
2023-08-24 18:44:55 +00:00
|
|
|
"fmt"
|
2022-10-05 08:09:53 +00:00
|
|
|
"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"
|
2024-10-02 11:52:54 +00:00
|
|
|
containerSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
|
2020-12-10 12:26:40 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2023-08-24 18:44:55 +00:00
|
|
|
func (exec *execCtx) executeOnContainer(ctx context.Context) error {
|
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
|
2023-08-24 18:44:55 +00:00
|
|
|
if err := exec.initEpoch(); err != nil {
|
|
|
|
return fmt.Errorf("%s: %w", logs.CouldNotGetCurrentEpochNumber, err)
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
|
2021-01-12 14:55:02 +00:00
|
|
|
for {
|
2023-08-24 18:44:55 +00:00
|
|
|
if err := exec.processCurrentEpoch(ctx); err != nil {
|
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--
|
|
|
|
}
|
|
|
|
|
2023-08-24 18:44:55 +00:00
|
|
|
return nil
|
2021-01-12 14:55:02 +00:00
|
|
|
}
|
|
|
|
|
2023-08-24 18:44:55 +00:00
|
|
|
func (exec *execCtx) processCurrentEpoch(ctx context.Context) error {
|
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),
|
|
|
|
)
|
|
|
|
|
2024-07-15 15:03:43 +00:00
|
|
|
traverser, _, err := exec.svc.traverserGenerator.GenerateTraverser(exec.containerID(), nil, exec.curProcEpoch)
|
2023-08-24 18:44:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("%s: %w", logs.SearchCouldNotGenerateContainerTraverser, err)
|
2021-01-12 14:55:02 +00:00
|
|
|
}
|
|
|
|
|
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 {
|
2023-08-24 18:44:55 +00:00
|
|
|
exec.log.Debug(logs.SearchCouldNotConstructRemoteNodeClient, zap.String("error", err.Error()))
|
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()
|
2023-08-24 18:44:55 +00:00
|
|
|
err = exec.writeIDList(ids)
|
2022-10-05 08:09:53 +00:00
|
|
|
mtx.Unlock()
|
2023-08-24 18:44:55 +00:00
|
|
|
if err != nil {
|
|
|
|
exec.log.Debug(logs.SearchCouldNotWriteObjectIdentifiers, zap.String("error", err.Error()))
|
|
|
|
return
|
|
|
|
}
|
2022-10-05 08:09:53 +00:00
|
|
|
}(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
|
|
|
}
|
|
|
|
|
2023-08-24 18:44:55 +00:00
|
|
|
return nil
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
2024-10-02 11:52:54 +00:00
|
|
|
|
|
|
|
func (exec *execCtx) getContainer() (containerSDK.Container, error) {
|
|
|
|
cnrID := exec.containerID()
|
|
|
|
cnr, err := exec.svc.containerSource.Get(cnrID)
|
|
|
|
if err != nil {
|
|
|
|
return containerSDK.Container{}, err
|
|
|
|
}
|
|
|
|
return cnr.Value, nil
|
|
|
|
}
|