Aleksey Savchuk
f0c43c8d80
All checks were successful
Vulncheck / Vulncheck (pull_request) Successful in 3m1s
Pre-commit hooks / Pre-commit (pull_request) Successful in 3m29s
Tests and linters / gopls check (pull_request) Successful in 3m50s
Tests and linters / Lint (pull_request) Successful in 4m35s
DCO action / DCO (pull_request) Successful in 5m12s
Tests and linters / Run gofumpt (pull_request) Successful in 5m33s
Build / Build Components (pull_request) Successful in 5m45s
Tests and linters / Tests with -race (pull_request) Successful in 6m37s
Tests and linters / Tests (pull_request) Successful in 7m17s
Tests and linters / Staticcheck (pull_request) Successful in 7m36s
Tests and linters / Run gofumpt (push) Successful in 1m22s
Tests and linters / Staticcheck (push) Successful in 3m19s
Tests and linters / Lint (push) Successful in 4m35s
Vulncheck / Vulncheck (push) Successful in 5m20s
Build / Build Components (push) Successful in 6m16s
Pre-commit hooks / Pre-commit (push) Successful in 6m37s
Tests and linters / Tests (push) Successful in 6m48s
Tests and linters / Tests with -race (push) Successful in 7m15s
Tests and linters / gopls check (push) Successful in 7m27s
Use `zap.Error` instead of `zap.String` for logging errors: change all expressions like `zap.String("error", err.Error())` or `zap.String("err", err.Error())` to `zap.Error(err)`. Leave similar expressions with other messages unchanged, for example, `zap.String("last_error", lastErr.Error())` or `zap.String("reason", ctx.Err().Error())`. This change was made by applying the following patch: ```diff @@ var err expression @@ -zap.String("error", err.Error()) +zap.Error(err) @@ var err expression @@ -zap.String("err", err.Error()) +zap.Error(err) ``` Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
124 lines
2.7 KiB
Go
124 lines
2.7 KiB
Go
package searchsvc
|
|
|
|
import (
|
|
"context"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"sync"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/client"
|
|
containerSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
func (exec *execCtx) executeOnContainer(ctx context.Context) error {
|
|
lookupDepth := exec.netmapLookupDepth()
|
|
|
|
exec.log.Debug(ctx, logs.TryingToExecuteInContainer,
|
|
zap.Uint64("netmap lookup depth", lookupDepth),
|
|
)
|
|
|
|
// initialize epoch number
|
|
if err := exec.initEpoch(); err != nil {
|
|
return fmt.Errorf("%s: %w", logs.CouldNotGetCurrentEpochNumber, err)
|
|
}
|
|
|
|
for {
|
|
if err := exec.processCurrentEpoch(ctx); err != nil {
|
|
break
|
|
}
|
|
|
|
// check the maximum depth has been reached
|
|
if lookupDepth == 0 {
|
|
break
|
|
}
|
|
|
|
lookupDepth--
|
|
|
|
// go to the previous epoch
|
|
exec.curProcEpoch--
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (exec *execCtx) processCurrentEpoch(ctx context.Context) error {
|
|
exec.log.Debug(ctx, logs.ProcessEpoch,
|
|
zap.Uint64("number", exec.curProcEpoch),
|
|
)
|
|
|
|
traverser, _, err := exec.svc.traverserGenerator.GenerateTraverser(exec.containerID(), nil, exec.curProcEpoch)
|
|
if err != nil {
|
|
return fmt.Errorf("%s: %w", logs.SearchCouldNotGenerateContainerTraverser, err)
|
|
}
|
|
|
|
ctx, cancel := context.WithCancel(ctx)
|
|
defer cancel()
|
|
|
|
for {
|
|
addrs := traverser.Next()
|
|
if len(addrs) == 0 {
|
|
exec.log.Debug(ctx, logs.NoMoreNodesAbortPlacementIteration)
|
|
break
|
|
}
|
|
|
|
var wg sync.WaitGroup
|
|
var mtx sync.Mutex
|
|
|
|
for i := range addrs {
|
|
wg.Add(1)
|
|
go func(i int) {
|
|
defer wg.Done()
|
|
select {
|
|
case <-ctx.Done():
|
|
exec.log.Debug(ctx, logs.InterruptPlacementIterationByContext,
|
|
zap.Error(ctx.Err()))
|
|
return
|
|
default:
|
|
}
|
|
|
|
var info client.NodeInfo
|
|
|
|
client.NodeInfoFromNetmapElement(&info, addrs[i])
|
|
|
|
exec.log.Debug(ctx, logs.ProcessingNode, zap.String("key", hex.EncodeToString(addrs[i].PublicKey())))
|
|
|
|
c, err := exec.svc.clientConstructor.get(info)
|
|
if err != nil {
|
|
exec.log.Debug(ctx, logs.SearchCouldNotConstructRemoteNodeClient, zap.Error(err))
|
|
return
|
|
}
|
|
|
|
ids, err := c.searchObjects(ctx, exec, info)
|
|
if err != nil {
|
|
exec.log.Debug(ctx, logs.SearchRemoteOperationFailed,
|
|
zap.Error(err))
|
|
|
|
return
|
|
}
|
|
|
|
mtx.Lock()
|
|
err = exec.writeIDList(ids)
|
|
mtx.Unlock()
|
|
if err != nil {
|
|
exec.log.Debug(ctx, logs.SearchCouldNotWriteObjectIdentifiers, zap.Error(err))
|
|
return
|
|
}
|
|
}(i)
|
|
}
|
|
|
|
wg.Wait()
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
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
|
|
}
|