@@ -29,30 +29,84 @@ func (p *Service) InitPut(ctx context.Context, hdr *object.Object, cp *util.Comm
2929}
3030
3131func (p * Service ) initTarget (ctx context.Context , hdr * object.Object , cp * util.CommonPrm , opts PutInitOptions ) (internal.Target , error ) {
32- // prepare needed put parameters
33- if err := p .prepareOptions (hdr , cp , & opts ); err != nil {
34- return nil , fmt .Errorf ("(%T) could not prepare put parameters: %w" , p , err )
32+ localOnly := cp .LocalOnly ()
33+ if localOnly && opts .CopiesNumber > 1 {
34+ return nil , errors .New ("storage of multiple object replicas is requested for a local operation" )
35+ }
36+
37+ localNodeKey , err := p .keyStorage .GetKey (nil )
38+ if err != nil {
39+ return nil , fmt .Errorf ("get local node's private key: %w" , err )
40+ }
41+
42+ idCnr := hdr .GetContainerID ()
43+ if idCnr .IsZero () {
44+ return nil , errors .New ("missing container ID" )
45+ }
46+
47+ // get container to store the object
48+ cnr , err := p .cnrSrc .Get (idCnr )
49+ if err != nil {
50+ return nil , fmt .Errorf ("(%T) could not get container by ID: %w" , p , err )
51+ }
52+
53+ containerNodes , err := p .neoFSNet .GetContainerNodes (idCnr )
54+ if err != nil {
55+ return nil , fmt .Errorf ("select storage nodes for the container: %w" , err )
56+ }
57+
58+ cnrNodes := containerNodes .Unsorted ()
59+ ecRulesN := len (containerNodes .ECRules ())
60+
61+ var localNodeInContainer bool
62+ var ecPart iec.PartInfo
63+ if ecRulesN > 0 {
64+ ecPart , err = iec .GetPartInfo (* hdr )
65+ if err != nil {
66+ return nil , fmt .Errorf ("get EC part info from object header: %w" , err )
67+ }
68+
69+ repRulesN := len (containerNodes .PrimaryCounts ())
70+ if ecPart .Index >= 0 {
71+ if ecPart .RuleIndex >= ecRulesN {
72+ return nil , fmt .Errorf ("invalid EC part info in object header: EC rule idx=%d with %d rules in total" , ecPart .RuleIndex , ecRulesN )
73+ }
74+ if hdr .Signature () == nil {
75+ return nil , errors .New ("unsigned EC part object" )
76+ }
77+ localNodeInContainer = localNodeInSet (p .neoFSNet , cnrNodes [repRulesN + ecPart .RuleIndex ])
78+ } else {
79+ if repRulesN == 0 && hdr .Signature () != nil {
80+ return nil , errors .New ("missing EC part info in signed object" )
81+ }
82+ localNodeInContainer = localNodeInSets (p .neoFSNet , cnrNodes )
83+ }
84+ } else {
85+ localNodeInContainer = localNodeInSets (p .neoFSNet , cnrNodes )
86+ }
87+ if ! localNodeInContainer && localOnly {
88+ return nil , errors .New ("local operation on the node not compliant with the container storage policy" )
3589 }
3690
3791 maxPayloadSz := p .maxSizeSrc .MaxObjectSize ()
3892 if maxPayloadSz == 0 {
3993 return nil , fmt .Errorf ("(%T) could not obtain max object size parameter" , p )
4094 }
4195
42- homomorphicChecksumRequired := ! opts . cnr .IsHomomorphicHashingDisabled ()
96+ homomorphicChecksumRequired := ! cnr .IsHomomorphicHashingDisabled ()
4397
4498 target := & distributedTarget {
4599 svc : p ,
46- localNodeSigner : opts . localNodeSigner ,
47- metaSigner : opts . localSignerRFC6979 ,
100+ localNodeSigner : ( * neofsecdsa . Signer )( localNodeKey ) ,
101+ metaSigner : ( * neofsecdsa . SignerRFC6979 )( localNodeKey ) ,
48102 opCtx : ctx ,
49103 commonPrm : cp ,
50104 localOnly : cp .LocalOnly (),
51105 linearReplNum : uint (opts .CopiesNumber ),
52- metainfoConsistencyAttr : metaAttribute (opts . cnr ),
53- containerNodes : opts . containerNodes ,
54- localNodeInContainer : opts . localNodeInContainer ,
55- ecPart : opts . ecPart ,
106+ metainfoConsistencyAttr : metaAttribute (cnr ),
107+ containerNodes : containerNodes ,
108+ localNodeInContainer : localNodeInContainer ,
109+ ecPart : ecPart ,
56110 }
57111
58112 if hdr .Signature () != nil {
@@ -131,70 +185,6 @@ func (p *Service) initTarget(ctx context.Context, hdr *object.Object, cp *util.C
131185 }, nil
132186}
133187
134- func (p * Service ) prepareOptions (hdr * object.Object , cp * util.CommonPrm , opts * PutInitOptions ) error {
135- localOnly := cp .LocalOnly ()
136- if localOnly && opts .CopiesNumber > 1 {
137- return errors .New ("storage of multiple object replicas is requested for a local operation" )
138- }
139-
140- localNodeKey , err := p .keyStorage .GetKey (nil )
141- if err != nil {
142- return fmt .Errorf ("get local node's private key: %w" , err )
143- }
144-
145- idCnr := hdr .GetContainerID ()
146- if idCnr .IsZero () {
147- return errors .New ("missing container ID" )
148- }
149-
150- // get container to store the object
151- opts .cnr , err = p .cnrSrc .Get (idCnr )
152- if err != nil {
153- return fmt .Errorf ("(%T) could not get container by ID: %w" , p , err )
154- }
155-
156- opts .containerNodes , err = p .neoFSNet .GetContainerNodes (idCnr )
157- if err != nil {
158- return fmt .Errorf ("select storage nodes for the container: %w" , err )
159- }
160- cnrNodes := opts .containerNodes .Unsorted ()
161- ecRulesN := len (opts .containerNodes .ECRules ())
162- if ecRulesN > 0 {
163- ecPart , err := iec .GetPartInfo (* hdr )
164- if err != nil {
165- return fmt .Errorf ("get EC part info from object header: %w" , err )
166- }
167-
168- repRulesN := len (opts .containerNodes .PrimaryCounts ())
169- if ecPart .Index >= 0 {
170- if ecPart .RuleIndex >= ecRulesN {
171- return fmt .Errorf ("invalid EC part info in object header: EC rule idx=%d with %d rules in total" , ecPart .RuleIndex , ecRulesN )
172- }
173- if hdr .Signature () == nil {
174- return errors .New ("unsigned EC part object" )
175- }
176- opts .localNodeInContainer = localNodeInSet (p .neoFSNet , cnrNodes [repRulesN + ecPart .RuleIndex ])
177- } else {
178- if repRulesN == 0 && hdr .Signature () != nil {
179- return errors .New ("missing EC part info in signed object" )
180- }
181- opts .localNodeInContainer = localNodeInSets (p .neoFSNet , cnrNodes )
182- }
183-
184- opts .ecPart = ecPart
185- } else {
186- opts .localNodeInContainer = localNodeInSets (p .neoFSNet , cnrNodes )
187- }
188- if ! opts .localNodeInContainer && localOnly {
189- return errors .New ("local operation on the node not compliant with the container storage policy" )
190- }
191-
192- opts .localNodeSigner = (* neofsecdsa .Signer )(localNodeKey )
193- opts .localSignerRFC6979 = (* neofsecdsa .SignerRFC6979 )(localNodeKey )
194-
195- return nil
196- }
197-
198188func metaAttribute (cnr container.Container ) string {
199189 return cnr .Attribute ("__NEOFS__METAINFO_CONSISTENCY" )
200190}
0 commit comments