Преглед изворни кода

BORG_CACHE_IMPL environment variable added

BORG_CACHE_IMPL allows users to choose the client-side cache implementation from 'local', 'newcache' and 'adhoc'.
Thomas Waldmann пре 10 месеци
родитељ
комит
616af8daa8
3 измењених фајлова са 20 додато и 0 уклоњено
  1. 10 0
      docs/usage/general/environment.rst.inc
  2. 9 0
      src/borg/cache.py
  3. 1 0
      src/borg/testsuite/conftest.py

+ 10 - 0
docs/usage/general/environment.rst.inc

@@ -84,6 +84,16 @@ General:
         - ``pyfuse3``: only try to load pyfuse3
         - ``llfuse``: only try to load llfuse
         - ``none``: do not try to load an implementation
+    BORG_CACHE_IMPL
+        Choose the implementation for the clientside cache, choose one of:
+
+        - ``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.
+          Also has a persistent files cache. Default implementation.
+        - ``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.
     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.

+ 9 - 0
src/borg/cache.py

@@ -382,6 +382,15 @@ class Cache:
         def adhoc():
             return AdHocCache(manifest=manifest, lock_wait=lock_wait, iec=iec)
 
+        impl = os.environ.get("BORG_CACHE_IMPL", None)
+        if impl is not None:
+            methods = dict(local=local, newcache=newcache, adhoc=adhoc)
+            try:
+                method = methods[impl]
+            except KeyError:
+                raise RuntimeError("Unknown BORG_CACHE_IMPL value: %s" % impl)
+            return method()
+
         if no_cache_sync_forced:
             return adhoc() if prefer_adhoc_cache else newcache()
 

+ 1 - 0
src/borg/testsuite/conftest.py

@@ -127,6 +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.mkdir(archiver.input_path)
     os.chmod(archiver.input_path, 0o777)  # avoid troubles with fakeroot / FUSE
     os.mkdir(archiver.output_path)