From 5b100699d7c9b2446539cbf19518bca963c5fc35 Mon Sep 17 00:00:00 2001 From: Ekaterina Lebedeva Date: Tue, 18 Jun 2024 10:20:45 +0300 Subject: [PATCH] [#566] policer: Move isClientErrMaintenance to frostfs-sdk-go Signed-off-by: Ekaterina Lebedeva --- go.mod | 2 +- go.sum | Bin 42738 -> 42738 bytes pkg/services/policer/check.go | 27 +-------------------------- pkg/services/policer/ec.go | 2 +- 4 files changed, 3 insertions(+), 28 deletions(-) diff --git a/go.mod b/go.mod index 4ce8a0d2..a04b9422 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.1-0.20240530152826-2f6d3209e1d3 git.frostfs.info/TrueCloudLab/frostfs-contract v0.19.3-0.20240409111539-e7a05a49ff45 git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20231101111734-b3ad3335ff65 - git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20240531132048-ebd8fcd1685f + git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20240617140730-1a5886e776de git.frostfs.info/TrueCloudLab/hrw v1.2.1 git.frostfs.info/TrueCloudLab/policy-engine v0.0.0-20240513163744-1f6f4163d40d git.frostfs.info/TrueCloudLab/tzhash v1.8.0 diff --git a/go.sum b/go.sum index cb97af3d42c28174a2f8bea873d28f2c7203d0af..0849b74a11c343918575b55cfbcb1ac83d4c9299 100644 GIT binary patch delta 119 zcmex#mg&=3rVTGxT+Iy44NVNpjSX}S6HP5F%u>zG%~DboG7PQ!vx>tb4YCT{y}}Gj zEX*U)%YF2X1BzWL%+tKga?<>KBT6DILNoG1lYA$CWLKDM&%!bJDvPifb`v+(v6d_Z E03ALhjQ{`u delta 119 zcmex#mg&=3rVTGxTuqG)4ULTqOe}O$lTs|wl2Z)LEKJiBG7PQCoP3-O{e#_ogY(RD zg1pM~3k>tq49Ze7(@LFEqEf0#!iwB1!}7F4-LfZtWLKDM&%!bJDvPifb`v+(v6d_Z E0B5}>>Hq)$ diff --git a/pkg/services/policer/check.go b/pkg/services/policer/check.go index 7120ba0b..bf67ec4d 100644 --- a/pkg/services/policer/check.go +++ b/pkg/services/policer/check.go @@ -2,7 +2,6 @@ package policer import ( "context" - "errors" "fmt" "git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs" @@ -11,7 +10,6 @@ import ( policycore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/policy" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/replicator" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" - apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" @@ -139,7 +137,7 @@ func (p *Policer) processRepNodes(ctx context.Context, requirements *placementRe if client.IsErrObjectNotFound(err) { checkedNodes.submitReplicaCandidate(nodes[i]) continue - } else if isClientErrMaintenance(err) { + } else if client.IsErrNodeUnderMaintenance(err) { shortage, uncheckedCopies = p.handleMaintenance(nodes[i], checkedNodes, shortage, uncheckedCopies) } else { p.log.Error(logs.PolicerReceiveObjectHeaderToCheckPolicyCompliance, @@ -204,26 +202,3 @@ func (p *Policer) handleProcessNodesResult(ctx context.Context, addr oid.Address requirements.removeLocalCopy = true } } - -// isClientErrMaintenance checks if err corresponds to FrostFS status return -// which tells that node is currently under maintenance. Supports wrapped -// errors. -// -// Similar to client.IsErr___ errors, consider replacing to FrostFS SDK. -func isClientErrMaintenance(err error) bool { - switch unwrapErr(err).(type) { - default: - return false - case *apistatus.NodeUnderMaintenance: - return true - } -} - -// unwrapErr unwraps error using errors.Unwrap. -func unwrapErr(err error) error { - for e := errors.Unwrap(err); e != nil; e = errors.Unwrap(err) { - err = e - } - - return err -} diff --git a/pkg/services/policer/ec.go b/pkg/services/policer/ec.go index b15efdd1..5b3793f7 100644 --- a/pkg/services/policer/ec.go +++ b/pkg/services/policer/ec.go @@ -126,7 +126,7 @@ func (p *Policer) processECChunk(ctx context.Context, objInfo objectcore.Info, n Nodes: []netmap.NodeInfo{requiredNode}, } p.replicator.HandleReplicationTask(ctx, task, newNodeCache()) - } else if isClientErrMaintenance(err) { + } else if client.IsErrNodeUnderMaintenance(err) { // consider maintenance mode has object, but do not drop local copy p.log.Debug(logs.PolicerConsiderNodeUnderMaintenanceAsOK, zap.String("node", netmap.StringifyPublicKey(requiredNode))) } else {