Skip to content

fix(posix): retry a failed file once its ctime changes - #809

Merged
aduffeck merged 2 commits into
opencloud-eu:mainfrom
NickWalters:fix/posix-assimilation-ctime
Oct 14, 2026
Merged

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

Conversation

@NickWalters

@NickWalters NickWalters commented Sep 20, 2026 •

Copy link
Copy Markdown

Fixes #805, a follow-up to #796.

Problem

#796 skips a file that failed to assimilate while its mtime, size, mode and owner stay the same. The retry delay starts at 1 minute and doubles up to 24h. A fix that changes none of those fields goes unnoticed until the delay runs out or the service restarts. setfacl and chattr -i are the common ones. A copy that replaces the file with the same attributes waits just as long.

How to reproduce

  1. In a posix space, give a file an ACL that stops the service user from writing its xattrs. For example: the file belongs to another user, and its group:: entry is r-- for a group the service user is in.
  2. Let the watcher or a scan pick it up. The log shows failed to set ... xattrs ... permission denied.
  3. Run setfacl -m g::rwX <file>. The mode, owner, size and mtime don't change.
  4. The next scans log item is unchanged since it failed to assimilate, not retrying before <time> until the delay runs out.

On 8.1.0 this hit 136 files here (details in #805).

Fix

Record reads the file again after the failed attempt and keeps that ctime, and unchanged compares it. Any later change to the file or its attributes moves the ctime on, so the next scan tries the file again. It uses timemanager.StatCTime, so the platform split stays in one place.

The ctime is read after the attempt on purpose. An attempt that sets some attributes and then fails has already moved the ctime. A value from before the attempt would never match again, and every scan would read the whole file. If the stat fails, the ctime stays unknown and only the attributes decide, as on a system with no ctime.

The doubling check uses the attributes only. So a change that shows only in the ctime keeps the doubled delay instead of starting again at 1 minute. A file that is fixed, retried and fails again costs one read per fix.

Trade-off

The recorded state has the attributes from before the attempt and the ctime from after it. A bulk setfacl -R that lands while a large file is being read for its checksum gets absorbed into the recorded ctime, and that file waits for its retry. A ctime from before the attempt would bring back the retry loop above, which is worse.

Tests

The spec in tree_non_watching_test.go detected reads through the access time. That no longer works, because changing the access time also changes the ctime. It now counts the bytes this process read from /proc/self/io, with a file big enough that nothing else explains them, and skips where /proc/self/io is missing. It also checks that a chmod to the mode the file already has (what setfacl and chattr look like from here) makes the file get read again.

Both specs chmod until the ctime has really moved, because some kernels stamp it from a coarse clock.

go test -race ./pkg/storage/fs/posix/... passes locally, golangci-lint is clean, and the read-detection spec ran five times without a flake.

Notes

This conflicts with #853 on one import line in tree_non_watching_test.go. 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.

lgtm besides the timemanager.StatCTime() fix.

A file that fails to assimilate is skipped while its mtime, size, mode
and owner stay the same, with a delay that doubles up to 24h. A fix that
changes none of those fields went unnoticed until the delay ran out or
the service restarted. setfacl and chattr -i are the common ones, and a
copy that replaces the file with the same attributes behaves the same way.

The failure cache now also keeps the ctime, read after the failed attempt
so that the attributes the attempt did write are already in it. Any later
change to the file or its attributes moves the ctime on, and the next scan
tries the file again. The delay keeps doubling when only the ctime changed,
so a file that gets fixed again and again costs one read per fix. When the
file cannot be read again the ctime stays unknown and only the attributes
decide, which is what happens on a system that reports no ctime as well.

The spec for the skip found reads through the access time, which no longer
works: changing the access time changes the ctime as well. It counts the
bytes this process read instead, from /proc/self/io, and skips where that
file is missing.

Fixes opencloud-eu#805
@NickWalters
NickWalters force-pushed the fix/posix-assimilation-ctime branch from 5082655 to 061f2e2 Compare October 14, 2026 02:19
@NickWalters
NickWalters requested a review from aduffeck October 14, 2026 02:25
@aduffeck
aduffeck merged commit 617797c 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.

posix: notice setfacl and chattr fixes on files that failed to assimilate

2 participants