umf-access 0.1.0.dev8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- umf_access/__init__.py +109 -0
- umf_access/adoption.py +41 -0
- umf_access/build/__init__.py +2 -0
- umf_access/build/approximate.py +34 -0
- umf_access/build/catalog.py +1626 -0
- umf_access/build/commands.py +394 -0
- umf_access/build/pg_privileges.py +1544 -0
- umf_access/build/privileges.py +134 -0
- umf_access/build/search.py +365 -0
- umf_access/build/unity_search.py +104 -0
- umf_access/bulk.py +227 -0
- umf_access/canonical.py +23 -0
- umf_access/capture.py +410 -0
- umf_access/catalog.py +325 -0
- umf_access/codec_support.py +427 -0
- umf_access/commands.py +93 -0
- umf_access/delta_read.py +758 -0
- umf_access/dsl/__init__.py +148 -0
- umf_access/dsl/_context.py +36 -0
- umf_access/dsl/_expressions.py +625 -0
- umf_access/dsl/_joined.py +4 -0
- umf_access/dsl/_nodes.py +207 -0
- umf_access/dsl/_query.py +5559 -0
- umf_access/dsl/_selection.py +143 -0
- umf_access/dsl/navigation.py +302 -0
- umf_access/dsl/render.py +516 -0
- umf_access/dsl/search.py +343 -0
- umf_access/engine_catalog.py +563 -0
- umf_access/generated_core.py +5 -0
- umf_access/lifecycle/__init__.py +46 -0
- umf_access/lifecycle/_darwin_process_observer.c +306 -0
- umf_access/lifecycle/approval.py +366 -0
- umf_access/lifecycle/backfills.py +79 -0
- umf_access/lifecycle/catalog.py +289 -0
- umf_access/lifecycle/cli.py +231 -0
- umf_access/lifecycle/concurrent.py +196 -0
- umf_access/lifecycle/conversion_policy.py +188 -0
- umf_access/lifecycle/correspondence.py +203 -0
- umf_access/lifecycle/generation_authority_bootstrap.py +1491 -0
- umf_access/lifecycle/generation_authority_session.py +125 -0
- umf_access/lifecycle/generation_enrollment_authority.py +1108 -0
- umf_access/lifecycle/generation_enrollment_ledger.py +698 -0
- umf_access/lifecycle/generation_ingress.py +185 -0
- umf_access/lifecycle/generation_root_registry.py +138 -0
- umf_access/lifecycle/head.py +250 -0
- umf_access/lifecycle/head_view.py +81 -0
- umf_access/lifecycle/host.py +1183 -0
- umf_access/lifecycle/ingress_custody.py +750 -0
- umf_access/lifecycle/ingress_local_postgres.py +7990 -0
- umf_access/lifecycle/ingress_store.py +1488 -0
- umf_access/lifecycle/ledger.py +276 -0
- umf_access/lifecycle/ledger_schema.py +116 -0
- umf_access/lifecycle/mixed.py +593 -0
- umf_access/lifecycle/outcome_schema.py +136 -0
- umf_access/lifecycle/owner_approval_core.py +1810 -0
- umf_access/lifecycle/owner_authority.py +472 -0
- umf_access/lifecycle/owner_bootstrap.py +2077 -0
- umf_access/lifecycle/owner_wire.py +161 -0
- umf_access/lifecycle/phase_fence.py +52 -0
- umf_access/lifecycle/phase_policy.py +422 -0
- umf_access/lifecycle/privileges.py +145 -0
- umf_access/lifecycle/probe.py +39 -0
- umf_access/lifecycle/progress.py +497 -0
- umf_access/lifecycle/roles.py +96 -0
- umf_access/lifecycle/row_originals.py +1712 -0
- umf_access/lifecycle/row_originals_creation.py +759 -0
- umf_access/lifecycle/row_originals_receipt.py +413 -0
- umf_access/lifecycle/seeds.py +99 -0
- umf_access/lifecycle/sql_containment.py +358 -0
- umf_access/lifecycle/sql_containment_cli.py +33 -0
- umf_access/lifecycle/sql_containment_parser.py +20 -0
- umf_access/lifecycle/supervisor_journal_codec.py +1251 -0
- umf_access/lifecycle/table_boundary.py +22 -0
- umf_access/lifecycle/target_custody_codec.py +788 -0
- umf_access/lifecycle/witness.py +72 -0
- umf_access/managed_actions.py +271 -0
- umf_access/managed_bulk.py +353 -0
- umf_access/managed_delta.py +150 -0
- umf_access/managed_support.py +166 -0
- umf_access/manifest_commands.py +278 -0
- umf_access/native_actions.py +1007 -0
- umf_access/native_program.py +570 -0
- umf_access/pages.py +125 -0
- umf_access/postgres_bulk.py +509 -0
- umf_access/postgres_read.py +1230 -0
- umf_access/postgres_search.py +639 -0
- umf_access/protocols.py +665 -0
- umf_access/py.typed +0 -0
- umf_access/related_keys.py +233 -0
- umf_access/reviewed.py +706 -0
- umf_access/search_catalog.py +122 -0
- umf_access/targets.py +312 -0
- umf_access/types.py +220 -0
- umf_access/unified/__init__.py +187 -0
- umf_access/unified/_binding.py +654 -0
- umf_access/unified/head_session.py +144 -0
- umf_access/unified/native_binding.py +143 -0
- umf_access/unified/operation_values.py +173 -0
- umf_access/unified/outcome_values.py +76 -0
- umf_access/unified/session_async.py +161 -0
- umf_access/unified/session_binding.py +108 -0
- umf_access/unified/session_policy.py +152 -0
- umf_access/unified/session_psycopg2.py +70 -0
- umf_access/unified/session_sqlalchemy.py +161 -0
- umf_access/unified/session_sync.py +148 -0
- umf_access/unified/table_reads.py +314 -0
- umf_access/unified/table_writes.py +193 -0
- umf_access/unity_search.py +312 -0
- umf_access/values.py +280 -0
- umf_access/verification.py +64 -0
- umf_access-0.1.0.dev8.dist-info/METADATA +15 -0
- umf_access-0.1.0.dev8.dist-info/RECORD +117 -0
- umf_access-0.1.0.dev8.dist-info/WHEEL +4 -0
- umf_access-0.1.0.dev8.dist-info/entry_points.txt +4 -0
- umf_access-0.1.0.dev8.dist-info/licenses/LICENSE-APACHE +201 -0
- umf_access-0.1.0.dev8.dist-info/licenses/LICENSE-MIT +21 -0
- umf_access-0.1.0.dev8.dist-info/licenses/LICENSE.md +239 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT OR Apache-2.0
|
|
2
|
+
"""Native witnesses are captured only after source correspondence succeeds."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
from typing import Any, cast
|
|
8
|
+
|
|
9
|
+
from .catalog import _COLUMNS as _COLUMN_QUERY
|
|
10
|
+
from .catalog import _CONSTRAINTS, _INDEXES, _POLICY, CatalogError
|
|
11
|
+
from .privileges import _COLUMN_ACL, _TABLE_ACL
|
|
12
|
+
from .probe import _Query, _run
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _json_bytes(value: Any) -> bytes:
|
|
16
|
+
# All dictionary keys are fixed ASCII fields in this internal profile.
|
|
17
|
+
# Native values are arrays, strings, booleans, null and safe integers.
|
|
18
|
+
# This bounded subset is exactly RFC8785 without a second generic emitter.
|
|
19
|
+
remaining = 200_000
|
|
20
|
+
def check(item: Any, depth: int = 0) -> None:
|
|
21
|
+
nonlocal remaining
|
|
22
|
+
remaining -= 1
|
|
23
|
+
if depth > 64 or remaining < 0:
|
|
24
|
+
raise CatalogError('ledger-value-capacity')
|
|
25
|
+
if item is None or type(item) is bool:
|
|
26
|
+
return
|
|
27
|
+
if type(item) is int and abs(item) <= 9_007_199_254_740_991:
|
|
28
|
+
return
|
|
29
|
+
if type(item) is str:
|
|
30
|
+
item.encode('utf-8')
|
|
31
|
+
return
|
|
32
|
+
if isinstance(item,(list,tuple)):
|
|
33
|
+
for member in item: check(member,depth+1)
|
|
34
|
+
return
|
|
35
|
+
if type(item) is dict and all(type(k) is str and k.isascii() for k in item):
|
|
36
|
+
for member in item.values(): check(member,depth+1)
|
|
37
|
+
return
|
|
38
|
+
raise CatalogError('ledger-value-unqualified')
|
|
39
|
+
check(value)
|
|
40
|
+
return json.dumps(value,ensure_ascii=False,sort_keys=True,separators=(',',':'),allow_nan=False).encode('utf-8')
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _entry_digest(position: int, predecessor: str | None, plan_digest: str, witness: Any, file_digest: str | None = None) -> str:
|
|
44
|
+
return hashlib.sha256(_json_bytes({'position':position,'predecessor':predecessor,'planDigest':plan_digest,'witness':witness,**({'fileDigest':file_digest} if file_digest is not None else {})})).hexdigest()
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _capture_witness(connection: Any, source: dict[str, Any]) -> dict[str, Any]:
|
|
48
|
+
return _run(connection,_witness_steps(source))
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _witness_steps(source: dict[str, Any]) -> dict[str, Any]:
|
|
52
|
+
schema = source['configuration']['schema']
|
|
53
|
+
# Native expression trees retain typed constants without locale/timezone deparsing.
|
|
54
|
+
# Keep existing non-domain witness0.1 bytes unchanged.
|
|
55
|
+
exact_nodes=any(check['id'].startswith('domain:') for check in source['expectedCatalog']['checks'])
|
|
56
|
+
column_query=_COLUMN_QUERY.replace('pg_catalog.pg_get_expr(d.adbin,d.adrelid)','d.adbin::pg_catalog.text') if exact_nodes else _COLUMN_QUERY
|
|
57
|
+
constraint_query=_CONSTRAINTS.replace('pg_catalog.pg_get_constraintdef(co.oid,true)','CASE WHEN co.conbin IS NULL THEN pg_catalog.pg_get_constraintdef(co.oid,true) ELSE co.conbin::pg_catalog.text END') if exact_nodes else _CONSTRAINTS
|
|
58
|
+
roles = sorted({source['configuration'][k] for k in ('ownerRole', 'personRole', 'batchRole')} | set(source['configuration']['groupRoles'].values()))
|
|
59
|
+
tables = []
|
|
60
|
+
for table in source['expectedCatalog']['tables']:
|
|
61
|
+
name = table['name']
|
|
62
|
+
relation = (yield _Query('one', 'SELECT c.oid,c.relowner,c.relkind,c.relpersistence,c.relrowsecurity,c.relforcerowsecurity,c.relispartition,c.relhassubclass,c.relhasrules,c.relreplident,c.relam\nFROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace WHERE n.nspname=%s AND c.relname=%s', (schema, name)))
|
|
63
|
+
policies = []
|
|
64
|
+
for audience in ('person', 'batch'):
|
|
65
|
+
for command in ('select', 'insert', 'update', 'delete'):
|
|
66
|
+
policies.append([audience, command, (yield _Query('one', _POLICY, (schema, name, 'umf_' + audience + '_' + command)))])
|
|
67
|
+
tables.append({'id': table['id'], 'relation': relation, 'columns': (yield _Query('all', column_query, (schema, name))), 'constraints': (yield _Query('all', constraint_query, (schema, name))), 'indexes': (yield _Query('all', _INDEXES, (schema, name))), 'tableAcl': (yield _Query('all', _TABLE_ACL, (schema, name))), 'columnAcl': (yield _Query('all', _COLUMN_ACL, (schema, name))), 'policies': policies})
|
|
68
|
+
role_rows = []
|
|
69
|
+
for role_name in roles:
|
|
70
|
+
role_rows.append((yield _Query('one', 'SELECT oid,rolname FROM pg_catalog.pg_roles WHERE rolname=%s', (role_name,))))
|
|
71
|
+
result = {'version': 'umf.native-table-witness/0.2' if exact_nodes else 'umf.native-table-witness/0.1', 'serverVersion': (yield _Query('one', "SELECT current_setting('server_version_num')::pg_catalog.int4", ()))[0], 'database': (yield _Query('one', 'SELECT oid,datname FROM pg_catalog.pg_database WHERE datname=current_database()', ())), 'schema': (yield _Query('one', 'SELECT oid,nspowner FROM pg_catalog.pg_namespace WHERE nspname=%s', (schema,))), 'roles': role_rows, 'tables': tables}
|
|
72
|
+
return cast(dict[str, Any], json.loads(_json_bytes(result)))
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT OR Apache-2.0
|
|
2
|
+
"""Managed raw Delta execution of original compiler programs.
|
|
3
|
+
|
|
4
|
+
This is separate from Ashlar publication targets. The caller supplies a qualified
|
|
5
|
+
native admission/transaction interval; no connection or authority is invented.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import hashlib
|
|
11
|
+
from datetime import timedelta
|
|
12
|
+
from time import monotonic
|
|
13
|
+
|
|
14
|
+
from .managed_support import (
|
|
15
|
+
checked_receipt,
|
|
16
|
+
drive,
|
|
17
|
+
net_changes,
|
|
18
|
+
preserve_body_failure,
|
|
19
|
+
require_atomic_dispatch,
|
|
20
|
+
)
|
|
21
|
+
from .native_actions import NativeScope, _State
|
|
22
|
+
from .native_program import canonical_json
|
|
23
|
+
from .protocols import (
|
|
24
|
+
ActionFailed,
|
|
25
|
+
ActionRefused,
|
|
26
|
+
Committed,
|
|
27
|
+
Conflict,
|
|
28
|
+
Denied,
|
|
29
|
+
Indeterminate,
|
|
30
|
+
Rejected,
|
|
31
|
+
TimedOut,
|
|
32
|
+
ValidationFailure,
|
|
33
|
+
ValidationResult,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class ManagedNativeConflict(Exception):
|
|
38
|
+
"""Only an independently verified original native serialization conflict."""
|
|
39
|
+
|
|
40
|
+
def __init__(self, original):
|
|
41
|
+
self.original = original
|
|
42
|
+
super().__init__("Original managed native conflict; no retry")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class ManagedDeltaActionExecutor:
|
|
46
|
+
def __init__(self, connection, programs, admission, *, default_timeout: timedelta):
|
|
47
|
+
if (
|
|
48
|
+
type(default_timeout) is not timedelta
|
|
49
|
+
or not 0 < default_timeout.total_seconds() <= 60
|
|
50
|
+
):
|
|
51
|
+
raise ActionRefused("FINITE_MANAGED_DELTA_DEADLINE_REQUIRED")
|
|
52
|
+
self.connection = connection
|
|
53
|
+
self.programs, self.admission, self.default_timeout = (
|
|
54
|
+
tuple(programs),
|
|
55
|
+
admission,
|
|
56
|
+
default_timeout,
|
|
57
|
+
)
|
|
58
|
+
self.quarantined = False
|
|
59
|
+
|
|
60
|
+
def _state(self, action, inputs):
|
|
61
|
+
if self.quarantined:
|
|
62
|
+
raise ActionRefused("MANAGED_DELTA_EXECUTOR_QUARANTINED")
|
|
63
|
+
matching = [
|
|
64
|
+
p
|
|
65
|
+
for p in self.programs
|
|
66
|
+
if p.checked().get("profile") == "umf.actions.managed-delta/0.1"
|
|
67
|
+
and p.checked()["source"]["documentSha256"]
|
|
68
|
+
== getattr(action.source, "document_sha256", None)
|
|
69
|
+
and p.checked()["source"]["action"] == action.action
|
|
70
|
+
]
|
|
71
|
+
if len(matching) != 1:
|
|
72
|
+
raise ActionRefused("MANAGED_DELTA_ACTION_NOT_COMPILED")
|
|
73
|
+
require_atomic_dispatch(matching[0].checked())
|
|
74
|
+
return _State(action, matching[0], inputs)
|
|
75
|
+
|
|
76
|
+
def _run(self, action, inputs, timeout, validate):
|
|
77
|
+
state = self._state(action, inputs)
|
|
78
|
+
budget = self.default_timeout if timeout is None else timeout
|
|
79
|
+
if type(budget) is not timedelta or not 0 < budget.total_seconds() <= 60:
|
|
80
|
+
raise ActionRefused("FINITE_MANAGED_DELTA_DEADLINE_REQUIRED")
|
|
81
|
+
deadline = monotonic() + budget.total_seconds()
|
|
82
|
+
native = None
|
|
83
|
+
commit_started = False
|
|
84
|
+
write_started = False
|
|
85
|
+
try:
|
|
86
|
+
with preserve_body_failure(
|
|
87
|
+
self.admission.hold(
|
|
88
|
+
self.connection, state.program, state.request, deadline=deadline
|
|
89
|
+
)
|
|
90
|
+
) as native:
|
|
91
|
+
# The owner proves these native identities and holds their current
|
|
92
|
+
# source/role/identity fence through the original commit interval.
|
|
93
|
+
state.scope = NativeScope(
|
|
94
|
+
native.store,
|
|
95
|
+
native.epoch,
|
|
96
|
+
native.authenticated,
|
|
97
|
+
native.effective,
|
|
98
|
+
native,
|
|
99
|
+
native.attribution_json,
|
|
100
|
+
)
|
|
101
|
+
if native.require_exact_commit_receipt() is not None:
|
|
102
|
+
raise ActionRefused("QUALIFIED_NATIVE_RECEIPT_PROOF_REQUIRED")
|
|
103
|
+
if type(native.allowed) is not bool:
|
|
104
|
+
raise ActionRefused("NATIVE_AUTHORIZATION_RESULT_REQUIRED")
|
|
105
|
+
native.recheck()
|
|
106
|
+
if not native.allowed:
|
|
107
|
+
return (
|
|
108
|
+
ValidationResult(
|
|
109
|
+
False, (ValidationFailure("ROLE_DENIED"),), True
|
|
110
|
+
)
|
|
111
|
+
if validate
|
|
112
|
+
else Denied("ROLE_DENIED", state.details("rolled-back"))
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
def check_time():
|
|
116
|
+
if monotonic() >= deadline:
|
|
117
|
+
raise TimeoutError("original managed action deadline expired")
|
|
118
|
+
|
|
119
|
+
def key_check():
|
|
120
|
+
check_time()
|
|
121
|
+
if native.query(*state.statement("/keyCheck")) != [(0,)]:
|
|
122
|
+
raise ActionRefused("MANAGED_DELTA_NATIVE_KEY_INTEGRITY")
|
|
123
|
+
|
|
124
|
+
key_check()
|
|
125
|
+
drive(state.images("pre"), native)
|
|
126
|
+
missing = [
|
|
127
|
+
name
|
|
128
|
+
for name, entity in state.program["entities"].items()
|
|
129
|
+
if entity["requiredExisting"]
|
|
130
|
+
and state.pre["entity:" + name] is None
|
|
131
|
+
]
|
|
132
|
+
failures = (
|
|
133
|
+
[ValidationFailure("ENTITY_MISSING")]
|
|
134
|
+
if missing
|
|
135
|
+
else drive(state.conditions("pre", collect_all=validate), native)
|
|
136
|
+
)
|
|
137
|
+
if failures or validate:
|
|
138
|
+
if validate:
|
|
139
|
+
return ValidationResult(
|
|
140
|
+
not failures,
|
|
141
|
+
tuple(failures),
|
|
142
|
+
not missing or not state.program["preconditions"],
|
|
143
|
+
)
|
|
144
|
+
condition = next(
|
|
145
|
+
(
|
|
146
|
+
c
|
|
147
|
+
for c in state.program["preconditions"]
|
|
148
|
+
if c["code"] == failures[0].code
|
|
149
|
+
),
|
|
150
|
+
None,
|
|
151
|
+
)
|
|
152
|
+
return Rejected(
|
|
153
|
+
failures[0].code,
|
|
154
|
+
False if condition is None else condition["retryable"],
|
|
155
|
+
state.details("rolled-back"),
|
|
156
|
+
)
|
|
157
|
+
for index, effect in enumerate(state.program["effects"]):
|
|
158
|
+
check_time()
|
|
159
|
+
before = state.pre["effect:" + str(index)]
|
|
160
|
+
if effect["kind"] == "create" and before is not None:
|
|
161
|
+
raise ActionFailed(
|
|
162
|
+
"KEY_EXISTS",
|
|
163
|
+
ValueError("original managed CREATE Key already exists"),
|
|
164
|
+
state.details("rolled-back"),
|
|
165
|
+
)
|
|
166
|
+
if effect["kind"] != "create" and before is None:
|
|
167
|
+
raise ActionFailed(
|
|
168
|
+
"ENTITY_MISSING",
|
|
169
|
+
ValueError("original managed effect entity absent"),
|
|
170
|
+
state.details("rolled-back"),
|
|
171
|
+
)
|
|
172
|
+
if effect["guard"] is not None:
|
|
173
|
+
rows = native.query(
|
|
174
|
+
*state.statement("/effects/" + str(index) + "/guard")
|
|
175
|
+
)
|
|
176
|
+
if (
|
|
177
|
+
len(rows) != 1
|
|
178
|
+
or len(rows[0]) != 1
|
|
179
|
+
or type(rows[0][0]) is not bool
|
|
180
|
+
):
|
|
181
|
+
raise ActionRefused("MANAGED_DELTA_EFFECT_MARKER")
|
|
182
|
+
if not rows[0][0]:
|
|
183
|
+
state.markers.append({"id": effect["id"], "changed": False})
|
|
184
|
+
continue
|
|
185
|
+
write_started = True
|
|
186
|
+
native.execute(
|
|
187
|
+
*state.statement("/effects/" + str(index) + "/statement")
|
|
188
|
+
)
|
|
189
|
+
state.markers.append({"id": effect["id"], "changed": True})
|
|
190
|
+
key_check()
|
|
191
|
+
drive(state.images("post"), native)
|
|
192
|
+
failures = drive(state.conditions("post"), native)
|
|
193
|
+
if failures:
|
|
194
|
+
raise ActionFailed(
|
|
195
|
+
"POSTCONDITION_" + failures[0].code,
|
|
196
|
+
ValueError("original managed postcondition failed"),
|
|
197
|
+
state.details("rolled-back"),
|
|
198
|
+
)
|
|
199
|
+
created, changed = net_changes(state)
|
|
200
|
+
markers = canonical_json(
|
|
201
|
+
{
|
|
202
|
+
"programSha256": hashlib.sha256(
|
|
203
|
+
canonical_json(state.program).encode()
|
|
204
|
+
).hexdigest(),
|
|
205
|
+
"requestSha256": hashlib.sha256(
|
|
206
|
+
state.request.encode()
|
|
207
|
+
).hexdigest(),
|
|
208
|
+
"verification": state.verification,
|
|
209
|
+
"effects": state.markers,
|
|
210
|
+
"changes": state.changes,
|
|
211
|
+
"noOp": not state.changes,
|
|
212
|
+
}
|
|
213
|
+
)
|
|
214
|
+
native.recheck()
|
|
215
|
+
check_time()
|
|
216
|
+
# Owner commits data + these exact markers + original request in
|
|
217
|
+
# one native transaction and returns its exact retained receipt.
|
|
218
|
+
commit_started = True
|
|
219
|
+
state.receipt = checked_receipt(
|
|
220
|
+
native.commit(markers_json=markers), state.scope
|
|
221
|
+
)
|
|
222
|
+
result = Committed(
|
|
223
|
+
None, state.receipt, created, changed, state.details("committed")
|
|
224
|
+
)
|
|
225
|
+
native.recheck()
|
|
226
|
+
return result
|
|
227
|
+
except BaseException as error:
|
|
228
|
+
if (
|
|
229
|
+
isinstance(error, ManagedNativeConflict)
|
|
230
|
+
and native is not None
|
|
231
|
+
and native.rollback_confirmed is True
|
|
232
|
+
):
|
|
233
|
+
return Conflict(
|
|
234
|
+
False, "SERIALIZABLE_CONFLICT", state.details("rolled-back")
|
|
235
|
+
)
|
|
236
|
+
if native is not None and (
|
|
237
|
+
commit_started
|
|
238
|
+
or native.commit_submitted
|
|
239
|
+
or (
|
|
240
|
+
(write_started or native.write_submitted)
|
|
241
|
+
and native.rollback_confirmed is not True
|
|
242
|
+
)
|
|
243
|
+
):
|
|
244
|
+
self.quarantined = True
|
|
245
|
+
self.original_failure = error
|
|
246
|
+
try:
|
|
247
|
+
self.admission.quarantine(state.scope, error)
|
|
248
|
+
except BaseException as cleanup_error: # noqa: BLE001 - retain both original and failed quarantine custody
|
|
249
|
+
self.quarantine_failure = (error, cleanup_error)
|
|
250
|
+
return Indeterminate(state.details("indeterminate"))
|
|
251
|
+
if (
|
|
252
|
+
isinstance(error, TimeoutError)
|
|
253
|
+
and native is not None
|
|
254
|
+
and native.rollback_confirmed is True
|
|
255
|
+
):
|
|
256
|
+
return TimedOut(state.details("rolled-back"))
|
|
257
|
+
if (
|
|
258
|
+
native is not None
|
|
259
|
+
and native.rollback_confirmed is True
|
|
260
|
+
and not isinstance(error, (ActionRefused, ActionFailed))
|
|
261
|
+
):
|
|
262
|
+
raise ActionFailed(
|
|
263
|
+
"MANAGED_NATIVE_FAILURE", error, state.details("rolled-back")
|
|
264
|
+
) from error
|
|
265
|
+
raise
|
|
266
|
+
|
|
267
|
+
def invoke(self, action, input, *, timeout=None):
|
|
268
|
+
return self._run(action, input, timeout, False)
|
|
269
|
+
|
|
270
|
+
def validate(self, action, input, *, timeout=None):
|
|
271
|
+
return self._run(action, input, timeout, True)
|