From 5a500cddf85853e0d511750ffe74154d7509b755 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Thu, 18 Jul 2024 22:14:00 +0200 Subject: [PATCH] rename NewCache -> AdHocWithFilesCache --- docs/usage/general/environment.rst.inc | 2 +- src/borg/archive.py | 2 +- src/borg/archiver/create_cmd.py | 2 +- src/borg/cache.py | 20 ++++++++++---------- src/borg/helpers/parseformat.py | 4 ++-- src/borg/testsuite/archiver/__init__.py | 2 +- src/borg/testsuite/archiver/checks.py | 8 ++++++-- src/borg/testsuite/archiver/create_cmd.py | 6 ++++-- src/borg/testsuite/archiver/debug_cmds.py | 2 +- src/borg/testsuite/conftest.py | 2 +- 10 files changed, 28 insertions(+), 22 deletions(-) diff --git a/docs/usage/general/environment.rst.inc b/docs/usage/general/environment.rst.inc index 917db5c7c..cd32e09b9 100644 --- a/docs/usage/general/environment.rst.inc +++ b/docs/usage/general/environment.rst.inc @@ -93,7 +93,7 @@ General: - ``adhoc``: builds a non-persistent chunks cache by querying the repo. Chunks cache contents are somewhat sloppy for already existing chunks, concerning their refcount ("infinite") and size (0). No files cache (slow, will chunk all input files). DEPRECATED. - - ``newcache``: Like ``adhoc``, but with a persistent files cache. + - ``adhocwithfiles``: Like ``adhoc``, but with a persistent files cache. BORG_SELFTEST This can be used to influence borg's builtin self-tests. The default is to execute the tests at the beginning of each borg command invocation. diff --git a/src/borg/archive.py b/src/borg/archive.py index 13cac5fc5..eda4ec4c6 100644 --- a/src/borg/archive.py +++ b/src/borg/archive.py @@ -2334,7 +2334,7 @@ class ArchiveChecker: logger.info(f"{len(orphaned)} orphaned (unused) objects found.") for chunk_id in orphaned: logger.debug(f"chunk {bin_to_hex(chunk_id)} is orphaned.") - # To support working with AdHocCache or NewCache, we do not set self.error_found = True. + # To support working with AdHocCache or AdHocWithFilesCache, we do not set self.error_found = True. if self.repair and unused: logger.info( "Deleting %d orphaned and %d superseded objects..." % (len(orphaned), len(self.possibly_superseded)) diff --git a/src/borg/archiver/create_cmd.py b/src/borg/archiver/create_cmd.py index 785c7ea8a..40160f641 100644 --- a/src/borg/archiver/create_cmd.py +++ b/src/borg/archiver/create_cmd.py @@ -815,7 +815,7 @@ class CreateMixIn: "--prefer-adhoc-cache", dest="prefer_adhoc_cache", action="store_true", - help="experimental: prefer AdHocCache (w/o files cache) over NewCache (with files cache).", + help="experimental: prefer AdHocCache (w/o files cache) over AdHocWithFilesCache (with files cache).", ) subparser.add_argument( "--stdin-name", diff --git a/src/borg/cache.py b/src/borg/cache.py index 38a6ce215..4836314d4 100644 --- a/src/borg/cache.py +++ b/src/borg/cache.py @@ -368,8 +368,8 @@ class Cache: cache_mode=cache_mode, ) - def newcache(): - return NewCache( + def adhocwithfiles(): + return AdHocWithFilesCache( manifest=manifest, path=path, warn_if_unencrypted=warn_if_unencrypted, @@ -384,7 +384,7 @@ class Cache: impl = os.environ.get("BORG_CACHE_IMPL", None) if impl is not None: - methods = dict(local=local, newcache=newcache, adhoc=adhoc) + methods = dict(local=local, adhocwithfiles=adhocwithfiles, adhoc=adhoc) try: method = methods[impl] except KeyError: @@ -392,13 +392,13 @@ class Cache: return method() if no_cache_sync_forced: - return adhoc() if prefer_adhoc_cache else newcache() + return adhoc() if prefer_adhoc_cache else adhocwithfiles() if not no_cache_sync_permitted: return local() # no cache sync may be permitted, but if the local cache is in sync it'd be stupid to invalidate - # it by needlessly using the AdHocCache or the NewCache. + # it by needlessly using the AdHocCache or the AdHocWithFilesCache. # Check if the local cache exists and is in sync. cache_config = CacheConfig(repository, path, lock_wait) @@ -410,12 +410,12 @@ class Cache: # Local cache is in sync, use it logger.debug("Cache: choosing local cache (in sync)") return local() - if prefer_adhoc_cache: + if prefer_adhoc_cache: # adhoc cache, without files cache logger.debug("Cache: choosing AdHocCache (local cache does not exist or is not in sync)") return adhoc() else: - logger.debug("Cache: choosing NewCache (local cache does not exist or is not in sync)") - return newcache() + logger.debug("Cache: choosing AdHocWithFilesCache (local cache does not exist or is not in sync)") + return adhocwithfiles() class CacheStatsMixin: @@ -675,7 +675,7 @@ class ChunksMixin: "chunk has same id [%r], but different size (stored: %d new: %d)!" % (id, entry.size, size) ) else: - # NewCache / AdHocCache: + # AdHocWithFilesCache / AdHocCache: # Here *size* is used to update the chunk's size information, which will be zero for existing chunks. self.chunks[id] = entry._replace(size=size) return entry.refcount @@ -1162,7 +1162,7 @@ class LocalCache(CacheStatsMixin, FilesCacheMixin, ChunksMixin): self.cache_config.mandatory_features.update(repo_features & my_features) -class NewCache(CacheStatsMixin, FilesCacheMixin, ChunksMixin): +class AdHocWithFilesCache(CacheStatsMixin, FilesCacheMixin, ChunksMixin): """ Like AdHocCache, but with a files cache. """ diff --git a/src/borg/helpers/parseformat.py b/src/borg/helpers/parseformat.py index 7e906547a..c69889b18 100644 --- a/src/borg/helpers/parseformat.py +++ b/src/borg/helpers/parseformat.py @@ -1184,13 +1184,13 @@ class BorgJsonEncoder(json.JSONEncoder): from ..repository import Repository from ..remote import RemoteRepository from ..archive import Archive - from ..cache import LocalCache, AdHocCache, NewCache + from ..cache import LocalCache, AdHocCache, AdHocWithFilesCache if isinstance(o, Repository) or isinstance(o, RemoteRepository): return {"id": bin_to_hex(o.id), "location": o._location.canonical_path()} if isinstance(o, Archive): return o.info() - if isinstance(o, (LocalCache, NewCache)): + if isinstance(o, (LocalCache, AdHocWithFilesCache)): return {"path": o.path, "stats": o.stats()} if isinstance(o, AdHocCache): return {"stats": o.stats()} diff --git a/src/borg/testsuite/archiver/__init__.py b/src/borg/testsuite/archiver/__init__.py index abfadf6ce..9d7a5db42 100644 --- a/src/borg/testsuite/archiver/__init__.py +++ b/src/borg/testsuite/archiver/__init__.py @@ -357,7 +357,7 @@ def check_cache(archiver): with Cache(repository, manifest, sync=False) as cache: original_chunks = cache.chunks # the LocalCache implementation has an on-disk chunks cache, - # but NewCache and AdHocCache don't have persistent chunks cache. + # but AdHocWithFilesCache and AdHocCache don't have persistent chunks cache. persistent = isinstance(cache, LocalCache) Cache.destroy(repository) with Cache(repository, manifest) as cache: diff --git a/src/borg/testsuite/archiver/checks.py b/src/borg/testsuite/archiver/checks.py index 60c87db6f..c095762e6 100644 --- a/src/borg/testsuite/archiver/checks.py +++ b/src/borg/testsuite/archiver/checks.py @@ -204,7 +204,9 @@ def test_unknown_feature_on_create(archivers, request): cmd_raises_unknown_feature(archiver, ["create", "test", "input"]) -@pytest.mark.skipif(os.environ.get("BORG_CACHE_IMPL") in ("newcache", "adhoc"), reason="only works with LocalCache") +@pytest.mark.skipif( + os.environ.get("BORG_CACHE_IMPL") in ("adhocwithfiles", "adhoc"), reason="only works with LocalCache" +) def test_unknown_feature_on_cache_sync(archivers, request): # LocalCache.sync checks repo compat archiver = request.getfixturevalue(archivers) @@ -324,7 +326,9 @@ def test_check_cache(archivers, request): check_cache(archiver) -@pytest.mark.skipif(os.environ.get("BORG_CACHE_IMPL") in ("newcache", "adhoc"), reason="only works with LocalCache") +@pytest.mark.skipif( + os.environ.get("BORG_CACHE_IMPL") in ("adhocwithfiles", "adhoc"), reason="only works with LocalCache" +) def test_env_use_chunks_archive(archivers, request, monkeypatch): archiver = request.getfixturevalue(archivers) create_test_files(archiver.input_path) diff --git a/src/borg/testsuite/archiver/create_cmd.py b/src/borg/testsuite/archiver/create_cmd.py index 50c02aab2..461097ac5 100644 --- a/src/borg/testsuite/archiver/create_cmd.py +++ b/src/borg/testsuite/archiver/create_cmd.py @@ -540,8 +540,10 @@ def test_create_pattern_intermediate_folders_first(archivers, request): assert out_list.index("d x/b") < out_list.index("- x/b/foo_b") -@pytest.mark.skipif(os.environ.get("BORG_CACHE_IMPL") in ("newcache", "local"), reason="only works with AdHocCache") -def test_create_no_cache_sync_adhoc(archivers, request): # TODO: add test for NewCache +@pytest.mark.skipif( + os.environ.get("BORG_CACHE_IMPL") in ("adhocwithfiles", "local"), reason="only works with AdHocCache" +) +def test_create_no_cache_sync_adhoc(archivers, request): # TODO: add test for AdHocWithFilesCache archiver = request.getfixturevalue(archivers) create_test_files(archiver.input_path) cmd(archiver, "rcreate", RK_ENCRYPTION) diff --git a/src/borg/testsuite/archiver/debug_cmds.py b/src/borg/testsuite/archiver/debug_cmds.py index 0dd4ea139..3923871a5 100644 --- a/src/borg/testsuite/archiver/debug_cmds.py +++ b/src/borg/testsuite/archiver/debug_cmds.py @@ -169,7 +169,7 @@ def test_debug_refcount_obj(archivers, request): archive_id = create_json["archive"]["id"] output = cmd(archiver, "debug", "refcount-obj", archive_id).strip() # LocalCache does precise refcounting, so we'll get 1 reference for the archive. - # AdHocCache or NewCache doesn't, we'll get ChunkIndex.MAX_VALUE as refcount. + # AdHocCache or AdHocWithFilesCache doesn't, we'll get ChunkIndex.MAX_VALUE as refcount. assert ( output == f"object {archive_id} has 1 referrers [info from chunks cache]." or output == f"object {archive_id} has 4294966271 referrers [info from chunks cache]." diff --git a/src/borg/testsuite/conftest.py b/src/borg/testsuite/conftest.py index d17f1dc7a..4708d9170 100644 --- a/src/borg/testsuite/conftest.py +++ b/src/borg/testsuite/conftest.py @@ -127,7 +127,7 @@ def archiver(tmp_path, set_env_variables): archiver.patterns_file_path = os.fspath(tmp_path / "patterns") os.environ["BORG_KEYS_DIR"] = archiver.keys_path os.environ["BORG_CACHE_DIR"] = archiver.cache_path - # os.environ["BORG_CACHE_IMPL"] = "newcache" + # os.environ["BORG_CACHE_IMPL"] = "adhocwithfiles" os.mkdir(archiver.input_path) os.chmod(archiver.input_path, 0o777) # avoid troubles with fakeroot / FUSE os.mkdir(archiver.output_path)