Skip to content

Commit 662e8f3

Browse files
committed
Introduced new setting "disable_rollback"
1 parent a63bb24 commit 662e8f3

File tree

6 files changed

+32
-4
lines changed

6 files changed

+32
-4
lines changed

CONFIG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ Specifies the names of variables to be included in the target dataset. Defaults
149149
Type _array_.
150150
Specifies the names of individual variables to be excluded from all contributing datasets.
151151

152+
### `disable_rollback`
153+
154+
Type _boolean_.
155+
Disable rolling back dataset changes on failure. Effectively disables transactional dataset modifications, so use this setting with care.
156+
Defaults to `false`.
157+
152158
### `dry_run`
153159

154160
Type _boolean_.

tests/test_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ def test_schema(self):
209209
self.assertEqual(
210210
{
211211
'append_dim',
212+
'disable_rollback',
212213
'dry_run',
213214
'excluded_variables',
214215
'fixed_dims',

tests/test_context.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ def test_temp_dir(self):
6161
self.assertIsInstance(ctx.temp_dir, FileObj)
6262
self.assertTrue(ctx.temp_dir.exists())
6363

64+
def test_disable_rollback(self):
65+
ctx = Context({"target_uri": "memory://target.zarr"})
66+
self.assertFalse(ctx.disable_rollback)
67+
ctx = Context({"target_uri": "memory://target.zarr",
68+
"disable_rollback": True})
69+
self.assertTrue(ctx.disable_rollback)
70+
6471
def test_dry_run(self):
6572
ctx = Context({"target_uri": "memory://target.zarr"})
6673
self.assertEqual(False, ctx.dry_run)

zappend/config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,14 @@
408408
"items": {"type": "string", "minLength": 1}
409409
},
410410

411+
disable_rollback={
412+
"description": "Disable rolling back dataset changes on failure."
413+
" Effectively disables transactional dataset"
414+
" modifications, so use this setting with care.",
415+
"type": "boolean",
416+
"default": False
417+
},
418+
411419
dry_run={
412420
"description": "If 'true', log only what would have been done,"
413421
" but don't apply any changes.",

zappend/context.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from .config import DEFAULT_ZARR_VERSION
1414
from .metadata import DatasetMetadata
1515
from .fsutil.fileobj import FileObj
16-
from .log import logger
1716

1817

1918
class Context:
@@ -99,6 +98,10 @@ def slice_polling(self) -> tuple[float, float] | tuple[None, None]:
9998
def temp_dir(self) -> FileObj:
10099
return self._temp_dir
101100

101+
@property
102+
def disable_rollback(self) -> bool:
103+
return self._config.get("disable_rollback", False)
104+
102105
@property
103106
def dry_run(self) -> bool:
104107
return self._config.get("dry_run", False)

zappend/processor.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,18 @@ def process_slice(self, slice_obj: str | xr.Dataset):
6767
ctx.append_dim_name
6868
)
6969

70-
with Transaction(ctx.target_dir, ctx.temp_dir) as rollback_cb:
70+
transaction = Transaction(ctx.target_dir,
71+
ctx.temp_dir,
72+
disable_rollback=ctx.disable_rollback)
73+
with transaction as rollback_callback:
7174
if ctx.target_metadata is slice_metadata:
7275
create_target_from_slice(ctx,
7376
slice_dataset,
74-
rollback_cb)
77+
rollback_callback)
7578
else:
7679
update_target_from_slice(ctx,
7780
slice_dataset,
78-
rollback_cb)
81+
rollback_callback)
7982

8083

8184
def create_target_from_slice(ctx: Context,

0 commit comments

Comments
 (0)