[#165] cli: Refactor collectObjectRelatives
Resolve funlen linter Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
c2cf708e0e
commit
1d5f2dd681
1 changed files with 30 additions and 5 deletions
|
@ -339,8 +339,6 @@ func initFlagSession(cmd *cobra.Command, verb string) {
|
||||||
// container.
|
// container.
|
||||||
//
|
//
|
||||||
// The object itself is not included in the result.
|
// The object itself is not included in the result.
|
||||||
//
|
|
||||||
// nolint: funlen
|
|
||||||
func collectObjectRelatives(cmd *cobra.Command, cli *client.Client, cnr cid.ID, obj oid.ID) []oid.ID {
|
func collectObjectRelatives(cmd *cobra.Command, cli *client.Client, cnr cid.ID, obj oid.ID) []oid.ID {
|
||||||
common.PrintVerbose(cmd, "Fetching raw object header...")
|
common.PrintVerbose(cmd, "Fetching raw object header...")
|
||||||
|
|
||||||
|
@ -372,13 +370,28 @@ func collectObjectRelatives(cmd *cobra.Command, cli *client.Client, cnr cid.ID,
|
||||||
|
|
||||||
splitInfo := errSplit.SplitInfo()
|
splitInfo := errSplit.SplitInfo()
|
||||||
|
|
||||||
|
if members, ok := tryGetSplitMembersByLinkingObject(cmd, splitInfo, prmHead, cnr); ok {
|
||||||
|
return members
|
||||||
|
}
|
||||||
|
|
||||||
|
if members, ok := tryGetSplitMembersBySplitID(cmd, splitInfo, cli, cnr); ok {
|
||||||
|
return members
|
||||||
|
}
|
||||||
|
|
||||||
|
return tryRestoreChainInReverse(cmd, splitInfo, prmHead, cli, cnr, obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func tryGetSplitMembersByLinkingObject(cmd *cobra.Command, splitInfo *object.SplitInfo, prmHead internal.HeadObjectPrm, cnr cid.ID) ([]oid.ID, bool) {
|
||||||
// collect split chain by the descending ease of operations (ease is evaluated heuristically).
|
// collect split chain by the descending ease of operations (ease is evaluated heuristically).
|
||||||
// If any approach fails, we don't try the next since we assume that it will fail too.
|
// If any approach fails, we don't try the next since we assume that it will fail too.
|
||||||
|
|
||||||
if idLinking, ok := splitInfo.Link(); ok {
|
if idLinking, ok := splitInfo.Link(); ok {
|
||||||
common.PrintVerbose(cmd, "Collecting split members using linking object %s...", idLinking)
|
common.PrintVerbose(cmd, "Collecting split members using linking object %s...", idLinking)
|
||||||
|
|
||||||
|
var addrObj oid.Address
|
||||||
|
addrObj.SetContainer(cnr)
|
||||||
addrObj.SetObject(idLinking)
|
addrObj.SetObject(idLinking)
|
||||||
|
|
||||||
prmHead.SetAddress(addrObj)
|
prmHead.SetAddress(addrObj)
|
||||||
prmHead.SetRawFlag(false)
|
prmHead.SetRawFlag(false)
|
||||||
// client is already set
|
// client is already set
|
||||||
|
@ -390,14 +403,17 @@ func collectObjectRelatives(cmd *cobra.Command, cli *client.Client, cnr cid.ID,
|
||||||
common.PrintVerbose(cmd, "Received split members from the linking object: %v", children)
|
common.PrintVerbose(cmd, "Received split members from the linking object: %v", children)
|
||||||
|
|
||||||
// include linking object
|
// include linking object
|
||||||
return append(children, idLinking)
|
return append(children, idLinking), true
|
||||||
}
|
}
|
||||||
|
|
||||||
// linking object is not required for
|
// linking object is not required for
|
||||||
// object collecting
|
// object collecting
|
||||||
common.PrintVerbose(cmd, "failed to get linking object's header: %w", err)
|
common.PrintVerbose(cmd, "failed to get linking object's header: %w", err)
|
||||||
}
|
}
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
func tryGetSplitMembersBySplitID(cmd *cobra.Command, splitInfo *object.SplitInfo, cli *client.Client, cnr cid.ID) ([]oid.ID, bool) {
|
||||||
if idSplit := splitInfo.SplitID(); idSplit != nil {
|
if idSplit := splitInfo.SplitID(); idSplit != nil {
|
||||||
common.PrintVerbose(cmd, "Collecting split members by split ID...")
|
common.PrintVerbose(cmd, "Collecting split members by split ID...")
|
||||||
|
|
||||||
|
@ -412,12 +428,18 @@ func collectObjectRelatives(cmd *cobra.Command, cli *client.Client, cnr cid.ID,
|
||||||
res, err := internal.SearchObjects(prm)
|
res, err := internal.SearchObjects(prm)
|
||||||
commonCmd.ExitOnErr(cmd, "failed to search objects by split ID: %w", err)
|
commonCmd.ExitOnErr(cmd, "failed to search objects by split ID: %w", err)
|
||||||
|
|
||||||
members := res.IDList()
|
parts := res.IDList()
|
||||||
|
|
||||||
common.PrintVerbose(cmd, "Found objects by split ID: %v", res.IDList())
|
common.PrintVerbose(cmd, "Found objects by split ID: %v", res.IDList())
|
||||||
|
|
||||||
return members
|
return parts, true
|
||||||
}
|
}
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
func tryRestoreChainInReverse(cmd *cobra.Command, splitInfo *object.SplitInfo, prmHead internal.HeadObjectPrm, cli *client.Client, cnr cid.ID, obj oid.ID) []oid.ID {
|
||||||
|
var addrObj oid.Address
|
||||||
|
addrObj.SetContainer(cnr)
|
||||||
|
|
||||||
idMember, ok := splitInfo.LastPart()
|
idMember, ok := splitInfo.LastPart()
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -427,6 +449,8 @@ func collectObjectRelatives(cmd *cobra.Command, cli *client.Client, cnr cid.ID,
|
||||||
common.PrintVerbose(cmd, "Traverse the object split chain in reverse...", idMember)
|
common.PrintVerbose(cmd, "Traverse the object split chain in reverse...", idMember)
|
||||||
|
|
||||||
var res *internal.HeadObjectRes
|
var res *internal.HeadObjectRes
|
||||||
|
var err error
|
||||||
|
|
||||||
chain := []oid.ID{idMember}
|
chain := []oid.ID{idMember}
|
||||||
chainSet := map[oid.ID]struct{}{idMember: {}}
|
chainSet := map[oid.ID]struct{}{idMember: {}}
|
||||||
|
|
||||||
|
@ -437,6 +461,7 @@ func collectObjectRelatives(cmd *cobra.Command, cli *client.Client, cnr cid.ID,
|
||||||
common.PrintVerbose(cmd, "Reading previous element of the split chain member %s...", idMember)
|
common.PrintVerbose(cmd, "Reading previous element of the split chain member %s...", idMember)
|
||||||
|
|
||||||
addrObj.SetObject(idMember)
|
addrObj.SetObject(idMember)
|
||||||
|
prmHead.SetAddress(addrObj)
|
||||||
|
|
||||||
res, err = internal.HeadObject(prmHead)
|
res, err = internal.HeadObject(prmHead)
|
||||||
commonCmd.ExitOnErr(cmd, "failed to read split chain member's header: %w", err)
|
commonCmd.ExitOnErr(cmd, "failed to read split chain member's header: %w", err)
|
||||||
|
|
Loading…
Reference in a new issue