@@ -51,43 +51,45 @@ func initContainerService(c *cfg) {
5151 }
5252
5353 if c .containerCache != nil {
54- subscribeToContainerCreation (c , func (id cid.ID ) {
55- // read owner of the created container in order to update the reading cache.
56- // TODO: use owner directly from the event after neofs-contract#256 will become resolved
57- // but don't forget about the profit of reading the new container and caching it:
58- // creation success are most commonly tracked by polling GET op.
59- cnr , err := c .containerCache .Get (id )
60- if err == nil {
61- c .containerListCache .update (cnr .Value .Owner (), id , true )
62- } else {
63- // unlike removal, we expect successful receive of the container
64- // after successful creation, so logging can be useful
65- c .log .Error ("read newly created container after the notification" ,
66- zap .Stringer ("id" , id ),
67- zap .Error (err ),
68- )
54+ subscribeToContainerCreation (c , func (id cid.ID , owner user.ID ) {
55+ if owner .IsZero () {
56+ c .log .Debug ("container removal event's receipt" , zap .Stringer ("id" , id ))
57+ // read owner of the created container in order to update the reading cache.
58+ cnr , err := c .containerCache .Get (id )
59+ if err == nil {
60+ c .containerListCache .update (cnr .Value .Owner (), id , true )
61+ } else {
62+ // unlike removal, we expect successful receive of the container
63+ // after successful creation, so logging can be useful
64+ c .log .Error ("read newly created container after the notification" , zap .Stringer ("id" , id ), zap .Error (err ))
65+ }
66+ return
6967 }
70-
71- c .log .Debug ("container creation event's receipt" ,
72- zap .Stringer ("id" , id ),
73- )
68+ c .log .Info ("caught container creation, updating cache..." , zap .Stringer ("id" , id ), zap .Stringer ("owner" , owner ))
69+ c .containerListCache .update (owner , id , true )
7470 })
7571
76- subscribeToContainerRemoval (c , func (id cid.ID ) {
77- // read owner of the removed container in order to update the listing cache.
78- // It's strange to read already removed container, but we can successfully hit
79- // the cache.
80- // TODO: use owner directly from the event after neofs-contract#256 will become resolved
81- cnr , err := c .containerCache .Get (id )
82- if err == nil {
83- c .containerListCache .update (cnr .Value .Owner (), id , false )
72+ subscribeToContainerRemoval (c , func (id cid.ID , owner user.ID ) {
73+ if owner .IsZero () {
74+ c .log .Debug ("container removal event's receipt" , zap .Stringer ("id" , id ))
75+ // read owner of the removed container in order to update the listing cache.
76+ // It's strange to read already removed container, but we can successfully hit
77+ // the cache.
78+ cnr , err := c .containerCache .Get (id )
79+ if err == nil {
80+ c .containerListCache .update (cnr .Value .Owner (), id , false )
81+ }
82+ c .containerCache .handleRemoval (id )
83+ return
8484 }
85+ c .log .Info ("caught container removal, updating cache..." , zap .Stringer ("id" , id ),
86+ zap .Stringer ("owner" , owner ))
8587
88+ c .containerListCache .update (owner , id , false )
8689 c .containerCache .handleRemoval (id )
8790
88- c .log .Debug ("container removal event's receipt" ,
89- zap .Stringer ("id" , id ),
90- )
91+ c .log .Info ("successfully updated cache of the removed container" ,
92+ zap .Stringer ("id" , id ))
9193 })
9294 }
9395
@@ -212,21 +214,33 @@ func registerEventParserOnceContainer(c *cfg, name string, p event.NotificationP
212214
213215// subscribes to successful container creation. Provided handler is called asynchronously
214216// on corresponding routine pool. MUST NOT be called concurrently with itself and other
215- // similar functions.
216- func subscribeToContainerCreation (c * cfg , h func (cid.ID )) {
217+ // similar functions. Owner may be zero.
218+ func subscribeToContainerCreation (c * cfg , h func (id cid. ID , owner user .ID )) {
217219 const eventNameContainerCreated = "PutSuccess"
218220 registerEventParserOnceContainer (c , eventNameContainerCreated , containerEvent .ParsePutSuccess )
219221 addContainerAsyncNotificationHandler (c , eventNameContainerCreated , func (e event.Event ) {
220- h (e .(containerEvent.PutSuccess ).ID )
222+ h (e .(containerEvent.PutSuccess ).ID , user.ID {})
223+ })
224+ const eventNameContainerCreatedV2 = "Created"
225+ registerEventParserOnceContainer (c , eventNameContainerCreatedV2 , containerEvent .RestoreCreated )
226+ addContainerAsyncNotificationHandler (c , eventNameContainerCreatedV2 , func (e event.Event ) {
227+ created := e .(containerEvent.Created )
228+ h (created .ID , created .Owner )
221229 })
222230}
223231
224- // like subscribeToContainerCreation but for removal.
225- func subscribeToContainerRemoval (c * cfg , h func (cid.ID )) {
232+ // like subscribeToContainerCreation but for removal. Owner may be zero.
233+ func subscribeToContainerRemoval (c * cfg , h func (id cid. ID , owner user .ID )) {
226234 const eventNameContainerRemoved = "DeleteSuccess"
227235 registerEventParserOnceContainer (c , eventNameContainerRemoved , containerEvent .ParseDeleteSuccess )
228236 addContainerAsyncNotificationHandler (c , eventNameContainerRemoved , func (e event.Event ) {
229- h (e .(containerEvent.DeleteSuccess ).ID )
237+ h (e .(containerEvent.DeleteSuccess ).ID , user.ID {})
238+ })
239+ const eventNameContainerRemovedV2 = "Removed"
240+ registerEventParserOnceContainer (c , eventNameContainerRemovedV2 , containerEvent .RestoreRemoved )
241+ addContainerAsyncNotificationHandler (c , eventNameContainerRemovedV2 , func (e event.Event ) {
242+ removed := e .(containerEvent.Removed )
243+ h (removed .ID , removed .Owner )
230244 })
231245}
232246
0 commit comments