Skip to content

Commit 3e4cd15

Browse files
authored
meta: do not try processing non-meta-enabled containers (#3173)
2 parents 9f00c0c + 3964bfc commit 3e4cd15

File tree

4 files changed

+63
-25
lines changed

4 files changed

+63
-25
lines changed

cmd/neofs-node/meta.go

+47-25
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,47 @@ type metaContainerListener struct {
6363
prevRes map[cid.ID]struct{}
6464
}
6565

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+
66107
func (c *metaContainerListener) List() (map[cid.ID]struct{}, error) {
67108
actualContainers, err := c.cnrClient.List(nil)
68109
if err != nil {
@@ -99,33 +140,14 @@ func (c *metaContainerListener) List() (map[cid.ID]struct{}, error) {
99140
var wg errgroup.Group
100141
for _, cID := range actualContainers {
101142
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
112146
}
113147

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()
129151

130152
return nil
131153
})

pkg/services/meta/meta.go

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ type ContainerLister interface {
3131
// List returns node's containers that support chain-based meta data and
3232
// any error that does not allow listing.
3333
List() (map[cid.ID]struct{}, error)
34+
// IsMineWithMeta checks if the given CID has meta enabled and current
35+
// node belongs to it.
36+
IsMineWithMeta(cid.ID) (bool, error)
3437
}
3538

3639
// wsClient is for test purposes only.

pkg/services/meta/notifications.go

+9
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ func (m *Meta) listenNotifications(ctx context.Context) error {
119119
continue
120120
}
121121

122+
ok, err = m.cLister.IsMineWithMeta(ev.cID)
123+
if err != nil {
124+
l.Error("can't get container data", zap.Error(err))
125+
continue
126+
}
127+
if !ok {
128+
continue
129+
}
130+
122131
m.m.Lock()
123132

124133
st, err := storageForContainer(m.rootPath, ev.cID)

pkg/services/meta/notifications_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ type testContainerLister struct {
3939
resErr error
4040
}
4141

42+
func (t *testContainerLister) IsMineWithMeta(id cid.ID) (bool, error) {
43+
return true, nil
44+
}
45+
4246
func (t *testContainerLister) List() (map[cid.ID]struct{}, error) {
4347
return t.res, t.resErr
4448
}

0 commit comments

Comments
 (0)