2
0
Эх сурвалжийг харах

BORG_CACHE_IMPL defaults to "adhocwithfiles" now

Also: support a "cli" env var value, that does not determine
the implementation from the env var, but rather from cli options (similar to as it was before adding BORG_CACHE_IMPL).
Thomas Waldmann 10 сар өмнө
parent
commit
619a06a5ba

+ 4 - 2
docs/usage/general/environment.rst.inc

@@ -89,11 +89,13 @@ General:
 
 
         - ``local``: uses a persistent chunks cache and keeps it in a perfect state (precise refcounts and
         - ``local``: uses a persistent chunks cache and keeps it in a perfect state (precise refcounts and
           sizes), requiring a potentially resource expensive cache sync in multi-client scenarios.
           sizes), requiring a potentially resource expensive cache sync in multi-client scenarios.
-          Also has a persistent files cache. Default implementation.
+          Also has a persistent files cache.
         - ``adhoc``: builds a non-persistent chunks cache by querying the repo. Chunks cache contents
         - ``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
           are somewhat sloppy for already existing chunks, concerning their refcount ("infinite") and
           size (0). No files cache (slow, will chunk all input files). DEPRECATED.
           size (0). No files cache (slow, will chunk all input files). DEPRECATED.
-        - ``adhocwithfiles``: Like ``adhoc``, but with a persistent files cache.
+        - ``adhocwithfiles``: Like ``adhoc``, but with a persistent files cache. Default implementation.
+        - ``cli``: Determine the cache implementation from cli options. Without special options, will
+          usually end up with the ``local`` implementation.
     BORG_SELFTEST
     BORG_SELFTEST
         This can be used to influence borg's builtin self-tests. The default is to execute the tests
         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.
         at the beginning of each borg command invocation.

+ 6 - 2
src/borg/cache.py

@@ -299,6 +299,10 @@ class CacheConfig:
             raise Exception("%s does not look like a Borg cache." % config_path) from None
             raise Exception("%s does not look like a Borg cache." % config_path) from None
 
 
 
 
+def get_cache_impl():
+    return os.environ.get("BORG_CACHE_IMPL", "adhocwithfiles")
+
+
 class Cache:
 class Cache:
     """Client Side cache"""
     """Client Side cache"""
 
 
@@ -382,8 +386,8 @@ class Cache:
         def adhoc():
         def adhoc():
             return AdHocCache(manifest=manifest, lock_wait=lock_wait, iec=iec)
             return AdHocCache(manifest=manifest, lock_wait=lock_wait, iec=iec)
 
 
-        impl = os.environ.get("BORG_CACHE_IMPL", None)
-        if impl is not None:
+        impl = get_cache_impl()
+        if impl != "cli":
             methods = dict(local=local, adhocwithfiles=adhocwithfiles, adhoc=adhoc)
             methods = dict(local=local, adhocwithfiles=adhocwithfiles, adhoc=adhoc)
             try:
             try:
                 method = methods[impl]
                 method = methods[impl]

+ 3 - 7
src/borg/testsuite/archiver/checks.py

@@ -4,7 +4,7 @@ from unittest.mock import patch
 
 
 import pytest
 import pytest
 
 
-from ...cache import Cache, LocalCache
+from ...cache import Cache, LocalCache, get_cache_impl
 from ...constants import *  # NOQA
 from ...constants import *  # NOQA
 from ...helpers import Location, get_security_dir, bin_to_hex
 from ...helpers import Location, get_security_dir, bin_to_hex
 from ...helpers import EXIT_ERROR
 from ...helpers import EXIT_ERROR
@@ -204,9 +204,7 @@ def test_unknown_feature_on_create(archivers, request):
     cmd_raises_unknown_feature(archiver, ["create", "test", "input"])
     cmd_raises_unknown_feature(archiver, ["create", "test", "input"])
 
 
 
 
-@pytest.mark.skipif(
-    os.environ.get("BORG_CACHE_IMPL") in ("adhocwithfiles", "adhoc"), reason="only works with LocalCache"
-)
+@pytest.mark.skipif(get_cache_impl() in ("adhocwithfiles", "adhoc"), reason="only works with LocalCache")
 def test_unknown_feature_on_cache_sync(archivers, request):
 def test_unknown_feature_on_cache_sync(archivers, request):
     # LocalCache.sync checks repo compat
     # LocalCache.sync checks repo compat
     archiver = request.getfixturevalue(archivers)
     archiver = request.getfixturevalue(archivers)
@@ -326,9 +324,7 @@ def test_check_cache(archivers, request):
         check_cache(archiver)
         check_cache(archiver)
 
 
 
 
-@pytest.mark.skipif(
-    os.environ.get("BORG_CACHE_IMPL") in ("adhocwithfiles", "adhoc"), reason="only works with LocalCache"
-)
+@pytest.mark.skipif(get_cache_impl() in ("adhocwithfiles", "adhoc"), reason="only works with LocalCache")
 def test_env_use_chunks_archive(archivers, request, monkeypatch):
 def test_env_use_chunks_archive(archivers, request, monkeypatch):
     archiver = request.getfixturevalue(archivers)
     archiver = request.getfixturevalue(archivers)
     create_test_files(archiver.input_path)
     create_test_files(archiver.input_path)

+ 2 - 3
src/borg/testsuite/archiver/create_cmd.py

@@ -12,6 +12,7 @@ import time
 import pytest
 import pytest
 
 
 from ... import platform
 from ... import platform
+from ...cache import get_cache_impl
 from ...constants import *  # NOQA
 from ...constants import *  # NOQA
 from ...manifest import Manifest
 from ...manifest import Manifest
 from ...platform import is_cygwin, is_win32, is_darwin
 from ...platform import is_cygwin, is_win32, is_darwin
@@ -540,9 +541,7 @@ def test_create_pattern_intermediate_folders_first(archivers, request):
     assert out_list.index("d x/b") < out_list.index("- x/b/foo_b")
     assert out_list.index("d x/b") < out_list.index("- x/b/foo_b")
 
 
 
 
-@pytest.mark.skipif(
-    os.environ.get("BORG_CACHE_IMPL") in ("adhocwithfiles", "local"), reason="only works with AdHocCache"
-)
+@pytest.mark.skipif(get_cache_impl() in ("adhocwithfiles", "local"), reason="only works with AdHocCache")
 def test_create_no_cache_sync_adhoc(archivers, request):  # TODO: add test for AdHocWithFilesCache
 def test_create_no_cache_sync_adhoc(archivers, request):  # TODO: add test for AdHocWithFilesCache
     archiver = request.getfixturevalue(archivers)
     archiver = request.getfixturevalue(archivers)
     create_test_files(archiver.input_path)
     create_test_files(archiver.input_path)