Intention
The original rationale for developing the bookkeeping system was to create packages of delivery data that can be saved on the NAS with backup as well as keep track of which data and files are still necessary and which are not. This concept has been expanded into actual workflow management, however, data tracking is still at the centre. Thus, one important task is to remove data that is not necessary any more to free up resources. This duty is performed by the cleaner.py based on the graph data and information deposited there by the workflow modules.
Cleanup preparations done by other modules
Certain modules that are at key steps of the workflow put information into the graph that is later used by the cleaner to identify no longer required data:
- Any module that creates packages or data locations (data package creators, startup modules, but others as well) registers those with the bookkeeping system
- During startup module task return, it is decided whether earlier workflow executions are stopped and processing restarts from the metadata. In this case, the earlier processing files are marked as outdated and deprecated.
- After archivematica ingest and integrity check by the DIP export module, unpacked deliveries, deliveries within delivery packages as well as deliveries within NAS packages are marked as deprecated
Final cleanup by the bookkeeping Cleaner
The Cleaner does not decide from file names, ages, sizes, or contents. It uses the bookkeeping graph as the source of truth. A physical path is eligible only when the corresponding RDF entity has already been marked owl:deprecated true and still has the initial "not deleted" value for schema:dateDeleted. Newly registered entities use the Unix epoch for this value; the cleanup queries accept values before 1970-01-02T00:00:00+00:00.
The cleaner() flow reads every configured source and processes the following entity types in this fixed order:
wdmvoc:NASDataPackagewdmvoc:DeliveryDataPackagewdmvoc:UnpackedDeliverylocationswdmvoc:NASProcessingFileslocations
How packages become eligible
Before selecting packages, PackageCleaner runs mark_packages_deprecated() for the current package type. A package is changed to owl:deprecated true when all of the following graph conditions hold:
- it is a package of the requested type;
- it has the initial
schema:dateDeletedvalue; - at least one
dcterms:hasPartcomponent is markedowl:deprecated true; and - none of its components is explicitly marked
owl:deprecated false.
Consequently, the query treats a component without any owl:deprecated value as non-blocking. The intended normal state is that all registered components have an explicit deprecation value.
The subsequent selection query requires the package to have its requested RDF type, owl:deprecated true, a wdmvoc:packageLocation, and the initial schema:dateDeleted value. Thus, a package is removed only after the workflow has made its components obsolete; marking one file inside the archive as deleted is not itself part of this decision.
How locations become eligible
For locations, the selection query requires all of the following:
- the requested RDF type;
owl:deprecated true;- a
wdmvoc:locationBaseAbsvalue, which supplies the path to process; and - the initial
schema:dateDeletedvalue.
The normal workflow prepares these marks beforehand. In particular, startup processing marks superseded wdmvoc:NASProcessingFiles locations as deprecated, and a successful Archivematica DIP export/integrity check marks wdmvoc:UnpackedDelivery, wdmvoc:DeliveryDataPackageComponent, and wdmvoc:NASDataPackageComponent locations as deprecated.
What happens to each selected entity
Candidates are requested in batches of 20. The Cleaner repeats the query until a batch contains fewer than 20 entries. For each entry, the operations occur in this order:
- The relevant RDF subgraph is serialized as Turtle. Package serializations include the package, its components, files, checksums, publication links, and derivation links. Location serializations also include associated activity information.
- The Turtle is written into a daily ZIP archive below
Bookkeeping/ttl_archives/packages/cleaner/<source>/orBookkeeping/ttl_archives/locations/cleaner/<source>/under the configured data root. Each entity gets a.ttlmember named from its UUID. - Mutable details are removed from the live graph and
schema:dateDeletedis changed from the epoch sentinel to the current time. For locations this removes routing, path, suspension, non-LTA flags, contained-file details, and file-use statements. For packages it removes the package path and identifier as well as mutable details of its components. The entity nodes and important relationships remain;wdmvoc:InLTAandwdmvoc:LTAVerifiedflags are preserved. - The physical operation is chosen from the recorded path. A string beginning exactly with
sftp://is passed to the SFTP deleter; every other package/location path is handled as a mounted/local path.wdmvoc:NASProcessingFilesuses the dedicated folder handler instead.
Serialization and graph pruning therefore happen before physical removal. These operations are not wrapped in one transaction. If deletion or moving fails, the graph has already received a real deletion timestamp, so the normal selection query will not pick the entity up again. The archive should be consulted and the filesystem state checked when recovering such a failure.
Fake and real cleanup modes
use_fake_deleters defaults to True and changes the physical operation, but not serialization or graph pruning:
| Entity/path | use_fake_deleters=True |
use_fake_deleters=False |
|---|---|---|
| Local package or location file | Confirms that the path exists and logs the unlink that would occur | Deletes the file with Path.unlink() |
| SFTP package or location file | Validates the sftp:// URL and logs the deletion that would occur |
Verifies that the URL belongs to the configured connector and removes the remote file |
wdmvoc:NASProcessingFiles folder |
Calls nas_folder_mover() to relocate the folder to the non-backed-up Automatische_Prozessierung/Testsicherung area and intends to leave content_moved.txt at the old location |
Removes and recreates the folder, then leaves content_removed.txt in the empty folder |
The processing-folder behavior in fake mode is deliberately not a no-op: it uses a mover rather than the logging-only folder_fake_deleter. Operators should therefore treat even a default Cleaner run as capable of changing processing folders. Also note that the present nas_folder_mover() implementation constructs a destination directory but calls rename() with that directory itself and then writes a tombstone at the old path; this behavior should be verified on the target filesystem before relying on fake mode for recovery.
Once an entity has received its real deletion timestamp, it no longer matches later batches or later Cleaner runs. Processing then continues with the next entity type and, finally, the next configured source.