Skip to content

Commit cf42914

Browse files
authored
[Disk Manager] Fix style in filesystem traversal mechanism (#5142)
1 parent e47635b commit cf42914

File tree

4 files changed

+31
-25
lines changed

4 files changed

+31
-25
lines changed

cloud/disk_manager/internal/pkg/dataplane/filesystem_snapshot/filesystem_traversal/traversal.go

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,17 @@ func (t *FilesystemTraverser) Traverse(
9494
logging.String("FILESYSTEM_ID", t.filesystemID),
9595
logging.String("FILESYSTEM_CHECKPOINT_ID", t.filesystemCheckpointID),
9696
)
97+
defer close(t.processedNodeIDs)
98+
9799
if !t.rootNodeAlreadyScheduled {
98100
err := t.storage.ScheduleRootNodeForListing(ctx, t.filesystemSnapshotID)
99101
if err != nil {
100102
return err
101103
}
102104

103-
if t.stateSaver != nil {
104-
err = t.stateSaver(ctx)
105-
if err != nil {
106-
return err
107-
}
105+
err = t.stateSaver(ctx)
106+
if err != nil {
107+
return err
108108
}
109109
}
110110

@@ -126,7 +126,7 @@ func (t *FilesystemTraverser) Traverse(
126126
func (t *FilesystemTraverser) directoryScheduler(ctx context.Context) error {
127127
defer close(t.scheduledNodes)
128128

129-
processedNodeIDs := make(map[uint64]struct{})
129+
processingNodeIDs := make(map[uint64]struct{})
130130
pendingNodes := make([]*storage.NodeQueueEntry, 0)
131131

132132
for {
@@ -136,34 +136,34 @@ func (t *FilesystemTraverser) directoryScheduler(ctx context.Context) error {
136136
case <-ctx.Done():
137137
return ctx.Err()
138138
case nodeID := <-t.processedNodeIDs:
139-
delete(processedNodeIDs, nodeID)
139+
delete(processingNodeIDs, nodeID)
140140
case t.scheduledNodes <- node:
141141
pendingNodes = pendingNodes[:len(pendingNodes)-1]
142-
processedNodeIDs[node.NodeID] = struct{}{}
142+
processingNodeIDs[node.NodeID] = struct{}{}
143143
}
144144
continue
145145
}
146146

147147
entries, err := t.storage.SelectNodesToList(
148148
ctx,
149149
t.filesystemSnapshotID,
150-
processedNodeIDs,
150+
processingNodeIDs,
151151
t.selectNodesToListLimit,
152152
)
153153
if err != nil {
154154
return err
155155
}
156156

157157
if len(entries) == 0 {
158-
if len(processedNodeIDs) == 0 {
158+
if len(processingNodeIDs) == 0 {
159159
logging.Info(ctx, "Traversal complete for %s", t.filesystemSnapshotID)
160160
return nil
161161
}
162162
select {
163163
case <-ctx.Done():
164164
return ctx.Err()
165165
case nodeID := <-t.processedNodeIDs:
166-
delete(processedNodeIDs, nodeID)
166+
delete(processingNodeIDs, nodeID)
167167
}
168168
continue
169169
}
@@ -183,7 +183,12 @@ func (t *FilesystemTraverser) directoryLister(
183183
onListedNodes OnListedNodesFunc,
184184
) error {
185185

186-
session, err := t.client.CreateSession(ctx, t.filesystemID, t.filesystemCheckpointID, true)
186+
session, err := t.client.CreateSession(
187+
ctx,
188+
t.filesystemID,
189+
t.filesystemCheckpointID,
190+
true,
191+
)
187192
if err != nil {
188193
return err
189194
}
@@ -232,7 +237,7 @@ func (t *FilesystemTraverser) listNode(
232237

233238
cookie := node.Cookie
234239
for {
235-
nodes, nextCookie, err := t.client.ListNodes(
240+
children, nextCookie, err := t.client.ListNodes(
236241
ctx,
237242
session,
238243
node.NodeID,
@@ -242,15 +247,15 @@ func (t *FilesystemTraverser) listNode(
242247
return err
243248
}
244249

245-
if len(nodes) > 0 {
246-
err = onListedNodes(ctx, nodes, session, t.client)
250+
if len(children) > 0 {
251+
err = onListedNodes(ctx, children, session, t.client)
247252
if err != nil {
248253
return err
249254
}
250255
}
251256

252257
var childDirs []nfs.Node
253-
for _, n := range nodes {
258+
for _, n := range children {
254259
// In case of filesystem scrubbing, ListNodes may return InvalidNodeID
255260
// for nodes present in index tablet and absent in shard.
256261
// See: https://github.com/ydb-platform/nbs/issues/5094
@@ -275,7 +280,7 @@ func (t *FilesystemTraverser) listNode(
275280
return err
276281
}
277282

278-
if nextCookie == "" {
283+
if nextCookie == "" { // Listing of this node is finished
279284
return nil
280285
}
281286

cloud/disk_manager/internal/pkg/dataplane/filesystem_snapshot/storage/mocks/storage_mock.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,13 @@ func (s *StorageMock) SelectNodesToList(
151151
func (s *StorageMock) ScheduleChildNodesForListing(
152152
ctx context.Context,
153153
snapshotID string,
154-
nodeID uint64,
154+
parentNodeID uint64,
155155
nextCookie string,
156156
depth uint64,
157157
children []nfs.Node,
158158
) error {
159159

160-
args := s.Called(ctx, snapshotID, nodeID, nextCookie, depth, children)
160+
args := s.Called(ctx, snapshotID, parentNodeID, nextCookie, depth, children)
161161
return args.Error(0)
162162
}
163163

cloud/disk_manager/internal/pkg/dataplane/filesystem_snapshot/storage/storage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ type Storage interface {
118118
ScheduleChildNodesForListing(
119119
ctx context.Context,
120120
snapshotID string,
121-
nodeID uint64,
121+
parentNodeID uint64,
122122
nextCookie string,
123123
depth uint64,
124124
children []nfs.Node,

cloud/disk_manager/internal/pkg/dataplane/filesystem_snapshot/storage/storage_ydb.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,7 @@ func (s *storageYDB) selectNodesToList(
919919
}
920920

921921
// Exclude InvalidNodeID to avoid handling empty excludeNodeIDs slice case.
922+
// List can't be empty in YDB query.
922923
excludeNodeIDs = append(
923924
excludeNodeIDs,
924925
persistence.Uint64Value(
@@ -973,7 +974,7 @@ func (s *storageYDB) scheduleChildNodesForListing(
973974
ctx context.Context,
974975
session *persistence.Session,
975976
snapshotID string,
976-
nodeID uint64,
977+
parentNodeID uint64,
977978
nextCookie string,
978979
depth uint64,
979980
children []nfs.Node,
@@ -999,7 +1000,7 @@ func (s *storageYDB) scheduleChildNodesForListing(
9991000
where filesystem_snapshot_id = $snapshot_id and node_id = $node_id
10001001
`, s.tablesPath),
10011002
persistence.ValueParam("$snapshot_id", persistence.UTF8Value(snapshotID)),
1002-
persistence.ValueParam("$node_id", persistence.Uint64Value(nodeID)),
1003+
persistence.ValueParam("$node_id", persistence.Uint64Value(parentNodeID)),
10031004
)
10041005
} else {
10051006
_, err = tx.Execute(ctx, fmt.Sprintf(`
@@ -1014,7 +1015,7 @@ func (s *storageYDB) scheduleChildNodesForListing(
10141015
values ($snapshot_id, $node_id, $cookie, $depth)
10151016
`, s.tablesPath),
10161017
persistence.ValueParam("$snapshot_id", persistence.UTF8Value(snapshotID)),
1017-
persistence.ValueParam("$node_id", persistence.Uint64Value(nodeID)),
1018+
persistence.ValueParam("$node_id", persistence.Uint64Value(parentNodeID)),
10181019
persistence.ValueParam("$cookie", persistence.StringValue([]byte(nextCookie))),
10191020
persistence.ValueParam("$depth", persistence.Uint64Value(depth)),
10201021
)
@@ -1099,7 +1100,7 @@ func (s *storageYDB) SelectNodesToList(
10991100
func (s *storageYDB) ScheduleChildNodesForListing(
11001101
ctx context.Context,
11011102
snapshotID string,
1102-
nodeID uint64,
1103+
parentNodeID uint64,
11031104
nextCookie string,
11041105
depth uint64,
11051106
children []nfs.Node,
@@ -1114,7 +1115,7 @@ func (s *storageYDB) ScheduleChildNodesForListing(
11141115
ctx,
11151116
session,
11161117
snapshotID,
1117-
nodeID,
1118+
parentNodeID,
11181119
nextCookie,
11191120
depth,
11201121
children,

0 commit comments

Comments
 (0)