Repository navigation
fix(posix): re-assimilate moved and changed files during a scan - #808
Conversation
| // 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)] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
c358968 to
2e04ae6
Compare
|
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
|
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 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.
|
I added 92abba7 after a second review of the branch:
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 |
Fixes opencloud-eu/opencloud#3251
Problem
opencloud posixfs scanand the startup scan miss files that were renamed, moved or changed on disk. A renamed or moved file keeps its olduser.oc.nameanduser.oc.parentid. A changed file keeps its olduser.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 wheneverScanFSis on, which is the default. WithWatchFSoff, 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
a.txtin a posix space and runopencloud posixfs scan <space path>. The file shows up.mv a.txt b.txt, or change the content ofa.txt, and run the scan again.Cause
The walk in
WarmupIDCacheassimilates 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.
assimilateskips items whose path and mtime still match, so files that are up to date cost nothing extra.CacheIDcall already fixes that. Assimilating it would read the whole file for its checksums, write a new blob id and, withEnableFSRevisions, create a revision, for every file under the renamed folder. The walk keeps the ids of the folders it passed (filepath.Walkvisits a folder before its children), so this needs no extra reads.os.IsNotExistcounts as "gone from the old path". A stat that fails withEACCESorEIOis not a move.assimilateis true.tree.go:530and the GPFS audit watcher passfalseand 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.namewith 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 andgo test -race ./pkg/storage/fs/posix/...passes on the result. I'll rebase whichever one goes second.