Skip to content

fix(posix): back off retries of files that failed to assimilate - #796

Merged
aduffeck merged 2 commits into
opencloud-eu:mainfrom
NickWalters:fix/posix-assimilation-backoff
Sep 18, 2026
Merged

aduffeck merged 2 commits into
opencloud-eu:mainfrom
NickWalters:fix/posix-assimilation-backoff

Conversation

@NickWalters

@NickWalters NickWalters commented Sep 10, 2026 •

Copy link
Copy Markdown

Fixes opencloud-eu/opencloud#3498

Some files can't be assimilated, and the cause doesn't go away by itself. In my case the opencloud user had no write permission on the files, so it couldn't set the user.oc.* xattrs. Nothing remembers such a failure. The next directory listing or scan tries again. Each try reads the whole file for its checksums before it gets to the step that fails. On my setup that was about 117 MB/s of reads for 46 hours before I found the cause.

With this change, updateFile remembers files that failed after the checksum step. The new tree/assimilation package keeps them by path in assimilation.Failures, which wraps an expirable LRU from golang-lru (already a dependency). While the mtime, size, mode, owner and group of a file stay the same, updateFile skips it until a delay ends. The delay starts at 1 minute and doubles with each failure, up to 24h. If the file changes, for example after a chmod or chown, the next scan tries it right away.

The cache keeps at most 10,000 failures, which is about 8 MB. When it is full, it keeps the failures it has and doesn't store new ones. An LRU would evict each file before a scan over more failing files comes back to it. So only the files beyond the limit get read on every scan, like before. Entries expire after 48h, so paths that no longer exist don't pile up.

Only failures after the checksum step go into the cache. The steps before it are cheap: locking, parent lookups and reading attributes. Failures there still retry on the next scan or listing, like before. So a file that failed because of its parent directory gets another try as soon as someone fixes the directory. A short ID cache outage mostly fails at the parent lookup, so it doesn't leave files waiting on a backoff either.

The skip returns the original error, so the logs still show the real cause:

item is unchanged since it failed to assimilate, not retrying before 2026-09-18T12:22:21+08:00: failed to set 10/10 xattrs: xattr.Set .../readonly user.oc.name: permission denied

One gap is left. An ACL or chattr change leaves the mtime, size, mode and owner alone. So that fix only takes effect at the next retry or after a restart. I thought about comparing ctime instead. But ctime also changes when some of the xattr writes succeed, so a file where only some of them fail would loop again.

The backoff also applies when the cause isn't the file itself, for example a full disk. After such an outage ends, a file waits about as long as the outage lasted, up to 24h, or until the next restart.

For tests, a new spec in tree_non_watching_test.go lists a folder with a read-only file in it twice. It uses the access time of the file to check that only the first listing reads it. It fails on main and passes with this change. It skips when it runs as root, because root can set xattrs on read-only files. It also skips on file systems that don't update access times.

The unit-test pipeline runs as root in the golang image. So assimilation.Failures has its own specs too, and those run as root. They cover the retry delay, the backoff and the chmod and chown checks. go test -race ./pkg/storage/fs/posix/... passes locally, and golangci-lint reports no issues on the package.

Related: updateFile used to propagate the size of a file to its parents before it wrote the attributes of the file. So every failed try inflated the tree sizes. #797 fixed that and is merged now.

@NickWalters NickWalters changed the title fix(posix): back off retries of items that failed to assimilate fix(posix): back off retries of files that failed to assimilate Sep 10, 2026
@NickWalters
NickWalters force-pushed the fix/posix-assimilation-backoff branch 2 times, most recently from fcd3901 to fc2f433 Compare September 10, 2026 16:02
@NickWalters

Copy link
Copy Markdown
Author

Hi @aduffeck and @rhafer, sorry for the ping. This is my first PR here, so CI is sitting at "pending approval" until someone lets it run. Could one of you kick it off when you get a chance? I think it'll also need a Type:Bug label.

#797 is the tree size fix I mentioned in the description. They don't depend on each other, so either can go in first. Thanks!

A file that failed to assimilate after its checksums were computed, e.g.
because the service user can't set extended attributes on it, was
assimilated again on every directory listing and scan, reading the whole
file each time.

Remember such failures per path and don't read the file again while it
is unchanged (same mtime, size, mode and inode) until a retry delay has
passed. The delay starts at a minute and doubles with every failure up
to a day. Failures before the checksum step are cheap and still retried
right away. The skip returns the last error so logs still say why the
file isn't assimilated.

Fixes opencloud-eu/opencloud#3498
@NickWalters
NickWalters force-pushed the fix/posix-assimilation-backoff branch from fc2f433 to 8b6886e Compare September 16, 2026 16:09
@NickWalters

NickWalters commented Sep 16, 2026 •

Copy link
Copy Markdown
Author

Thanks for kicking off CI last time. The build failed at the upload step because the old minio/mc image returned a 403, which #801 has since fixed. I rebased this and #797 onto main to pick up that change. The code itself is unchanged. @aduffeck @rhafer, could one of you approve the new runs when you get a chance?

Comment thread pkg/storage/fs/posix/tree/tree.go Resolved
@NickWalters
NickWalters force-pushed the fix/posix-assimilation-backoff branch from 2e59ae4 to 2139177 Compare September 18, 2026 04:28
@NickWalters
NickWalters force-pushed the fix/posix-assimilation-backoff branch 2 times, most recently from 79a3cdd to e55e677 Compare September 18, 2026 04:45
Changes from the review:

- Move the failure tracking from tree to a new tree/assimilation
  package, as assimilation.Failures with Recent and Record.
- Use unnamed returns in updateFile again. The deferred Record reads
  the err that updateFile declares. Every failure after the checksum
  step sets it before it returns.
- Compare the uid and gid of the file instead of its inode. A retry now
  starts as soon as a chown makes the file assimilatable.
- Keep at most 10000 failures, which is about 8 MB. When full, keep the
  stored ones and don't store new ones. With LRU eviction, a scan over
  more failing files evicted each entry before it got back to that file,
  so it skipped nothing.
@NickWalters
NickWalters force-pushed the fix/posix-assimilation-backoff branch from e55e677 to 7cf03ea Compare September 18, 2026 05:00
@NickWalters

NickWalters commented Sep 18, 2026 •

Copy link
Copy Markdown
Author

@aduffeck I've pushed changes for your review comments. Could you or @rhafer approve the CI run again when you get a chance? Thanks

@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.

Awesome, thank you. lgtm

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.

posix: files that fail to assimilate are re-read in full on every scan, with no backoff

2 participants