Repository navigation
feat: clean up old revisions according to a cleanup strategy - #895
Conversation
Points github.com/opencloud-eu/reva/v2 at the head of opencloud-eu/reva#895 in its fork (pbleser-oc/reva 4ebaa069b), which adds the revision cleanup this branch configures and calls, and re-vendors. Temporary: to be replaced by a regular reva bump once opencloud-eu/reva#895 is merged.
butonic
left a comment
There was a problem hiding this comment.
Ok, I could lament that some of the changes are not really necessary for the retention, but then again, they all prepare the code to be testable. Ultimately, they make the retention feature properly testable.
I'm happy to merge this now and change the implementation after we decided opencloud-eu/opencloud#3735, unless someone thinks we should have a non-surprising retention policy from the start.
two comments from a local review:pkg/storage/pkg/decomposedfs/revisioncleanup/service.go, Service.send:With the default block policy, a driver Service blocks the calling request goroutine (FinishUploadDecomposed, MarkProcessing, CommitUpload, RestoreRevision) until a worker frees a queue slot: stopped is only set for on-demand runs, so the request's context is never considered. This is documented as intentional backpressure and can't deadlock (the node lock is released before enqueueing, workers never block in send), but under sustained load with a slow blobstore (decomposeds3) it directly throttles uploads — and with FinishUploadDecomposed's context.WithoutCancel, even a disconnected client keeps waiting. Options worth considering: default to drop (nothing is lost permanently, the node is cleaned up again at its next revision, and the on-demand run covers the rest), or make block bounded (wait for room up to a timeout, then drop and count it on reva_revision_cleanup_queue_full_total). Since this can be changed and is disabled by default, not a merge blocker and we can revisit this after a loadtest. pkg/storage/pkg/decomposedfs/revisioncleanup/service.go, Service.cleanupNode:node.ReadNode(ctx, s.lu, spaceID, nodeID, "", false, nil, false) passes canListDisabledSpace=false, so a queued cleanup of a file in a disabled (trashed) space fails with "could not read node" and is reported as an error result — while the on-demand path (Decomposedfs.revisionCleanupRoot) explicitly distinguishes disabled spaces and reports them as skipped. Cosmetic, but the worker path could do the same (read with true, check IsDisabled, report Skipped) so disabled spaces don't show up as cleanup failures in the results/logs. |
4ebaa06 to
6083983
Compare
Points github.com/opencloud-eu/reva/v2 at the head of opencloud-eu/reva#895 in its fork (pbleser-oc/reva 608398352), which adds the revision cleanup this branch configures and calls, and re-vendors. Temporary: to be replaced by a regular reva bump once opencloud-eu/reva#895 is merged.
6083983 to
eba5978
Compare
Points github.com/opencloud-eu/reva/v2 at the head of opencloud-eu/reva#895 in its fork (pbleser-oc/reva eba5978bc), which adds the revision cleanup this branch configures and calls, and re-vendors. Temporary: to be replaced by a regular reva bump once opencloud-eu/reva#895 is merged.
|
Thanks, both fixed, amended into the commits they belong to:
|
eba5978 to
60d1d78
Compare
Points github.com/opencloud-eu/reva/v2 at the head of opencloud-eu/reva#895 in its fork (pbleser-oc/reva 60d1d7896), which adds the revision cleanup this branch configures and calls, and re-vendors. Temporary: to be replaced by a regular reva bump once opencloud-eu/reva#895 is merged.
|
Issues and PRs connected to this one, grouped by how they relate to it: Merge order
Independent, in any order: #899, Follow-ups of this PR
Overlapping uploadsFound while checking how the cleanup copes with a file that gets a new upload while an older one is still in postprocessing:
posix
|
UnixMapper.ScopeUserByIds locks the goroutine to its OS thread before it switches the fsuid and the fsgid, as they belong to the thread. The function it returns restores them and unlocks the thread again. On an error, though, it returned without that function and without unlocking: the goroutine stayed locked to its thread for good, and a fsuid it had already switched before the fsgid failed was not restored. For a short-lived goroutine of a request, Go discards the locked thread when the goroutine ends. Long-lived goroutines would stay pinned to their thread after a single failure, with one more lock nested for every further one. The background workers of the revision cleanup proposed in opencloud-eu#895 are such goroutines: with use_space_groups, they switch to the group of a space for every file. ScopeUserByIds now restores the fsuid and unlocks the thread on every error path. Tests: the fsuid and fsgid are restored after switching, and unchanged after a failed switch to a group the process is not in (skipped where the switch succeeds, e.g. as root). Whether the thread was unlocked can't be observed from Go, there is no API to query it.
60d1d78 to
e42dd53
Compare
Points github.com/opencloud-eu/reva/v2 at the head of opencloud-eu/reva#895 in its fork (pbleser-oc/reva e42dd538c), which adds the revision cleanup this branch configures and calls, and re-vendors. Temporary: to be replaced by a regular reva bump once opencloud-eu/reva#895 is merged.
|
I added one commit after approval, 2bcbce0 Why: The command only deletes revisions, so the only stale entries are those of deleted revisions. But
All three cases also left a revision of the current content behind, as The fix:
With the fix, the stale-cache restore above returns HTTP 404, the file stays intact, and no revision is left behind. The new tests in This affects any stale metadata cache (e.g. several storage-users instances with the |
Points github.com/opencloud-eu/reva/v2 at the head of opencloud-eu/reva#895 in its fork (pbleser-oc/reva 2bcbce084), which adds the revision cleanup this branch configures and calls, and re-vendors. Temporary: to be replaced by a regular reva bump once opencloud-eu/reva#895 is merged.
A dry run of the revision cleanup doesn't take the node lock, but with posix, it still created lock files: the hybrid metadata backend locks to read the metadata of a node that isn't cached, and creates the lock file (and the folder for it) to do so. The on-demand cleanup runs in a process of its own, with a cache of its own, so it reads, and locked, every file it visited. metadata.WithReadOnly marks a context for reads that must not change anything on disk; metadata.IsReadOnly tells whether a context is one. Under it, the backends that lock to read (the hybrid backend in All and Reload, and the xattrs backend in its locked retry of a failed listing) lock the lock file of a node only if it exists, and read without a lock otherwise. A read without a lock can see a write to the node halfway through, which is acceptable for the decisions of a dry run, which are a snapshot anyway, but never for the server: only the dry run uses it. What the hybrid backend read without a lock isn't cached, as it could replace what a writer cached meanwhile in a cache shared with the server. Writes still lock, and create lock files, as before. A dry run (Cleaner.DryRun, and the on-demand cleanup of decomposedfs and posix, including the resolution of a path on disk and the reads of the background workers, whose context doesn't carry the marker of the request) reads under it. The messagepack backend of decomposed and decomposeds3 doesn't lock to read, so there, not taking the node lock was enough already. Tests: the hybrid backend, and the locked retry of the xattrs backend (for a missing file, whose attributes can't be listed), read without creating the lock file under WithReadOnly, still create it otherwise, and still wait for a lock that is held when the lock file exists; a dry run of the on-demand cleanup with posix leaves no lock files, also in the background with no file metadata cache, where the workers read every node from disk; a read without a lock isn't cached, one under the lock is. They fail without the change. Assisted-by: Claude Code:claude-opus-5-5
…s an upload The upload coordinator now tells drivers that implement the new optional storage.UploadFinishedHandler interface when an upload has finished: committed right away, synchronously, or after its postprocessing. Rolled back uploads never get there. Decomposedfs uses it to apply the revision cleanup strategy when the upload replaced existing content, instead of triggering it at the end of PrepareUpload and when MarkProcessing clears the processing mark. The latter also fired after a rollback and for uploads that created a new file, so a bulk upload of new files filled the cleanup queue with nodes that have no revisions at all. It also removes the unlocking before the trigger in MarkProcessing. CommitUpload keeps its own trigger for an older upload that writes into the revision a newer upload kept for it: only then does that revision become a version, which the versionCreated of the older upload doesn't tell. The middleware and the posix driver pass the call on to the wrapped driver. Assisted-by: Claude Code:claude-opus-5-5
…eanup request RestoreRevision protected the revision of the content it replaced only by passing its key along with the request for the cleanup. That protection was lost whenever the request was: when a full queue dropped it, after the timeout of a blocked caller, at a shutdown, for a cleanup by the other instance of the driver in the same process (the storage provider and the data provider each create one), and for a cleanup on demand in a process of its own. It also lost a race: a worker that had taken the request of an earlier upload before the restore listed the new revision without its key, and a strategy deleting by age removed it right away, as the revision is named after the mtime of the content it holds. RestoreRevision now marks that revision with node.KeepAfterRestoreAttr while it still holds the node lock. The value is the blob id of the restored content: every cleanup keeps a marked revision as long as the file still has that blob id. The next upload or restore, or a change on disk with posix, gives the file a new blob id; from then on the revision is a version like any other, and the next cleanup that isn't a dry run removes the mark. The revisions to keep are gone from the Service, its requests and the Cleaner, which now only read the marks. Assisted-by: Claude Code:claude-opus-5-5
… instances A process may set up the same storage more than once: the storage provider and the data provider each create an instance of the storage driver. Each instance got a revision cleanup Service of its own, so a storage ran twice the configured workers, the gauges added up, and the de-duplication of the requests per node didn't work across the two: a node could be queued and cleaned up by both at the same time. NewServiceFromOptions now returns one Service per storage root in a process. The first instance creates it, with its lookup and revision store, the others reuse it. Each instance shuts it down once, and only the last Shutdown stops the workers. Instances that disagree on the strategy or the background settings are rejected at startup, as the storage would otherwise be cleaned up with the settings of whichever came first. Assisted-by: Claude Code:claude-opus-5-5
…in Decomposedfs The trees of decomposedfs and posix checked the permissions in ListRevisions and DownloadRevision themselves, while RestoreRevision and DeleteRevision check them in Decomposedfs. That is why the revision cleanup, which lists revisions on behalf of the system, needed a ListRevisionsUnchecked twin in both trees. Decomposedfs.ListRevisions and DownloadRevision now check the permissions, like the other revision operations, and Tree.ListRevisions and Tree.DownloadRevision check none: Tree.ListRevisions takes the node and replaces ListRevisionsUnchecked, and Tree.DownloadRevision takes the node and the permissions of the user, for the resource info. This also removes the duplicated check from the two trees. Assisted-by: Claude Code:claude-opus-5-5
… node With posix and use_space_groups, a background worker switches to the group of the space before it reads the node, and the Cleaner then switched again: two stats of the root of the space and two pairs of system calls per node. scopeToSpace now records in the context the space the goroutine switched to, and doesn't switch again for the same space. The worker and the Cleaner run in the same goroutine; a request handed to a worker gets a context of its own, so the record never reaches another goroutine. Assisted-by: Claude Code:claude-opus-5-5
…ports them The background cleanup has no one to report to and throws its Result away, but it still built a RevisionResult for every revision of the file, with the reason of the strategy for each, on every upload. The Service now only asks the Cleaner for them when it reports its results, i.e. in an on-demand run. Cleaner.Cleanup and DryRun still return them. Assisted-by: Claude Code:claude-opus-5-5
RestoreRevision releases the node lock before it triggers the revision cleanup, or on any return before that. sync.OnceValue makes sure it is released only once, instead of a hand-written flag. Assisted-by: Claude Code:claude-opus-5-5
2aeb7ff to
a37f627
Compare
|
@butonic thanks for the thorough review. I went through all of it; the branch is rebased onto main (now
The PR description is updated. |
Points github.com/opencloud-eu/reva/v3 at the head of opencloud-eu/reva#895 in its fork (pbleser-oc/reva a37f627e2), which adds the revision cleanup this branch configures and calls, and re-vendors. Temporary: to be replaced by a regular reva bump once opencloud-eu/reva#895 is merged. Assisted-by: Claude Code:claude-opus-5-5
|
I would like to argue for one change before this is merged. The cleanup currently decides what to delete from timestamps the client chooses.
I ran the PR's strategies against a few revision sets to see what that allows:
We agreed that writers can erase history in some configurations and that the docs will say so. This goes further. It affects every configuration, including the ones meant to protect versions. It can remove one specific version. The effect also outlasts the writer's access. The future-dated revisions stay in place, so the file keeps losing every new version after the share is revoked. Public links with edit rights go through the same I propose recording when a revision was created and letting the cleanup use only that time.
|
The cleanup took the time of a revision from its name, the modification
time of the content it holds, which whoever writes the file can choose,
e.g. with X-OC-Mtime. A revision dated just after an existing one pushed
that one out of its slot of "auto", and revisions dated years ahead took
the places of a number of revisions to keep, so that every new version
was deleted, also after the writer lost access to the file.
CreateRevision (decomposed and posix) and the posix assimilation now
record the time of the server when they create a revision, in
node.RevisionCreatedAttr ("user.oc.revision.created"), with
node.SetRevisionCreated, which node.RevisionCreated reads it back with:
the two decide how the time is stored. The cleanup orders
the revisions and measures their age by it. The names of the revisions,
the versions listing and X-OC-Mtime stay as they are.
revisions.Revision.LastModificationTime is renamed to CreationTime
accordingly.
Revisions without the attribute, created before it was introduced, get
an estimate of when they were replaced: the content time of the next
newer revision, or the mtime of the file for the newest one, capped at
the current time.
"auto" now keeps the oldest revision of each slot instead of the newest:
with creation times, the oldest holds the content the file had when the
slot began, while keeping the newest would drop a version that was
current for months as soon as the file is saved twice within a slot.
A duration like "30d" now counts from when a version was replaced rather
than from when its content was written, which is the question of
opencloud-eu/opencloud#3735.
Assisted-by: Claude Code:claude-opus-5-5
Points the temporary replace at the head of opencloud-eu/reva#895, whose last commit makes the revision cleanup go by the time a revision was created, recorded by the server, instead of the modification time of its content, which clients choose with X-OC-Mtime. "auto" keeps the oldest revision of each slot. - The storage-users README explains the new age of a revision. - The acceptance scenario outline that checked the age as the time the content was written is replaced by two scenarios: versions whose content is dated 60 and 50 days ago are kept by "30d", and a version with content dated 10 years ahead doesn't push out the newest one under "1". Assisted-by: Claude Code:claude-opus-5-5
|
@aduffeck thanks, that's a good catch, and I agree with the reasoning, including keeping the oldest revision per slot. I've implemented it as a separate commit on top, 39a0177, so that it can still be dropped or moved to a follow-up:
A test now has a revision named a hundred years ahead but created 200 days ago: Since it also changes what |
|
For the record, we decided to go with the recommendation of @aduffeck here, and implement the revision creation time change as well. |
opencloud-eu/reva#895 (the revision cleanup) was merged into reva main with 5a237e94c, so the temporary replace of its fork is no longer needed. Along with it comes the other reva change merged since 37496dc6a, opencloud-eu/reva#1027 (OCM invite and provider fixes): an invalid invitation token is now rejected with the actual reason, so the acceptance test of an expired token expects "token not valid" instead of "token has expired", as in opencloud-eu#4065. Assisted-by: Claude Code:claude-opus-5-5
Follows opencloud-eu/reva#895, which makes the revision cleanup go by the time a revision was created, recorded by the server, instead of the modification time of its content, which clients choose with X-OC-Mtime. "auto" keeps the oldest revision of each slot (opencloud-eu#3735). - The storage-users README explains the new age of a revision. - The acceptance scenario outline that checked the age as the time the content was written is replaced by two scenarios: versions whose content is dated 60 and 50 days ago are kept by "30d", and a version with content dated 10 years ahead doesn't push out the newest one under "1". Assisted-by: Claude Code:claude-opus-5-5
We bump reva to 0093d72f4c9d, the merge of opencloud-eu/reva#1035 on reva main. This brings in the OCM unshare and permission change notifications, the ocm core share events and the fixes to the permissions of OCM shares, on top of the invite and provider fixes already on reva main. It also pulls in the revision cleanup from opencloud-eu/reva#895. Its strategy defaults to empty, which keeps all revisions, so nothing changes until we wire up the option. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
Follows opencloud-eu/reva#895, which makes the revision cleanup go by the time a revision was created, recorded by the server, instead of the modification time of its content, which clients choose with X-OC-Mtime. "auto" keeps the oldest revision of each slot (opencloud-eu#3735). - The storage-users README explains the new age of a revision. - The acceptance scenario outline that checked the age as the time the content was written is replaced by two scenarios: versions whose content is dated 60 and 50 days ago are kept by "30d", and a version with content dated 10 years ahead doesn't push out the newest one under "1". Assisted-by: Claude Code:claude-opus-5-5
Follows opencloud-eu/reva#895, which makes the revision cleanup go by the time a revision was created, recorded by the server, instead of the modification time of its content, which clients choose with X-OC-Mtime. "auto" keeps the oldest revision of each slot (opencloud-eu#3735). - The storage-users README explains the new age of a revision. - The acceptance scenario outline that checked the age as the time the content was written is replaced by two scenarios: versions whose content is dated 60 and 50 days ago are kept by "30d", and a version with content dated 10 years ahead doesn't push out the newest one under "1". Assisted-by: Claude Code:claude-opus-5-5
Implements the reva side of opencloud-eu/opencloud#1419: old revisions (versions) are deleted according to a configurable cleanup strategy, for the
decomposed,decomposeds3andposixdrivers.The age of a revision is the time it was created, i.e. when its content was replaced, by the clock of the server, as agreed in the team on @aduffeck's proposal.
Fixes opencloud-eu/opencloud#3735
The OpenCloud side (configuration and the
opencloud storage-users revisions cleanupcommand) follows in a separate PR in opencloud-eu/opencloud, once this one is merged.What it does
Cleanup whenever a file gets a new revision
Triggers:
pkg/upload) calls the new optionalstorage.UploadFinishedHandlerof the driver fromfinished(), which every successful upload passes through, whether it was committed right away or after its postprocessing. Rolled back uploads never get there. Decomposedfs cleans up if the upload replaced existing content (versionCreated), so uploads of new files queue nothing;CommitUploadtriggers the cleanup once the locks are released;enable_fs_revisions, after a change on disk created a revision, once the new content has been copied to.CURRENT.Files with an upload still in postprocessing are skipped.
Revisions that are not versions are left alone and not counted: a revision that keeps the processing mark of an older upload (the older upload writes its content into it once its postprocessing is done), and revisions the coordinator keeps only to roll back an upload (
node.KeptForRollback). They are reported as protected, with the reason. The blob the file itself uses is never deleted with a revision.Strategies
auto(keeps one revision per time slot, with longer slots for older revisions),10),30d; with an uppercase unit,1Dor1W, counting from midnight),and combinations:
14d, auto,auto, 90d,5, 30d,7d, auto, 90d.Empty or
disabled(the default) keeps everything. An invalid strategy makes the driver fail at startup.Restores
RestoreRevisionmarks the revision it creates of the content it replaced withnode.KeepAfterRestoreAttr, while it still holds the node lock. The value is the blob id of the restored content, and every cleanup keeps the revision as long as the file has that blob id: also a cleanup in the other driver instance of the process, one on demand in a process of its own, and one after a request was dropped from a full queue. The next upload or restore, or a change on disk with posix, gives the file a new blob id: from then on the revision is a version like any other, and the next cleanup that isn't a dry run removes the mark. Until then, the strategy doesn't apply to that one revision, also not an age limit like30d.In the background by default
Shutdown. Instances with different cleanup settings for the same storage fail at startup.The worker count, the queue size and what happens when the queue is full are configurable. By default, a cleanup that finds the queue full is skipped (
drop, logged with the file's location on disk), and happens with the file's next revision, so that a write never waits for the cleanup. Withblock, the write waits for room, but at most for a timeout (5s by default, 0 for as long as it takes), after which the cleanup is skipped as withdrop: blocking without a bound would, under sustained load, slow down every write, e.g. the consumer of the postprocessing events.A file whose space was disabled (moved to the trash) between being queued and being cleaned up is skipped, and its files are left alone.
Decomposedfs.Shutdownstops the workers.A queued cleanup doesn't keep the request that triggered it alive: its context only carries the logger, with the request's fields and id, and it gets a trace of its own, a span
revision cleanuplinked to the request's span.Node Lock
The node lock is held briefly: the blobs of deleted revisions are deleted after the lock is released, as with decomposeds3 every blob is a request. A revision only counts as deleted once its blob is; otherwise it is reported and counted as a failure.
Posix with use_space_groups
The cleanup switches to the group of the space before it touches its files (
revisioncleanup.SpaceScoper), as the middleware does for user requests: in background workers already to read the file, and in on-demand runs already to find the file or folder to start from, as well as to walk the folders. A path on disk is resolved through the id cache only, which needs no group.On Demand
Decomposedfs.CleanupRevisionsUnchecked(therevisioncleanup.OnDemandinterface) cleans up all spaces, given spaces, or a file or folder within a space.With posix, it can also clean up a file or folder given by its path on disk.
It supports
metadata.WithReadOnly, so that no lock files are created (see below); its decisions are therefore a snapshot,It reports a
Resultfor every file.It needs no user in the context and checks no permissions, as it is meant for command line tools.
Such a tool runs in a process of its own next to the server, and with a metadata cache local to the process, like the default
memorycache, its cache doesn't see what the server changes. The cleanup of a file therefore reads the file's status and blob id from storage, under the file's lock (Backend.Reload, see below): it sees an upload the server started after the walk read the file, and keeps the revision that upload rolls back to should it fail.Prometheus Metrics
reva_revision_cleanup_*: deleted revisions and bytes, failed deletions, queue length, capacity and full events, workers.A Reason for Every Decision
Logged at debug level for every deleted revision, e.g.
deleted by "auto" (last hour): its slot of 1 minute starting … already keeps a newer revision.Configuration
New decomposedfs options, which posix inherits:
revisions_cleanup_strategy""(disabled)revisions_cleanup_asynctruerevisions_cleanup_async_workers0(half the CPUs, at least 2)revisions_cleanup_async_queue_size0(64 per worker)revisions_cleanup_async_queue_fulldroprevisions_cleanup_async_queue_full_timeout5s(forblock;0waits as long as it takes)Changes to shared code
node.KeptForRollback: the coordinator's check for revisions kept only for a rollback (Decomposedfs.keptForRollback, with its two attributes) moved to packagenode, asnode.KeptForRollback,node.UploadSnapshotAttrandnode.PurgeOnRestoreAttr, so that the cleanup uses the same definition. A separate commit, no functional change.Uncheckedsuffix, so that they aren't used by mistake where permissions must be checked. For that, a separate commit renames the existingNode.DeleteRevisiontoNode.DeleteRevisionUnchecked, asDecomposedfs.DeleteRevision, of the same name, checks permissions. The functions of the cleanup that keep their names, e.g.Cleaner.Cleanup, say in their doc comment that they check no permissions.Decomposedfs:Decomposedfs.ListRevisionsandDownloadRevisioncheck the permissions, likeRestoreRevisionandDeleteRevisionalready did, instead of the two trees.node.Tree.ListRevisionsnow takes the node and checks none, so that the cleanup can use it, andTree.DownloadRevisiontakes the node and the user's permissions, for the resource info. There is also a newListFolderKnownUncheckedfor the on-demand walk, which, unlikeListFolder, checks no permissions and lists only the children known to the storage: with posix, it skips files created on disk that aren't assimilated yet instead of assimilating them, so that a cleanup, a dry run in particular, changes nothing but the revisions it deletes.revisioncleanup.PurgeRevisionUncheckedvalidates the key (node.ValidateRevisionKey, which rejects keys that would turn into an empty version), then callsNode.DeleteRevisionUncheckedandTree.DeleteBlob.aspects.Aspectshas a new field,RevisionsCleanup. The posix test env passes it on, asposix.Newdoes.storage.UploadFinishedHandler, new: an optional interface of the storage drivers, which the upload coordinator calls fromfinished(). The middleware andposixFSpass it on.CommitUploadkeeps a trigger of its own for an older upload that writes its content into the revision a newer one kept for it, as only then does that revision become a version. It andRestoreRevisiontrigger the cleanup after the node lock is released (a cleanup waiting for room in a full queue must not hold the lock).RestoreRevisionandDownloadRevisionnow check that the revision still exists on disk and return "not found" otherwise. Its metadata may come from a stale cache entry: with the default in-memory metadata cache, a revision deleted by another process, e.g. the OpenCloud command that cleans up on demand, stays in the server's cache. Restoring it reported success on decomposed but pointed the file to the deleted blob. A commit of its own, with tests on decomposed and posix.metadata.Backend.Reload, new: reads all attributes of a node from storage, never from the cache, and updates the cache. The messagepack backend answersGetfrom its cache alone once it holds an entry for the node, even for an attribute the entry lacks, so a separate process can't see a processing mark the server set later. Implemented by the three backends, with the mock regenerated; a commit of its own, with tests that use two backends with caches of their own.metadata.WithReadOnly, new: a context for reads that must not change anything on disk. Under it, the backends that lock to read (the hybrid backend of posix inAllandReload, and the xattrs backend in its locked retry) lock a node's lock file only if it exists, and read without a lock otherwise, instead of creating the lock file. Only the dry run uses it, also in the background workers, whose context doesn't carry the marker of the request: a read without a lock can see a write halfway through. For the same reason, what the hybrid backend read without a lock isn't cached, where it could replace what a writer cached meanwhile in a cache shared with the server. A commit of its own, the last one.RestoreRevisionkeeps the node's lock file. It removed the lock file after releasing the lock, which the metadata backends warn against (Treesize propagation seems to be broken opencloud#1793): whoever waits for the lock then locks the removed file while the next writer locks a new one. The cleanup that runs after a restore, also in the background, is such a waiter. A commit of its own, before the cleanup is wired in.UnixMapper.ScopeUserByIds, which the cleanup calls for every file withuse_space_groups, leaves the goroutine locked to its OS thread when it fails. That would pin a background worker to its thread for good; the fix is in its own PR, fix: unlock the OS thread when ScopeUserByIds fails #899.spaceidindex.Index.Indexeslists the indexes, so that "all spaces" covers every space type.posixFSforwardsCleanupRevisionsUncheckedandHandleUploadFinished.pkg/storage/revisions, which only plans what to keep and what to delete and touches no storage. It rejectsX1, X2pairs of the same kind, with the equivalent single value in the error. A number of revisions is counted in absolute terms. Only days and weeks can count from midnight, with the uppercase unitsDandW.Documentation
pkg/storage/pkg/decomposedfs/revisioncleanup/README.md, for operators: options, strategies with examples, how the age of a revision is measured, when the cleanup runs, metrics with PromQL examples, logging.pkg/storage/pkg/decomposedfs/README.md, new: how the three drivers are built on decomposedfs, with diagrams, including the steps of an upload the upload coordinator calls. It documents the code as it is onmain, so it has a commit of its own, the first one, together with package comments fordecomposedfs,decomposed,decomposeds3andposixthat point to it. The feature commits then add the few lines about the revision cleanup.Review notes
Decomposedfs, and three small ones. Before them: the documentation of the existing drivers, theNode.DeleteRevisionrename and the move ofkeptForRollbackfirst, then one per step of the feature, with two fixes of shared code where they are needed (the lock file ofRestoreRevision,Backend.Reload), and, at the end, a fix of the posix test environment (it ignored the configured file metadata cache, so no posix test could run without one) andmetadata.WithReadOnly. The first four steps build the cleanup bottom up: the strategies, listing and deleting revisions, the cleaner that applies a strategy to a node, and only then the wiring that calls it. Each commit builds and passes its tests. Reviewing commit by commit is probably easier than the whole diff (72 files, ~10100 lines, more than half of them tests).disabled, while the issue namesautoas the default. Switching the cleanup on deletes versions, so I kept it off in reva; whether OpenCloud should default toautois still to be decided.CommitUploadwould discard that content if the revision were gone. The cleanup therefore never deletes, nor counts, such a revision. Once the older upload has written its content into it, the revision is a version, andCommitUploadruns the cleanup for it (tested end to end through the coordinator).coordinator.go,commit_upload.go, @butonic): the call ofUploadFinishedHandlerinfinished(), the trigger inCommitUpload, and the move ofkeptForRollback. The recovery of an interrupted synchronous upload (recover.go) triggers nothing: it is rare, and the file's next revision triggers the cleanup.CreateRevision(decomposed and posix) and the posix assimilation record it with the clock of the server, in the new attributeuser.oc.revision.created(node.SetRevisionCreated,node.RevisionCreated), and the cleanup orders the revisions and measures their age by it. The content mtime in the name of a revision, which clients choose withX-OC-Mtime, would let anyone who can write a file push other revisions out of their slots ofauto, or, dated years ahead, out of a number of revisions to keep, and it made30ddelete the previous content of a file unchanged for two months as soon as it was edited.autokeeps the oldest revision of each slot, which holds the content the file had when the slot began. Revisions created before get an estimate of when they were replaced: the content mtime of the next newer revision, or the mtime of the file for the newest one, never later than now. The names of the revisions, the version list andX-OC-Mtimestay as they are, so the version list still shows the content mtime (Revision cleanup: should the age of a revision be the age of its content, or the time it was replaced? opencloud#3735).Follow-ups
Decomposedfs.deleteRevisionFileto userevisioncleanup.PurgeRevisionUnchecked, to get the key validation on that path too.Tests
Unit tests for the strategies and the parser (including the reasons), the Service (de-duplication, queue full policies, shutdown,
Wait, the context of a queued cleanup), the metrics, and the cleanup on real decomposedfs and posix trees: uploads through the upload coordinator (finished right away, after postprocessing that succeeds or fails, and an empty file uploaded while an older upload is in postprocessing, whose revision is cleaned up once the older upload is done), the coordinator telling the driver that an upload finished (with and without a new version, and not for a rolled back upload), restores, the mark of a restore (kept by every cleanup, also by another cleaner, until the file gets other content; stale marks removed, but not in a dry run), one Service per storage in a process, changes on disk, revisions that are not versions, a revision sharing the blob of the file, blobs deleted only after the node lock is released, on-demand runs including dry runs, timeouts (also during the lookup of a space), paths on disk and spaces given twice, an upload the server started after an on-demand run had read the file,Backend.Reloadon all three backends, dry runs that create no lock files (also with posix, and in background workers that read every node from disk), the lock file kept by a restore, and restoring and downloading a revision deleted by another process, on decomposed and posix. The tests of new code paths were checked to fail without the change they test. Every commit builds and passesgo vet;make testandmake lintpass on a37f627; on the last commit, 39a0177, the tests ofpkg/storage/...andpkg/upload/...pass with-race. The integration tests (tests/integration) fail locally in the same way with and without this PR: 8 public-link specs fail onmaintoo, and the whole suite runs into its 15 minute timeout. End to end, the OpenCloud PR adds Behat acceptance tests for the command and for the configured strategy, also with the default cleanup in background workers. reva's own acceptance runs (OpenCloud'scoreApiVersionssuite on decomposed, decomposeds3 and posix) run with the cleanup off, its default, so they show that versions behave as before; the cleanup itself is tested end to end only in the OpenCloud PR.Not tested: the actual switch to the group of a space with
use_space_groups. The tests check that the cleanup asks for it (with a stand-in), also to read a file in a background worker and to find where an on-demand run starts, and that the posix tree puts the group of the space root into the context, but switching the fsgid needsCAP_SETGID, and as root file permissions don't apply. The switch itself is the existingUnixMapper.ScopeUserByIds, which the middleware and the assimilation use too; what's new is only that the cleanup calls it. A check on a server withuse_space_groupsis still to be done.