Skip to content

Commit 8218f64

Browse files
refactor(gc): rename orphaned_paths -> orphaned_schema_paths for full symmetry
Completes the hash/schema stat-name parallelism: the two orphan-path lists are now orphaned_hash_paths and orphaned_schema_paths (was the unqualified orphaned_paths). Keys + internal variable renamed; no behavior change. GC 39/39.
1 parent f6bcccb commit 8218f64

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

src/datajoint/gc.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def collect(self, dry_run: bool = True, verbose: bool = False) -> dict[str, Any]
323323
(NOT bare hashes — passed as-is to the deleter)
324324
- schema_paths_referenced / schema_paths_stored / schema_paths_orphaned
325325
/ schema_paths_orphaned_bytes
326-
- orphaned_paths: orphaned schema files as full relative store paths
326+
- orphaned_schema_paths: orphaned schema files as full relative store paths
327327
- hash_paths_deleted / schema_paths_deleted / deleted / bytes_freed (0 when
328328
dry_run) / errors / dry_run
329329
"""
@@ -342,7 +342,7 @@ def collect(self, dry_run: bool = True, verbose: bool = False) -> dict[str, Any]
342342
orphaned_hash_paths = sorted(set(hash_paths_stored.keys()) - hash_paths_referenced)
343343
# Coverage, not exact set difference: a referenced path may be a
344344
# directory-valued object (many files + a manifest sidecar).
345-
orphaned_paths = sorted(p for p in schema_paths_stored if not _is_covered(p, schema_paths_referenced))
345+
orphaned_schema_paths = sorted(p for p in schema_paths_stored if not _is_covered(p, schema_paths_referenced))
346346

347347
hash_paths_deleted = 0
348348
schema_paths_deleted = 0
@@ -363,7 +363,7 @@ def collect(self, dry_run: bool = True, verbose: bool = False) -> dict[str, Any]
363363
errors += 1
364364
logger.warning(f"Failed to delete {path}: {e}")
365365

366-
for path in orphaned_paths:
366+
for path in orphaned_schema_paths:
367367
try:
368368
if self.delete_schema_path(path):
369369
schema_paths_deleted += 1
@@ -384,9 +384,9 @@ def collect(self, dry_run: bool = True, verbose: bool = False) -> dict[str, Any]
384384
# Schema-addressed storage stats
385385
"schema_paths_referenced": len(schema_paths_referenced),
386386
"schema_paths_stored": len(schema_paths_stored),
387-
"schema_paths_orphaned": len(orphaned_paths),
388-
"schema_paths_orphaned_bytes": sum(schema_paths_stored.get(p, 0) for p in orphaned_paths),
389-
"orphaned_paths": orphaned_paths,
387+
"schema_paths_orphaned": len(orphaned_schema_paths),
388+
"schema_paths_orphaned_bytes": sum(schema_paths_stored.get(p, 0) for p in orphaned_schema_paths),
389+
"orphaned_schema_paths": orphaned_schema_paths,
390390
# Deletion outcome (all zero when dry_run)
391391
"hash_paths_deleted": hash_paths_deleted,
392392
"schema_paths_deleted": schema_paths_deleted,

tests/integration/test_gc.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def test_dry_run_reports_stats_and_deletes_nothing(self):
230230
# full report is present
231231
assert stats["hash_paths_orphaned"] == 1 and stats["orphaned_hash_paths"] == ["_hash/s/path3"]
232232
assert stats["hash_paths_orphaned_bytes"] == 200
233-
assert stats["schema_paths_orphaned"] == 1 and stats["orphaned_paths"] == ["s/t/pk2/f"]
233+
assert stats["schema_paths_orphaned"] == 1 and stats["orphaned_schema_paths"] == ["s/t/pk2/f"]
234234
assert stats["schema_paths_orphaned_bytes"] == 300
235235
# no combined totals
236236
for k in ("referenced", "stored", "orphaned", "orphaned_bytes"):
@@ -374,7 +374,7 @@ def test_custom_codec_reference_not_orphaned(self, schema_custom):
374374
live_path = next(iter(refs))
375375

376376
stats = collector.collect()
377-
assert live_path not in stats["orphaned_paths"], f"live custom-codec file wrongly flagged orphan: {live_path}"
377+
assert live_path not in stats["orphaned_schema_paths"], f"live custom-codec file wrongly flagged orphan: {live_path}"
378378

379379
def test_custom_codec_survives_collect(self, schema_custom):
380380
"""#1469 end-to-end data-loss guard: collect() must delete only the
@@ -432,7 +432,7 @@ def _make_store_dir(tmp_path, name, n_chunks=3):
432432

433433
def test_live_directory_object_not_orphaned(self, schema_dirobj, tmp_path):
434434
"""A live folder object's chunk files and manifest must be covered by
435-
its referenced prefix — none may appear in orphaned_paths."""
435+
its referenced prefix — none may appear in orphaned_schema_paths."""
436436
GcObjectTest.insert1({"rid": 1, "results": str(self._make_store_dir(tmp_path, "live.zarr"))})
437437

438438
collector = _gc(schema_dirobj)
@@ -446,7 +446,9 @@ def test_live_directory_object_not_orphaned(self, schema_dirobj, tmp_path):
446446
assert f"{ref}.manifest.json" in stored, "manifest sidecar must be listed (it is reclaimable state)"
447447

448448
stats = collector.collect()
449-
flagged = [p for p in stats["orphaned_paths"] if p == ref or p.startswith(ref + "/") or p == f"{ref}.manifest.json"]
449+
flagged = [
450+
p for p in stats["orphaned_schema_paths"] if p == ref or p.startswith(ref + "/") or p == f"{ref}.manifest.json"
451+
]
450452
assert not flagged, f"live directory object misclassified as orphaned: {flagged}"
451453

452454
def test_orphaned_directory_object_fully_reclaimed(self, schema_dirobj, tmp_path):
@@ -609,7 +611,7 @@ def test_custom_sections_written_scanned_and_collected(self, schema_prefixed):
609611
stats = collector.collect()
610612
assert stats["hash_paths_referenced"] >= 1
611613
assert not (hash_refs & set(stats["orphaned_hash_paths"]))
612-
assert not (obj_refs & set(stats["orphaned_paths"]))
614+
assert not (obj_refs & set(stats["orphaned_schema_paths"]))
613615

614616
# And reclamation works within the configured sections
615617
(GcObjectTest & {"rid": 2}).delete(prompt=False)
@@ -661,7 +663,7 @@ def test_live_hash_object_survives_prefix_change(self, schema_pfx):
661663

662664
stats = collector.collect()
663665
assert hash_ref not in set(
664-
stats["orphaned_paths"]
666+
stats["orphaned_schema_paths"]
665667
), "live hash object outside the current hash section must not be a schema orphan"
666668
assert hash_ref not in set(stats["orphaned_hash_paths"])
667669

@@ -736,7 +738,7 @@ def test_scan_one_schema_ignores_the_other(self, two_schemas):
736738
stats = collector.collect()
737739
# b's live objects are outside a's subtree → not counted, not orphaned
738740
assert stats["hash_paths_orphaned"] == 0 and stats["schema_paths_orphaned"] == 0
739-
assert not any(b.database in p for p in stats["orphaned_paths"] + stats["orphaned_hash_paths"])
741+
assert not any(b.database in p for p in stats["orphaned_schema_paths"] + stats["orphaned_hash_paths"])
740742

741743
def test_collect_one_schema_never_touches_the_other(self, two_schemas):
742744
a, b, b_blob, b_obj = two_schemas

0 commit comments

Comments
 (0)