mirror of
https://github.com/borgbackup/borg.git
synced 2025-03-10 14:15:43 +00:00
Refactor cache sync options and introduce new cache preference
Add new borg create option '--prefer-adhoc-cache' to prefer the AdHocCache over the NewCache implementation. Adjust a test to match the previous default behaviour (== use the AdHocCache) with --no-cache-sync.
This commit is contained in:
parent
85688e7543
commit
561dcc8abf
3 changed files with 28 additions and 16 deletions
|
@ -224,8 +224,9 @@ class CreateMixIn:
|
||||||
manifest,
|
manifest,
|
||||||
progress=args.progress,
|
progress=args.progress,
|
||||||
lock_wait=self.lock_wait,
|
lock_wait=self.lock_wait,
|
||||||
permit_adhoc_cache=args.no_cache_sync,
|
no_cache_sync_permitted=args.no_cache_sync,
|
||||||
force_adhoc_cache=args.no_cache_sync_forced,
|
no_cache_sync_forced=args.no_cache_sync_forced,
|
||||||
|
prefer_adhoc_cache=args.prefer_adhoc_cache,
|
||||||
cache_mode=args.files_cache_mode,
|
cache_mode=args.files_cache_mode,
|
||||||
iec=args.iec,
|
iec=args.iec,
|
||||||
) as cache:
|
) as cache:
|
||||||
|
@ -802,13 +803,19 @@ class CreateMixIn:
|
||||||
"--no-cache-sync",
|
"--no-cache-sync",
|
||||||
dest="no_cache_sync",
|
dest="no_cache_sync",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="experimental: do not synchronize the cache. Implies not using the files cache.",
|
help="experimental: do not synchronize the chunks cache.",
|
||||||
)
|
)
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
"--no-cache-sync-forced",
|
"--no-cache-sync-forced",
|
||||||
dest="no_cache_sync_forced",
|
dest="no_cache_sync_forced",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="experimental: do not synchronize the cache (forced). Implies not using the files cache.",
|
help="experimental: do not synchronize the chunks cache (forced).",
|
||||||
|
)
|
||||||
|
subparser.add_argument(
|
||||||
|
"--prefer-adhoc-cache",
|
||||||
|
dest="prefer_adhoc_cache",
|
||||||
|
action="store_true",
|
||||||
|
help="experimental: prefer AdHocCache (w/o files cache) over NewCache (with files cache).",
|
||||||
)
|
)
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
"--stdin-name",
|
"--stdin-name",
|
||||||
|
|
|
@ -350,8 +350,9 @@ class Cache:
|
||||||
warn_if_unencrypted=True,
|
warn_if_unencrypted=True,
|
||||||
progress=False,
|
progress=False,
|
||||||
lock_wait=None,
|
lock_wait=None,
|
||||||
permit_adhoc_cache=False,
|
no_cache_sync_permitted=False,
|
||||||
force_adhoc_cache=False,
|
no_cache_sync_forced=False,
|
||||||
|
prefer_adhoc_cache=False,
|
||||||
cache_mode=FILES_CACHE_MODE_DISABLED,
|
cache_mode=FILES_CACHE_MODE_DISABLED,
|
||||||
iec=False,
|
iec=False,
|
||||||
):
|
):
|
||||||
|
@ -381,14 +382,14 @@ 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)
|
||||||
|
|
||||||
if force_adhoc_cache:
|
if no_cache_sync_forced:
|
||||||
return adhoc()
|
return adhoc() if prefer_adhoc_cache else newcache()
|
||||||
|
|
||||||
if not permit_adhoc_cache:
|
if not no_cache_sync_permitted:
|
||||||
return local()
|
return local()
|
||||||
|
|
||||||
# ad-hoc cache may be permitted, but if the local cache is in sync it'd be stupid to invalidate
|
# 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 ad-hoc cache.
|
# it by needlessly using the AdHocCache or the NewCache.
|
||||||
# Check if the local cache exists and is in sync.
|
# Check if the local cache exists and is in sync.
|
||||||
|
|
||||||
cache_config = CacheConfig(repository, path, lock_wait)
|
cache_config = CacheConfig(repository, path, lock_wait)
|
||||||
|
@ -400,8 +401,12 @@ class Cache:
|
||||||
# Local cache is in sync, use it
|
# Local cache is in sync, use it
|
||||||
logger.debug("Cache: choosing local cache (in sync)")
|
logger.debug("Cache: choosing local cache (in sync)")
|
||||||
return local()
|
return local()
|
||||||
logger.debug("Cache: choosing ad-hoc cache (local cache does not exist or is not in sync)")
|
if prefer_adhoc_cache:
|
||||||
return adhoc()
|
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()
|
||||||
|
|
||||||
|
|
||||||
class CacheStatsMixin:
|
class CacheStatsMixin:
|
||||||
|
|
|
@ -540,20 +540,20 @@ 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")
|
||||||
|
|
||||||
|
|
||||||
def test_create_no_cache_sync(archivers, request):
|
def test_create_no_cache_sync_adhoc(archivers, request): # TODO: add test for NewCache
|
||||||
archiver = request.getfixturevalue(archivers)
|
archiver = request.getfixturevalue(archivers)
|
||||||
create_test_files(archiver.input_path)
|
create_test_files(archiver.input_path)
|
||||||
cmd(archiver, "rcreate", RK_ENCRYPTION)
|
cmd(archiver, "rcreate", RK_ENCRYPTION)
|
||||||
cmd(archiver, "rdelete", "--cache-only")
|
cmd(archiver, "rdelete", "--cache-only")
|
||||||
create_json = json.loads(
|
create_json = json.loads(
|
||||||
cmd(archiver, "create", "--no-cache-sync", "--json", "--error", "test", "input")
|
cmd(archiver, "create", "--no-cache-sync", "--prefer-adhoc-cache", "--json", "--error", "test", "input")
|
||||||
) # ignore experimental warning
|
) # ignore experimental warning
|
||||||
info_json = json.loads(cmd(archiver, "info", "-a", "test", "--json"))
|
info_json = json.loads(cmd(archiver, "info", "-a", "test", "--json"))
|
||||||
create_stats = create_json["cache"]["stats"]
|
create_stats = create_json["cache"]["stats"]
|
||||||
info_stats = info_json["cache"]["stats"]
|
info_stats = info_json["cache"]["stats"]
|
||||||
assert create_stats == info_stats
|
assert create_stats == info_stats
|
||||||
cmd(archiver, "rdelete", "--cache-only")
|
cmd(archiver, "rdelete", "--cache-only")
|
||||||
cmd(archiver, "create", "--no-cache-sync", "test2", "input")
|
cmd(archiver, "create", "--no-cache-sync", "--prefer-adhoc-cache", "test2", "input")
|
||||||
cmd(archiver, "rinfo")
|
cmd(archiver, "rinfo")
|
||||||
cmd(archiver, "check")
|
cmd(archiver, "check")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue