Skip to content

fix(posix): re-assimilate moved and changed files during a scan - #808

Merged
aduffeck merged 3 commits into
opencloud-eu:mainfrom
NickWalters:fix/posix-warmup-detect-changes
Oct 14, 2026
Merged

aduffeck merged 3 commits into
opencloud-eu:mainfrom
NickWalters:fix/posix-warmup-detect-changes

Conversation

@NickWalters

@NickWalters NickWalters commented Sep 20, 2026 •

Copy link
Copy Markdown

Fixes opencloud-eu/opencloud#3251

Problem

opencloud posixfs scan and the startup scan miss files that were renamed, moved or changed on disk. A renamed or moved file keeps its old user.oc.name and user.oc.parentid. A changed file keeps its old user.oc.mtime, so it also keeps its old etag and clients see nothing.

The startup scan uses the same walk (tree.go:199, WarmupIDCache(root, true, false)) and runs whenever ScanFS is on, which is the default. With WatchFS off, also the default, that walk is the only thing that picks up changes on disk. So a restart doesn't fix it either.

How to reproduce

  1. Create a.txt in a posix space and run opencloud posixfs scan <space path>. The file shows up.
  2. Run mv a.txt b.txt, or change the content of a.txt, and run the scan again.
  3. OpenCloud still shows the old name, or the old mtime and etag.

Cause

The walk in WarmupIDCache assimilates a known item again only when it is a copy with a clashing id. For every other known item it only points the id cache entry at the current path.

Fix

The walk assimilates an item again when its name or parent changed, or when its mtime on disk differs from the stored one. assimilate skips items whose path and mtime still match, so files that are up to date cost nothing extra.

  • An item whose ancestor was renamed is left alone. Only its cache entry is stale, and the CacheID call already fixes that. Assimilating it would read the whole file for its checksums, write a new blob id and, with EnableFSRevisions, create a revision, for every file under the renamed folder. The walk keeps the ids of the folders it passed (filepath.Walk visits a folder before its children), so this needs no extra reads.
  • Folders are left out of the mtime check, because adding or removing a child changes a folder's mtime. The name check still catches a renamed folder.
  • Only os.IsNotExist counts as "gone from the old path". A stat that fails with EACCES or EIO is not a move.
  • A missing or unparsable mtime attribute doesn't count as a change. Otherwise every scan would assimilate that item.
  • The new work runs only when assimilate is true. tree.go:530 and the GPFS audit watcher pass false and behave as before. The existing copy branch stays as it was.

Tests

Three specs in warmup_test.go: a renamed file, a changed file, and a renamed folder whose child must keep its blob id. All three fail on main. go test -race ./pkg/storage/fs/posix/... passes locally and golangci-lint is clean.

Known gap

A rename that keeps the mtime is missed while the id cache has no entry for the node. Comparing the stored user.oc.name with the name on disk would close that, at the cost of one more xattr read per item. I can add it if you want it.

Notes

This conflicts with #849 and #853 in the same part of WarmupIDCache. Both sides add lines, and #853 reads the stored parent id into a variable with another name. I merged all of them together and go test -race ./pkg/storage/fs/posix/... passes on the result. I'll rebase whichever one goes second.

@aduffeck aduffeck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This conflicts with main now that #849 has been merged so it needs to bebased.

// again only when its own name or parent changed. When an ancestor was
// renamed the item itself stayed as it was and the stale cache entry
// is all there is to fix.
parentOnDisk, known := dirIDs[filepath.Dir(path)]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That still leaves a little loophole though. Moves into folders created since the last scans are missed because they didn't end up in the dirIDs map.
I think a fix could be to use read the parent's id with IdentifyPath(filepath.Dir(path)) instead. That way we wouldn't need the dirIDs map at all.

@NickWalters NickWalters Oct 14, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good pickup. Rebased on main, and the dirIDs map is gone. It now reads the parent's id with IdentifyPath(filepath.Dir(path)), as you suggested. I added a spec for a file moved into a folder created since the last scan. It fails with the old map and passes now.

The walk in WarmupIDCache only re-assimilated an item when it was a copy
that carried a clashing id. For everything else it just pointed the id
cache at the current path, so the metadata of the item itself was never
updated. A file renamed or moved on disk kept its old name and parent id,
and a file that changed kept its old mtime, which also kept the old etag.
Neither a rescan nor a restart repaired it.

This assimilates an item again when its name or its parent changed, or
when the mtime on disk differs from the one in the metadata. An item
whose ancestor was renamed is left alone: it did not change itself, and
its stale cache entry is fixed by the CacheID call that was there before.
That matters because updateFile reads the whole file for its checksums
and gives it a new blob id.

Directories are left out of the mtime comparison, because their mtime on
disk also changes when a child is added or removed, and the walk visits
those children anyway. The new work is gated on the assimilate flag, so
callers that only want the id cache warmed up keep the behaviour they had.

Fixes opencloud-eu/opencloud#3251
@NickWalters
NickWalters force-pushed the fix/posix-warmup-detect-changes branch from c358968 to 2e04ae6 Compare October 14, 2026 02:19
@NickWalters

NickWalters commented Oct 14, 2026 •

Copy link
Copy Markdown
Author

if its all good. please make sure to add a label before merging, so it ends up in the release notes (or alternatively fix the bug where you need a label in your PR for release notes..). so end users and non technical staff have visibility into each release.

assimilate skipped an item when its cached path matched the path on disk
and its mtime was unchanged. A file renamed on disk can get there with
its old name still in the metadata, for example when the id cache was
updated but the rename itself was never assimilated. The item then kept
the old name in every listing, and neither a scan nor a restart fixed it.

assimilate now also compares the stored name with the name on disk
before it skips an item, and the scan re-assimilates an item whose name
is stale. Space roots are left out, because their name doesn't have to
match their directory.

Refs opencloud-eu/opencloud#1810
@NickWalters

Copy link
Copy Markdown
Author

I added ed2114e for a case that came up on opencloud-eu/opencloud#1810. A file renamed on disk can keep its old name when the id cache already has the new path. assimilate then skipped it, because the cached path and the mtime both match. It now also compares the stored name with the name on disk before it skips an item, and the scan re-assimilates an item with a stale name. Space roots are left out. The new spec fails without the change, and also fails with only the scan part.

assimilate read the mtime and stat of an item before it took the item's
lock, and decided whether to skip it with those values after it got the
lock. An upload holds that lock while it sets the mtime on disk and then
writes the mtime attribute. A scan that got between the two saw a changed
file, waited for the lock and re-assimilated it with the old values. That
cleared the upload's processing status and gave the file a new blob id,
so the upload ended up in a revision instead of the file. assimilate now
reads both again once it holds the lock.

The stale-name check also covers the parent now: an item moved to another
directory under the same name kept its old parent id when the id cache
already had the new path, e.g. after the cache-only warmup that runs on a
GPFS rename. And it reads the name and parent id from disk, like
IdentifyPath, so a cached copy can't hide a difference or fake one.
@NickWalters

NickWalters commented Oct 14, 2026 •

Copy link
Copy Markdown
Author

I added 92abba7 after a second review of the branch:

  • A scan running during an upload could re-assimilate the file. The upload holds the lock while it sets the mtime on disk and then writes the mtime attribute. assimilate read both before it took the lock, so a scan that got between the two re-assimilated the file with stale values. That cleared the upload's processing status, and the upload ended up in a revision. assimilate now reads them again once it holds the lock. This one came from the new mtime check in this PR, so it had to be fixed here.
  • The stale-name check from ed2114e now also compares the parent id. An item moved to another folder under the same name kept its old parent when the id cache already had the new path. The cache-only warmup on a GPFS rename can cause that.
  • The check reads the name and parent id from disk, like IdentifyPath, not through the metadata cache.

Each fix has a spec that fails without it. The race spec holds the lock the way an upload does, and it passed 20 of 20 runs. The posix suite passes 3 runs in a row with -race, and lint

@aduffeck aduffeck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍 thanks, lgtm

@aduffeck
aduffeck merged commit 4109b7f into opencloud-eu:main Oct 14, 2026
20 checks passed
@openclouders openclouders mentioned this pull request Oct 14, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

posixfs scan command doesn't catch file changes

2 participants