frostfs-node/pkg/services/object/get/container.go
Dmitrii Stepanov 22d47376a6 [] getsvc: Refactor errors
Move errors to separate files.
Use zap.Error for error logging.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-04-28 14:03:12 +00:00

93 lines
1.7 KiB
Go

package getsvc
import (
"context"
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/client"
"go.uber.org/zap"
)
func (r *request) executeOnContainer(ctx context.Context) {
if r.isLocal() {
r.log.Debug(logs.GetReturnResultDirectly)
return
}
lookupDepth := r.netmapLookupDepth()
r.log.Debug(logs.TryingToExecuteInContainer,
zap.Uint64("netmap lookup depth", lookupDepth),
)
// initialize epoch number
ok := r.initEpoch()
if !ok {
return
}
for {
if r.processCurrentEpoch(ctx) {
break
}
// check the maximum depth has been reached
if lookupDepth == 0 {
break
}
lookupDepth--
// go to the previous epoch
r.curProcEpoch--
}
}
func (r *request) processCurrentEpoch(ctx context.Context) bool {
r.log.Debug(logs.ProcessEpoch,
zap.Uint64("number", r.curProcEpoch),
)
traverser, ok := r.generateTraverser(r.address())
if !ok {
return true
}
ctx, cancel := context.WithCancel(ctx)
defer cancel()
r.status = statusUndefined
for {
addrs := traverser.Next()
if len(addrs) == 0 {
r.log.Debug(logs.NoMoreNodesAbortPlacementIteration)
return false
}
for i := range addrs {
select {
case <-ctx.Done():
r.log.Debug(logs.InterruptPlacementIterationByContext,
zap.Error(ctx.Err()),
)
return true
default:
}
// TODO: #1142 consider parallel execution
// TODO: #1142 consider optimization: if status == SPLIT we can continue until
// we reach the best result - split info with linking object ID.
var info client.NodeInfo
client.NodeInfoFromNetmapElement(&info, addrs[i])
if r.processNode(ctx, info) {
r.log.Debug(logs.GetCompletingTheOperation)
return true
}
}
}
}