Skip to content

fix(fsx): stream directory entries in RemoveContents to avoid memory spike on large BN PVs#775

Merged
brunodam merged 4 commits into
mainfrom
00363-stream-removecontents-dir-entries
Jul 1, 2026
Merged

fix(fsx): stream directory entries in RemoveContents to avoid memory spike on large BN PVs#775
brunodam merged 4 commits into
mainfrom
00363-stream-removecontents-dir-entries

Conversation

@Dosik13

@Dosik13 Dosik13 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Description

This pull request changes the following:

  • pkg/fsx/manager_unix.goRemoveContents now streams directory entries in bounded
    batches via (*os.File).ReadDir(256) instead of loading the whole listing with
    os.ReadDir, keeping memory usage constant on large block node PVs.
  • internal/workflows/steps/step_cluster_uninstall.go — the cleanup-weaver-files step
    uses the same batched read pattern for consistency, preserving its skip-dirs and
    best-effort teardown behavior.
  • pkg/fsx/manager_unix_test.go — adds TestUnixManager_RemoveContents_MultipleBatches,
    which exercises the batched loop across more than two full batches.

Related Issues

Dosik13 added 3 commits June 25, 2026 11:29
Signed-off-by: dosi <dosi.kolev@limechain.tech>
Signed-off-by: dosi <dosi.kolev@limechain.tech>
Signed-off-by: dosi <dosi.kolev@limechain.tech>
@Dosik13 Dosik13 requested a review from a team as a code owner June 25, 2026 09:36
@Dosik13 Dosik13 requested a review from alex-au June 25, 2026 09:36
@swirlds-automation

swirlds-automation commented Jun 25, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates filesystem cleanup logic to avoid memory spikes when deleting very large directories by switching from os.ReadDir (reads entire listing) to bounded batched reads via (*os.File).ReadDir(256). It applies the same pattern both to fsx.Manager.RemoveContents and to the cluster uninstall cleanup step, and adds a unit test to exercise multi-batch behavior.

Changes:

  • Stream directory entries in pkg/fsx/unixManager.RemoveContents using ReadDir(removeContentsBatchSize) batches.
  • Update CleanupWeaverFiles to iterate /opt/solo/weaver entries in batches while preserving skip-dirs + best-effort teardown behavior.
  • Add TestUnixManager_RemoveContents_MultipleBatches to cover removal across multiple full batches.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
pkg/fsx/manager_unix.go Reworks RemoveContents to open the directory and remove entries while iterating in fixed-size ReadDir batches.
internal/workflows/steps/step_cluster_uninstall.go Switches weaver-home cleanup to batched directory reads and keeps teardown best-effort semantics.
pkg/fsx/manager_unix_test.go Adds a new test ensuring RemoveContents works correctly across multiple ReadDir batches.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/workflows/steps/step_cluster_uninstall.go
Signed-off-by: dosi <dosi.kolev@limechain.tech>

@brunodam brunodam left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@brunodam brunodam merged commit 9d083fd into main Jul 1, 2026
20 checks passed
@brunodam brunodam deleted the 00363-stream-removecontents-dir-entries branch July 1, 2026 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(fsx): stream directory entries in RemoveContents to avoid memory spike on large BN PVs

4 participants