@@ -63,6 +63,47 @@ type metaContainerListener struct {
63
63
prevRes map [cid.ID ]struct {}
64
64
}
65
65
66
+ func (c * metaContainerListener ) IsMineWithMeta (id cid.ID ) (bool , error ) {
67
+ curEpoch , err := c .network .Epoch ()
68
+ if err != nil {
69
+ return false , fmt .Errorf ("read current NeoFS epoch: %w" , err )
70
+ }
71
+ networkMap , err := c .network .GetNetMapByEpoch (curEpoch )
72
+ if err != nil {
73
+ return false , fmt .Errorf ("read network map at the current epoch #%d: %w" , curEpoch , err )
74
+ }
75
+ return c .isMineWithMeta (id , networkMap )
76
+ }
77
+
78
+ func (c * metaContainerListener ) isMineWithMeta (id cid.ID , networkMap * netmapsdk.NetMap ) (bool , error ) {
79
+ cnr , err := c .containers .Get (id )
80
+ if err != nil {
81
+ return false , fmt .Errorf ("read %s container: %w" , id , err )
82
+ }
83
+
84
+ const metaOnChainAttr = "__NEOFS__METAINFO_CONSISTENCY"
85
+ switch cnr .Value .Attribute (metaOnChainAttr ) {
86
+ case "optimistic" , "strict" :
87
+ default :
88
+ return false , nil
89
+ }
90
+
91
+ nodeSets , err := networkMap .ContainerNodes (cnr .Value .PlacementPolicy (), id )
92
+ if err != nil {
93
+ return false , fmt .Errorf ("apply container storage policy to %s container: %w" , id , err )
94
+ }
95
+
96
+ for _ , nodeSet := range nodeSets {
97
+ for _ , node := range nodeSet {
98
+ if bytes .Equal (node .PublicKey (), c .key ) {
99
+ return true , nil
100
+ }
101
+ }
102
+ }
103
+
104
+ return false , nil
105
+ }
106
+
66
107
func (c * metaContainerListener ) List () (map [cid.ID ]struct {}, error ) {
67
108
actualContainers , err := c .cnrClient .List (nil )
68
109
if err != nil {
@@ -99,33 +140,14 @@ func (c *metaContainerListener) List() (map[cid.ID]struct{}, error) {
99
140
var wg errgroup.Group
100
141
for _ , cID := range actualContainers {
101
142
wg .Go (func () error {
102
- cnr , err := c .containers .Get (cID )
103
- if err != nil {
104
- return fmt .Errorf ("read %s container: %w" , cID , err )
105
- }
106
-
107
- const metaOnChainAttr = "__NEOFS__METAINFO_CONSISTENCY"
108
- switch cnr .Value .Attribute (metaOnChainAttr ) {
109
- case "optimistic" , "strict" :
110
- default :
111
- return nil
143
+ ok , err := c .isMineWithMeta (cID , networkMap )
144
+ if err != nil || ! ok {
145
+ return err
112
146
}
113
147
114
- nodeSets , err := networkMap .ContainerNodes (cnr .Value .PlacementPolicy (), cID )
115
- if err != nil {
116
- return fmt .Errorf ("apply container storage policy to %s container: %w" , cID , err )
117
- }
118
-
119
- for _ , nodeSet := range nodeSets {
120
- for _ , node := range nodeSet {
121
- if bytes .Equal (node .PublicKey (), c .key ) {
122
- locM .Lock ()
123
- res [cID ] = struct {}{}
124
- locM .Unlock ()
125
- return nil
126
- }
127
- }
128
- }
148
+ locM .Lock ()
149
+ res [cID ] = struct {}{}
150
+ locM .Unlock ()
129
151
130
152
return nil
131
153
})
0 commit comments