Skip to content

fix: avoid skipping file records in orphan upload cleanup - #1635

Open
lhk0504 wants to merge 1 commit into
apache:mainfrom
lhk0504:fix/clean-orphan-upload-files-pagination
Open

lhk0504 wants to merge 1 commit into
apache:mainfrom
lhk0504:fix/clean-orphan-upload-files-pagination

Conversation

@lhk0504

@lhk0504 lhk0504 commented Sep 24, 2026

Copy link
Copy Markdown

Fixes #1631

Proposed Changes

  • Replace the OFFSET/LIMIT pagination of available file records with an id cursor query: status = Available AND id > lastID ORDER BY id ASC LIMIT n (GetFileRecordListAfterID).
  • Advance the lastID cursor per record in CleanOrphanUploadFiles, so records marked as Deleted during the scan no longer shift the remaining records forward and make the next page skip records that were never checked.
  • Add a regression test that runs the cleanup over 2500 records spanning several pages and asserts every eligible orphan is deleted and moved to the deleted directory, while referenced records and records younger than 48 hours are kept.

The removed GetFileRecordPage was only used by this cleanup loop.

CleanOrphanUploadFiles scans available file records with OFFSET/LIMIT
pagination while marking the processed orphans as Deleted, which removes
them from the available result set. The records that follow shift forward,
so the offset of the next page skips records that were never checked in
the same cleanup run.

Scan the available records by id cursor instead: query the records with
status = Available and id greater than the last scanned id, ordered by id
ascending, and advance the cursor per record. Records marked as deleted
during the scan no longer affect the position of the remaining records,
so every eligible record is checked in a single run.

Close apache#1631
Copilot AI lite review requested due to automatic review settings September 24, 2026 11:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

No unresolved review issues were identified.

Review effort: Lite
Findings: None

What changed in this PR

Fixes orphan-upload cleanup skipping records when deleted records shift offset-based pages.

Changes:

  • Replaces offset pagination with ID-cursor pagination.
  • Advances the cursor for each processed record.
  • Adds regression coverage across 2,500 records.
File Description
internal/​service/​file_record/​file_record_service.go Uses cursor-based cleanup scanning.
internal/​service/​file_record/​file_record_service_test.go Adds multi-page regression coverage.
internal/​repo/​file_record/​file_record_repo.go Implements ordered ID-cursor querying.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

This branch has not been deployed

No deployments
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.

CleanOrphanUploadFiles may skip records when using offset pagination

2 participants