Skip to content

dfs: improve read path downloader reuse#283

Open
Trifocals3537 wants to merge 5 commits into
sirrobot01:betafrom
Trifocals3537:improve/dfs-read-path
Open

dfs: improve read path downloader reuse#283
Trifocals3537 wants to merge 5 commits into
sirrobot01:betafrom
Trifocals3537:improve/dfs-read-path

Conversation

@Trifocals3537
Copy link
Copy Markdown

📌 Description

  • Improves DFS read-path behavior by reusing active downloaders across rapid sequential, nearby, and contiguous reads instead of creating and stopping downloaders too aggressively.

Target Branch Check (IMPORTANT)

  • I confirm this PR is targeting the correct branch

Expected target:

  • beta (for features)

Changes Made

  • Reuses active DFS downloaders when reads fall within or near an assigned downloader range.
  • Preserves adaptive chunk state across contiguous downloader activity.
  • Delays downloader shutdown across short close/reopen gaps to reduce churn from Plex, ffprobe, and seek behavior.
  • Adds tracing for downloader lifecycle, upstream fetches, and read amplification.
  • Adds focused unit tests for downloader reuse, adaptive state handling, read-ahead behavior, delayed stop handling, and watchdog behavior.

Testing

  • Tested locally

Steps:

  1. Rebased branch onto upstream/beta.
  2. Ran focused DFS VFS tests: go test ./pkg/mount/dfs/vfs -v
  3. Performed live Plex playback testing with remux/media files, including start playback, short playback, forward seek, and backward seek behavior.

Risks / Notes

  • This change is focused on the DFS read path and downloader lifecycle behavior.
  • Full go test ./... currently has unrelated failures on upstream/beta in:
    • internal/utils
    • pkg/usenet/fs/reader
  • No migrations or config changes.

Screenshots (if applicable)

N/A


Checklist

  • Code builds successfully
  • No console/log errors
  • Reviewed my own code
  • Target branch is correct

@Trifocals3537 Trifocals3537 force-pushed the improve/dfs-read-path branch from 01162f3 to a1c3005 Compare May 23, 2026 04:00
Copilot AI review requested due to automatic review settings May 23, 2026 04:00
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR improves DFS VFS download behavior by adding shared adaptive chunking across contiguous downloader lifecycles, enhancing downloader reuse heuristics, and introducing a grace period before stopping downloaders when the final file handle closes.

Changes:

  • Add shared “adaptive state” so sequential reads don’t re-ramp chunk sizes when a nearby downloader restarts.
  • Expand downloader reuse matching and add detailed trace logging for reuse, read-ahead expansion, and upstream fetches.
  • Delay stopping downloaders after last handle close via a grace period; add tests for the new behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
pkg/mount/dfs/vfs/downloaders_test.go Adds tests for adaptive state inheritance/reset decisions, downloader reuse matching, and grace-period stop/cancel behavior.
pkg/mount/dfs/vfs/downloaders.go Implements shared adaptive state, extends downloader matching to include assigned range, and adds multiple trace events around downloader lifecycle/read-ahead/upstream fetch.
pkg/mount/dfs/vfs/cache.go Adds delayed downloader shutdown with a grace-period timer, cancellation on reopen/close, and trace logging for cache misses.

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

Comment thread pkg/mount/dfs/vfs/cache.go
Comment thread pkg/mount/dfs/vfs/cache.go Outdated
Comment thread pkg/mount/dfs/vfs/downloaders_test.go Outdated
Comment thread pkg/mount/dfs/vfs/downloaders_test.go
Comment thread pkg/mount/dfs/vfs/downloaders.go Outdated
@Trifocals3537
Copy link
Copy Markdown
Author

Quick update on this PR:

I rebased the branch onto the latest upstream/beta and resolved the conflict in downloaders.go.

The main thing I checked during the conflict resolution was making sure we kept both sets of behavior:

  • the newer priority downloader behavior from beta
  • the read-path reuse/adaptive downloader improvements from this branch

I also added one small safety fix during the merge: priority/probe downloaders now avoid updating the shared adaptive state, so short probe reads should not accidentally reset or ramp down normal sequential playback behavior.

Validation completed:

  • Checked for leftover merge conflict markers
  • Ran git diff --check
  • Ran the targeted DFS/VFS test suite:
go test ./pkg/mount/dfs/vfs -count=1 -v

Result: targeted DFS/VFS tests passed.

Note: I’m not claiming a full go test ./... pass here because the latest beta baseline has unrelated test failures outside this PR’s DFS/VFS changes.

@Trifocals3537 Trifocals3537 force-pushed the improve/dfs-read-path branch from 6f30cf0 to a08bc4e Compare May 23, 2026 23:13
@Trifocals3537
Copy link
Copy Markdown
Author

Updated the PR based on the review feedback.

Changes made:

  • Made the release stop grace period atomic-backed for safer test overrides.
  • Added a test helper to restore the previous grace period value after each test.
  • Increased the grace-period test timeouts to reduce flakiness.
  • Renamed adaptiveStateForNewDownloader to adaptiveStateForNewDownloaderLocked.
  • Preserved priority downloader behavior so priority reads do not inherit or update shared adaptive state.

Validated locally:

  • git diff --check
  • conflict-marker grep across changed files
  • go test ./pkg/mount/dfs/vfs/... -race -count=1 -v

All passed locally.

@Trifocals3537
Copy link
Copy Markdown
Author

Added one more lock-order fix so StopDownloaders() runs after releasing handleMu.

Validated locally with:

  • git diff --check
  • conflict-marker grep across changed files
  • go test ./pkg/mount/dfs/vfs/... -race -count=1 -v

All passed locally.

@Trifocals3537 Trifocals3537 requested a review from Copilot May 23, 2026 23:24
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread pkg/mount/dfs/vfs/cache.go Outdated
Comment thread pkg/mount/dfs/vfs/downloaders.go
Comment thread pkg/mount/dfs/vfs/downloaders_test.go
@Trifocals3537 Trifocals3537 requested a review from Copilot May 23, 2026 23:40
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

Comment thread pkg/mount/dfs/vfs/downloaders.go
Comment thread pkg/mount/dfs/vfs/downloaders_test.go
Comment thread pkg/mount/dfs/vfs/cache.go
Comment thread pkg/mount/dfs/vfs/cache.go
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.

2 participants