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,353 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT OR Apache-2.0
|
|
2
|
+
"""Candidate bounded native managed bulk SET; no publication/Truss authority.
|
|
3
|
+
|
|
4
|
+
All SQL is the original managed compiler program. Preview is advisory. Execution
|
|
5
|
+
reselects and verifies the complete original population in one admitted native
|
|
6
|
+
transaction, with the same original receipt/settlement requirements as actions.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import hashlib
|
|
12
|
+
from collections.abc import Mapping
|
|
13
|
+
from dataclasses import dataclass, field
|
|
14
|
+
from datetime import timedelta
|
|
15
|
+
from decimal import Decimal
|
|
16
|
+
from time import monotonic
|
|
17
|
+
from types import MappingProxyType
|
|
18
|
+
from typing import Annotated, Any, cast
|
|
19
|
+
|
|
20
|
+
from pydantic import TypeAdapter
|
|
21
|
+
|
|
22
|
+
from .bulk import AtomicBulkPlan, BulkOutcome, BulkPreview
|
|
23
|
+
from .managed_actions import ManagedNativeConflict
|
|
24
|
+
from .managed_support import (
|
|
25
|
+
checked_receipt,
|
|
26
|
+
preserve_body_failure,
|
|
27
|
+
require_atomic_dispatch,
|
|
28
|
+
)
|
|
29
|
+
from .native_actions import NativeScope, _literal, native_input_value
|
|
30
|
+
from .native_program import NativeProgram, canonical_json
|
|
31
|
+
from .protocols import (
|
|
32
|
+
ActionConflict,
|
|
33
|
+
ActionDenied,
|
|
34
|
+
ActionFailed,
|
|
35
|
+
ActionIndeterminate,
|
|
36
|
+
ActionRefused,
|
|
37
|
+
ActionTimedOut,
|
|
38
|
+
NativeOutcomeDetails,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@dataclass(frozen=True)
|
|
43
|
+
class ManagedAtomicBulkExecutor:
|
|
44
|
+
connection: Any
|
|
45
|
+
program: NativeProgram
|
|
46
|
+
action: Any
|
|
47
|
+
inputs: Mapping[str, object]
|
|
48
|
+
admission: Any
|
|
49
|
+
default_timeout: timedelta
|
|
50
|
+
_quarantined: bool = field(default=False, init=False, repr=False, compare=False)
|
|
51
|
+
|
|
52
|
+
def __post_init__(self):
|
|
53
|
+
object.__setattr__(self, "inputs", MappingProxyType(dict(self.inputs)))
|
|
54
|
+
|
|
55
|
+
def _run(self, preview, timeout):
|
|
56
|
+
if self._quarantined:
|
|
57
|
+
raise ActionRefused("MANAGED_BULK_EXECUTOR_QUARANTINED")
|
|
58
|
+
self.program.bind(self.action)
|
|
59
|
+
program = self.program.checked()
|
|
60
|
+
if program["profile"] != "umf.actions.managed-delta-bulk/0.1":
|
|
61
|
+
raise ActionRefused("ORIGINAL_MANAGED_BULK_PROFILE_REQUIRED")
|
|
62
|
+
require_atomic_dispatch(program)
|
|
63
|
+
if set(self.inputs) != {p["name"] for p in program["parameters"]}:
|
|
64
|
+
raise ActionRefused("MANAGED_BULK_PARAMETER_INVENTORY")
|
|
65
|
+
carriers = {"string": str, "boolean": bool, "integer": int, "decimal": Decimal}
|
|
66
|
+
for p in program["parameters"]:
|
|
67
|
+
carrier = carriers[p["carrier"]]
|
|
68
|
+
TypeAdapter(carrier | None if p["nullable"] else carrier).validate_python(
|
|
69
|
+
self.inputs[p["name"]], strict=True
|
|
70
|
+
)
|
|
71
|
+
for source, name in program["actionInputs"].items():
|
|
72
|
+
field = self.action.input_type.model_fields[
|
|
73
|
+
next(
|
|
74
|
+
python
|
|
75
|
+
for original, python in self.action.input_fields
|
|
76
|
+
if original == source
|
|
77
|
+
)
|
|
78
|
+
]
|
|
79
|
+
annotation = (
|
|
80
|
+
Annotated[(field.annotation, *field.metadata)]
|
|
81
|
+
if field.metadata
|
|
82
|
+
else field.annotation
|
|
83
|
+
)
|
|
84
|
+
TypeAdapter(cast(Any, annotation)).validate_python(
|
|
85
|
+
self.inputs[name], strict=True
|
|
86
|
+
)
|
|
87
|
+
budget = self.default_timeout if timeout is None else timeout
|
|
88
|
+
if type(budget) is not timedelta or not 0 < budget.total_seconds() <= 60:
|
|
89
|
+
raise ActionRefused("FINITE_MANAGED_BULK_DEADLINE_REQUIRED")
|
|
90
|
+
deadline = monotonic() + budget.total_seconds()
|
|
91
|
+
request = canonical_json(
|
|
92
|
+
{
|
|
93
|
+
"program": program,
|
|
94
|
+
"inputDigest": self.program.bundle_input_digest,
|
|
95
|
+
"parameters": {
|
|
96
|
+
name: native_input_value(value)
|
|
97
|
+
for name, value in self.inputs.items()
|
|
98
|
+
},
|
|
99
|
+
}
|
|
100
|
+
)
|
|
101
|
+
scope = native = receipt = None
|
|
102
|
+
commit_started = write_started = False
|
|
103
|
+
markers, changes, verification = [], [], []
|
|
104
|
+
|
|
105
|
+
def details(state):
|
|
106
|
+
return NativeOutcomeDetails(
|
|
107
|
+
self.action,
|
|
108
|
+
program["profile"],
|
|
109
|
+
canonical_json(markers),
|
|
110
|
+
not changes if state == "committed" else None,
|
|
111
|
+
canonical_json(verification),
|
|
112
|
+
canonical_json(changes),
|
|
113
|
+
None if scope is None else scope.attribution_json,
|
|
114
|
+
receipt,
|
|
115
|
+
canonical_json({"state": state}),
|
|
116
|
+
request,
|
|
117
|
+
scope,
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
def statement(path):
|
|
121
|
+
if monotonic() >= deadline:
|
|
122
|
+
raise TimeoutError("original managed bulk deadline expired")
|
|
123
|
+
value = program[path]
|
|
124
|
+
values = []
|
|
125
|
+
for parameter in value["parameters"]:
|
|
126
|
+
source = parameter["source"]
|
|
127
|
+
if set(source) == {"bulkInput"}:
|
|
128
|
+
values.append(self.inputs[source["bulkInput"]])
|
|
129
|
+
elif set(source) == {"literal"}:
|
|
130
|
+
values.append(_literal(source["literal"]))
|
|
131
|
+
else:
|
|
132
|
+
raise ActionRefused("MANAGED_BULK_PARAMETER_SOURCE")
|
|
133
|
+
return value["sql"], tuple(values)
|
|
134
|
+
|
|
135
|
+
try:
|
|
136
|
+
with preserve_body_failure(
|
|
137
|
+
self.admission.hold(
|
|
138
|
+
self.connection, program, request, deadline=deadline
|
|
139
|
+
)
|
|
140
|
+
) as native:
|
|
141
|
+
scope = NativeScope(
|
|
142
|
+
native.store,
|
|
143
|
+
native.epoch,
|
|
144
|
+
native.authenticated,
|
|
145
|
+
native.effective,
|
|
146
|
+
native,
|
|
147
|
+
native.attribution_json,
|
|
148
|
+
)
|
|
149
|
+
if native.require_exact_commit_receipt() is not None:
|
|
150
|
+
raise ActionRefused("QUALIFIED_NATIVE_RECEIPT_PROOF_REQUIRED")
|
|
151
|
+
if type(native.allowed) is not bool:
|
|
152
|
+
raise ActionRefused("NATIVE_AUTHORIZATION_RESULT_REQUIRED")
|
|
153
|
+
native.recheck()
|
|
154
|
+
if not native.allowed:
|
|
155
|
+
raise ActionDenied("ROLE_DENIED", details("rolled-back"))
|
|
156
|
+
if native.query(*statement("keyCheck")) != [(0,)]:
|
|
157
|
+
raise ActionRefused("MANAGED_BULK_NATIVE_KEY_INTEGRITY")
|
|
158
|
+
fields = program["selectionFields"]
|
|
159
|
+
key_fields = program["entity"]["key"]["fields"]
|
|
160
|
+
key_ref = program["entity"]["key"]["reference"]
|
|
161
|
+
key_types = [
|
|
162
|
+
key.model
|
|
163
|
+
for key in self.action.key_types
|
|
164
|
+
if (key.module, key.element, key.key)
|
|
165
|
+
== (key_ref["module"], key_ref["element"], key_ref["key"])
|
|
166
|
+
]
|
|
167
|
+
if len(key_types) != 1:
|
|
168
|
+
raise ActionRefused("MANAGED_BULK_ORIGINAL_KEY_TYPE_REQUIRED")
|
|
169
|
+
key_type = key_types[0]
|
|
170
|
+
positions = [
|
|
171
|
+
next(
|
|
172
|
+
i
|
|
173
|
+
for i, field in enumerate(fields)
|
|
174
|
+
if field["reference"] == key["reference"]
|
|
175
|
+
)
|
|
176
|
+
for key in key_fields
|
|
177
|
+
]
|
|
178
|
+
selected = native.query(*statement("selection"))
|
|
179
|
+
if len(selected) > program["maxItems"]:
|
|
180
|
+
raise ActionRefused("MANAGED_BULK_MAX_ITEMS")
|
|
181
|
+
if any(len(row) != len(fields) for row in selected):
|
|
182
|
+
raise ActionRefused("MANAGED_BULK_ORIGINAL_PROJECTION")
|
|
183
|
+
keys = []
|
|
184
|
+
for row in selected:
|
|
185
|
+
values = {
|
|
186
|
+
(
|
|
187
|
+
field["reference"]["module"],
|
|
188
|
+
field["reference"]["element"],
|
|
189
|
+
): row[position]
|
|
190
|
+
for field, position in zip(key_fields, positions, strict=True)
|
|
191
|
+
}
|
|
192
|
+
keys.append(
|
|
193
|
+
key_type.model_validate(
|
|
194
|
+
{
|
|
195
|
+
name: values[(module, field)]
|
|
196
|
+
for module, field, name in key_type.UMF_FIELDS
|
|
197
|
+
},
|
|
198
|
+
strict=True,
|
|
199
|
+
)
|
|
200
|
+
)
|
|
201
|
+
if len({key.model_dump_json() for key in keys}) != len(keys):
|
|
202
|
+
raise ActionRefused("MANAGED_BULK_DUPLICATE_KEY")
|
|
203
|
+
if preview:
|
|
204
|
+
return BulkPreview(
|
|
205
|
+
tuple(keys),
|
|
206
|
+
"original bounded managed transaction selection; preview is advisory",
|
|
207
|
+
)
|
|
208
|
+
table = next(
|
|
209
|
+
table
|
|
210
|
+
for table in program["binding"]["tables"]
|
|
211
|
+
if table["logical"] == program["entity"]["key"]["table"]
|
|
212
|
+
)
|
|
213
|
+
columns = table["columns"]
|
|
214
|
+
key_positions = [
|
|
215
|
+
next(
|
|
216
|
+
i
|
|
217
|
+
for i, column in enumerate(columns)
|
|
218
|
+
if column["logical"] == key["logical"]
|
|
219
|
+
)
|
|
220
|
+
for key in key_fields
|
|
221
|
+
]
|
|
222
|
+
|
|
223
|
+
def population(rows):
|
|
224
|
+
result = {}
|
|
225
|
+
for row in rows:
|
|
226
|
+
if len(row) != len(columns):
|
|
227
|
+
raise ActionRefused(
|
|
228
|
+
"MANAGED_BULK_COMPLETE_POPULATION_SHAPE"
|
|
229
|
+
)
|
|
230
|
+
key = tuple(row[position] for position in key_positions)
|
|
231
|
+
if key in result:
|
|
232
|
+
raise ActionRefused("MANAGED_BULK_COMPLETE_POPULATION_KEY")
|
|
233
|
+
result[key] = tuple(row)
|
|
234
|
+
return result
|
|
235
|
+
|
|
236
|
+
before = population(native.query(*statement("before")))
|
|
237
|
+
if len(before) > 10000:
|
|
238
|
+
raise ActionRefused("MANAGED_BULK_COMPLETE_POPULATION_BOUND")
|
|
239
|
+
expected = dict(before)
|
|
240
|
+
changed = []
|
|
241
|
+
for selected_row, key_object in zip(selected, keys, strict=True):
|
|
242
|
+
key = tuple(selected_row[position] for position in positions)
|
|
243
|
+
if key not in expected:
|
|
244
|
+
raise ActionRefused(
|
|
245
|
+
"MANAGED_BULK_SELECTION_POPULATION_MISMATCH"
|
|
246
|
+
)
|
|
247
|
+
row = list(expected[key])
|
|
248
|
+
for field, source in program["values"]:
|
|
249
|
+
position = next(
|
|
250
|
+
i
|
|
251
|
+
for i, column in enumerate(columns)
|
|
252
|
+
if column["logical"] == field["logical"]
|
|
253
|
+
)
|
|
254
|
+
row[position] = (
|
|
255
|
+
self.inputs[program["actionInputs"][source["input"]]]
|
|
256
|
+
if "input" in source
|
|
257
|
+
else _literal(source["literal"])
|
|
258
|
+
)
|
|
259
|
+
expected[key] = tuple(row)
|
|
260
|
+
if expected[key] != before[key]:
|
|
261
|
+
changed.append(key_object)
|
|
262
|
+
native.recheck()
|
|
263
|
+
write_started = True
|
|
264
|
+
native.execute(*statement("update"))
|
|
265
|
+
if native.query(*statement("keyCheck")) != [(0,)]:
|
|
266
|
+
raise ActionRefused("MANAGED_BULK_NATIVE_KEY_INTEGRITY")
|
|
267
|
+
if population(native.query(*statement("after"))) != expected:
|
|
268
|
+
raise ActionFailed(
|
|
269
|
+
"MANAGED_BULK_FRAME_POSTCONDITION",
|
|
270
|
+
ValueError("original whole-population Key/Field frame differs"),
|
|
271
|
+
details("rolled-back"),
|
|
272
|
+
)
|
|
273
|
+
verification.extend(
|
|
274
|
+
[
|
|
275
|
+
{"check": "complete-key", "violations": 0},
|
|
276
|
+
{"check": "complete-population-frame", "violations": 0},
|
|
277
|
+
]
|
|
278
|
+
)
|
|
279
|
+
markers = [{"selected": len(keys), "changed": len(changed)}]
|
|
280
|
+
changes = [
|
|
281
|
+
{"kind": "updated", "key": key.model_dump_json()} for key in changed
|
|
282
|
+
]
|
|
283
|
+
original = canonical_json(
|
|
284
|
+
{
|
|
285
|
+
"programSha256": hashlib.sha256(
|
|
286
|
+
canonical_json(program).encode()
|
|
287
|
+
).hexdigest(),
|
|
288
|
+
"requestSha256": hashlib.sha256(request.encode()).hexdigest(),
|
|
289
|
+
"counts": markers,
|
|
290
|
+
"verification": verification,
|
|
291
|
+
"selectedKeys": [key.model_dump_json() for key in keys],
|
|
292
|
+
"changedKeys": [key.model_dump_json() for key in changed],
|
|
293
|
+
"noOp": not changed,
|
|
294
|
+
}
|
|
295
|
+
)
|
|
296
|
+
native.recheck()
|
|
297
|
+
if monotonic() >= deadline:
|
|
298
|
+
raise TimeoutError("original managed bulk deadline expired")
|
|
299
|
+
commit_started = True
|
|
300
|
+
receipt = checked_receipt(native.commit(markers_json=original), scope)
|
|
301
|
+
result = BulkOutcome(
|
|
302
|
+
len(keys), len(changed), receipt, details("committed")
|
|
303
|
+
)
|
|
304
|
+
return result
|
|
305
|
+
except BaseException as original:
|
|
306
|
+
if native is not None and native.rollback_confirmed is True:
|
|
307
|
+
if isinstance(original, ManagedNativeConflict):
|
|
308
|
+
raise ActionConflict(
|
|
309
|
+
"SERIALIZABLE_CONFLICT", False, details("rolled-back")
|
|
310
|
+
) from original
|
|
311
|
+
if (
|
|
312
|
+
isinstance(original, TimeoutError)
|
|
313
|
+
and not commit_started
|
|
314
|
+
and not native.commit_submitted
|
|
315
|
+
):
|
|
316
|
+
raise ActionTimedOut(
|
|
317
|
+
"MANAGED_BULK_TIMED_OUT", details("rolled-back")
|
|
318
|
+
) from original
|
|
319
|
+
if native is not None and (
|
|
320
|
+
commit_started
|
|
321
|
+
or native.commit_submitted
|
|
322
|
+
or (write_started or native.write_submitted)
|
|
323
|
+
and native.rollback_confirmed is not True
|
|
324
|
+
):
|
|
325
|
+
object.__setattr__(self, "_quarantined", True)
|
|
326
|
+
uncertain = ActionIndeterminate(
|
|
327
|
+
"MANAGED_BULK_INDETERMINATE", details("indeterminate")
|
|
328
|
+
)
|
|
329
|
+
try:
|
|
330
|
+
self.admission.quarantine(scope, original)
|
|
331
|
+
except BaseException as cleanup_error: # noqa: BLE001 - retain original settlement and quarantine failure together
|
|
332
|
+
uncertain.settlement_failures = (original, cleanup_error)
|
|
333
|
+
raise uncertain from original
|
|
334
|
+
if (
|
|
335
|
+
native is not None
|
|
336
|
+
and native.rollback_confirmed is True
|
|
337
|
+
and not isinstance(
|
|
338
|
+
original, (ActionRefused, ActionFailed, ActionDenied)
|
|
339
|
+
)
|
|
340
|
+
):
|
|
341
|
+
raise ActionFailed(
|
|
342
|
+
"MANAGED_BULK_NATIVE_FAILURE", original, details("rolled-back")
|
|
343
|
+
) from original
|
|
344
|
+
raise
|
|
345
|
+
|
|
346
|
+
def preview(self, *, timeout=None):
|
|
347
|
+
return self._run(True, timeout)
|
|
348
|
+
|
|
349
|
+
def execute(self, *, timeout=None):
|
|
350
|
+
return self._run(False, timeout)
|
|
351
|
+
|
|
352
|
+
def plan(self):
|
|
353
|
+
return AtomicBulkPlan(self)
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT OR Apache-2.0
|
|
2
|
+
"""Caller-owned managed Delta mutation target. No native capability is implied.
|
|
3
|
+
|
|
4
|
+
The initial managed profile is synchronous. A qualified native owner supplies
|
|
5
|
+
current source/identity/role/deployment fencing and exact commit metadata; the
|
|
6
|
+
SDK never creates a connection, synthesizes a receipt, retries or replays.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from collections.abc import Mapping
|
|
12
|
+
from contextlib import AbstractContextManager
|
|
13
|
+
from dataclasses import dataclass
|
|
14
|
+
from datetime import timedelta
|
|
15
|
+
from typing import Any, Protocol
|
|
16
|
+
|
|
17
|
+
from .adoption import TargetIdentity
|
|
18
|
+
from .bulk import AtomicBulkPlan
|
|
19
|
+
from .commands import CommandVariant
|
|
20
|
+
from .managed_actions import ManagedDeltaActionExecutor
|
|
21
|
+
from .managed_bulk import ManagedAtomicBulkExecutor
|
|
22
|
+
from .native_program import NativeProgram
|
|
23
|
+
from .protocols import ActionRefused, Receipt
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ManagedNativeScope(Protocol):
|
|
27
|
+
store: str
|
|
28
|
+
epoch: str
|
|
29
|
+
authenticated: str
|
|
30
|
+
effective: str
|
|
31
|
+
attribution_json: str
|
|
32
|
+
allowed: bool
|
|
33
|
+
write_submitted: bool
|
|
34
|
+
commit_submitted: bool
|
|
35
|
+
rollback_confirmed: bool
|
|
36
|
+
|
|
37
|
+
def require_exact_commit_receipt(self) -> None:
|
|
38
|
+
"""Refuse unless original qualified native metadata identifies this commit.
|
|
39
|
+
|
|
40
|
+
A boolean, label, latest history version or ledger correlation is not
|
|
41
|
+
evidence. The native owner retains its original capability/admission
|
|
42
|
+
proof in this scope through settlement, including the human mapping.
|
|
43
|
+
"""
|
|
44
|
+
...
|
|
45
|
+
|
|
46
|
+
def recheck(self) -> None: ...
|
|
47
|
+
def query(
|
|
48
|
+
self, sql: str, parameters: tuple[object, ...]
|
|
49
|
+
) -> list[tuple[Any, ...]]: ...
|
|
50
|
+
def execute(self, sql: str, parameters: tuple[object, ...]) -> None: ...
|
|
51
|
+
def commit(self, *, markers_json: str) -> Receipt: ...
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class ManagedDeltaAdmission(Protocol):
|
|
55
|
+
def identity(self, connection: Any) -> TargetIdentity:
|
|
56
|
+
"""Observe current native platform/target identity; no configured label substitute."""
|
|
57
|
+
...
|
|
58
|
+
|
|
59
|
+
def hold(
|
|
60
|
+
self,
|
|
61
|
+
connection: Any,
|
|
62
|
+
program: Mapping[str, Any],
|
|
63
|
+
request: str,
|
|
64
|
+
*,
|
|
65
|
+
deadline: float,
|
|
66
|
+
) -> AbstractContextManager[ManagedNativeScope]:
|
|
67
|
+
"""Require idle caller connection and retain original native fence until settled.
|
|
68
|
+
|
|
69
|
+
Entry proves original source/native table identities, current actor and
|
|
70
|
+
roles, settings, Key custody and deployed lifecycle/sole-writer fence.
|
|
71
|
+
Exit positively settles rollback, including validation/preview. It must
|
|
72
|
+
never close, reconnect or replay the caller connection. Uncertain exit
|
|
73
|
+
keeps original attempt custody and is quarantined by the executor.
|
|
74
|
+
"""
|
|
75
|
+
...
|
|
76
|
+
|
|
77
|
+
def quarantine(self, original: object, error: BaseException) -> None: ...
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@dataclass(frozen=True)
|
|
81
|
+
class UnityCatalogConfiguration:
|
|
82
|
+
identity: TargetIdentity
|
|
83
|
+
default_timeout: timedelta
|
|
84
|
+
|
|
85
|
+
def __post_init__(self) -> None:
|
|
86
|
+
if (
|
|
87
|
+
type(self.default_timeout) is not timedelta
|
|
88
|
+
or not 0 < self.default_timeout.total_seconds() <= 60
|
|
89
|
+
):
|
|
90
|
+
raise ActionRefused("FINITE_MANAGED_DELTA_DEADLINE_REQUIRED")
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class UnityCatalogTarget:
|
|
94
|
+
"""Mutation-only managed target; reads/search have distinct original profiles.
|
|
95
|
+
|
|
96
|
+
Programs are immutable source-bound catalog artifacts. No asynchronous or
|
|
97
|
+
replay capability is supplied by this target.
|
|
98
|
+
"""
|
|
99
|
+
|
|
100
|
+
def __init__(
|
|
101
|
+
self,
|
|
102
|
+
connection: Any,
|
|
103
|
+
catalog_target: UnityCatalogConfiguration,
|
|
104
|
+
admission: ManagedDeltaAdmission,
|
|
105
|
+
*,
|
|
106
|
+
programs: tuple[NativeProgram, ...] = (),
|
|
107
|
+
):
|
|
108
|
+
self.connection, self.configuration, self.admission = (
|
|
109
|
+
connection,
|
|
110
|
+
catalog_target,
|
|
111
|
+
admission,
|
|
112
|
+
)
|
|
113
|
+
self._executor = ManagedDeltaActionExecutor(
|
|
114
|
+
connection,
|
|
115
|
+
programs,
|
|
116
|
+
admission,
|
|
117
|
+
default_timeout=catalog_target.default_timeout,
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
def identity(self) -> TargetIdentity:
|
|
121
|
+
return self.admission.identity(self.connection)
|
|
122
|
+
|
|
123
|
+
def verify(self) -> None:
|
|
124
|
+
if self.identity() != self.configuration.identity:
|
|
125
|
+
raise ActionRefused("MANAGED_TARGET_IDENTITY_CHANGED")
|
|
126
|
+
|
|
127
|
+
def invoke(self, action, input, *, timeout=None):
|
|
128
|
+
self.verify()
|
|
129
|
+
return self._executor.invoke(action, input, timeout=timeout)
|
|
130
|
+
|
|
131
|
+
def validate(self, action, input, *, timeout=None):
|
|
132
|
+
self.verify()
|
|
133
|
+
return self._executor.validate(action, input, timeout=timeout)
|
|
134
|
+
|
|
135
|
+
def plan(
|
|
136
|
+
self,
|
|
137
|
+
entry: CommandVariant,
|
|
138
|
+
params: Mapping[str, object],
|
|
139
|
+
*,
|
|
140
|
+
timeout: timedelta | None = None,
|
|
141
|
+
) -> AtomicBulkPlan:
|
|
142
|
+
self.verify()
|
|
143
|
+
if not entry.pin.matches(self.identity()):
|
|
144
|
+
raise ActionRefused("NOT_COMPILED_FOR_TARGET")
|
|
145
|
+
budget = self.configuration.default_timeout if timeout is None else timeout
|
|
146
|
+
if type(budget) is not timedelta or not 0 < budget.total_seconds() <= 60:
|
|
147
|
+
raise ActionRefused("FINITE_MANAGED_BULK_DEADLINE_REQUIRED")
|
|
148
|
+
return ManagedAtomicBulkExecutor(
|
|
149
|
+
self.connection, entry.program, entry.action, params, self.admission, budget
|
|
150
|
+
).plan()
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT OR Apache-2.0
|
|
2
|
+
"""Managed execution mechanics; native authority and commit metadata remain owner ports."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import json
|
|
7
|
+
import re
|
|
8
|
+
from contextlib import contextmanager
|
|
9
|
+
|
|
10
|
+
from .native_actions import NativeScope
|
|
11
|
+
from .native_program import canonical_json
|
|
12
|
+
from .protocols import ActionRefused, Receipt
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@contextmanager
|
|
16
|
+
def preserve_body_failure(manager):
|
|
17
|
+
"""A host cleanup cannot suppress or replace the original operation failure."""
|
|
18
|
+
original = None
|
|
19
|
+
try:
|
|
20
|
+
with manager as value:
|
|
21
|
+
try:
|
|
22
|
+
yield value
|
|
23
|
+
except BaseException as error:
|
|
24
|
+
original = error
|
|
25
|
+
raise
|
|
26
|
+
except BaseException as closing:
|
|
27
|
+
if original is not None and closing is not original:
|
|
28
|
+
raise original from closing
|
|
29
|
+
raise
|
|
30
|
+
if original is not None:
|
|
31
|
+
raise original
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def checked_receipt(receipt: Receipt, scope: NativeScope) -> Receipt:
|
|
35
|
+
"""Validate the retained native receipt ABI; never infer native commit versions.
|
|
36
|
+
|
|
37
|
+
The admission owner must prove exact transaction metadata before dispatch.
|
|
38
|
+
This shape check cannot turn a ledger row, history tip or caller label into
|
|
39
|
+
that proof. A failure after COMMIT submission is uncertain settlement.
|
|
40
|
+
"""
|
|
41
|
+
try:
|
|
42
|
+
if (
|
|
43
|
+
type(receipt) is not Receipt
|
|
44
|
+
or receipt.store != scope.store
|
|
45
|
+
or receipt.epoch != scope.epoch
|
|
46
|
+
):
|
|
47
|
+
raise ValueError("receipt scope differs")
|
|
48
|
+
stores, versions = json.loads(receipt.store), json.loads(receipt.version)
|
|
49
|
+
if (
|
|
50
|
+
type(stores) is not list
|
|
51
|
+
or not stores
|
|
52
|
+
or any(
|
|
53
|
+
type(v) is not str
|
|
54
|
+
or re.fullmatch(
|
|
55
|
+
r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", v
|
|
56
|
+
)
|
|
57
|
+
is None
|
|
58
|
+
for v in stores
|
|
59
|
+
)
|
|
60
|
+
):
|
|
61
|
+
raise ValueError("native table UUID vector required")
|
|
62
|
+
if stores != sorted(set(stores)) or canonical_json(stores) != receipt.store:
|
|
63
|
+
raise ValueError("canonical distinct UUID vector required")
|
|
64
|
+
if (
|
|
65
|
+
type(versions) is not list
|
|
66
|
+
or not versions
|
|
67
|
+
or canonical_json(versions) != receipt.version
|
|
68
|
+
):
|
|
69
|
+
raise ValueError("canonical native commit vector required")
|
|
70
|
+
seen = set()
|
|
71
|
+
last = {}
|
|
72
|
+
for item in versions:
|
|
73
|
+
if (
|
|
74
|
+
type(item) is not dict
|
|
75
|
+
or set(item) != {"tableUuid", "version"}
|
|
76
|
+
or item["tableUuid"] not in stores
|
|
77
|
+
or type(item["version"]) is not str
|
|
78
|
+
or re.fullmatch(r"0|[1-9][0-9]*", item["version"]) is None
|
|
79
|
+
):
|
|
80
|
+
raise ValueError("exact native commit pair required")
|
|
81
|
+
table, version = item["tableUuid"], int(item["version"])
|
|
82
|
+
if table in last and version <= last[table]:
|
|
83
|
+
raise ValueError("native versions must increase per table")
|
|
84
|
+
last[table] = version
|
|
85
|
+
seen.add(table)
|
|
86
|
+
if seen != set(stores):
|
|
87
|
+
raise ValueError("complete table commit vector required")
|
|
88
|
+
except (ValueError, TypeError, KeyError) as error:
|
|
89
|
+
raise ActionRefused("EXACT_MANAGED_COMMIT_RECEIPT_REQUIRED") from error
|
|
90
|
+
return receipt
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def drive(generator, scope):
|
|
94
|
+
result = None
|
|
95
|
+
while True:
|
|
96
|
+
try:
|
|
97
|
+
operation = generator.send(result)
|
|
98
|
+
except StopIteration as done:
|
|
99
|
+
return done.value
|
|
100
|
+
if operation[0] != "query":
|
|
101
|
+
raise ActionRefused("DELTA_NATIVE_STATE_OPERATION")
|
|
102
|
+
result = scope.query(operation[1], operation[2])
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def net_changes(state):
|
|
106
|
+
created = []
|
|
107
|
+
changed = []
|
|
108
|
+
combined = {}
|
|
109
|
+
for index, effect in enumerate(state.program["effects"]):
|
|
110
|
+
identity = canonical_json(
|
|
111
|
+
[
|
|
112
|
+
effect["entity"]["key"]["reference"],
|
|
113
|
+
[
|
|
114
|
+
{"carrier": f["carrier"], "value": str(state.resolve(v))}
|
|
115
|
+
for f, v in zip(
|
|
116
|
+
effect["entity"]["key"]["fields"],
|
|
117
|
+
effect["entity"]["components"],
|
|
118
|
+
strict=True,
|
|
119
|
+
)
|
|
120
|
+
],
|
|
121
|
+
]
|
|
122
|
+
)
|
|
123
|
+
before, after = (
|
|
124
|
+
state.pre["effect:" + str(index)],
|
|
125
|
+
state.post["effect:" + str(index)],
|
|
126
|
+
)
|
|
127
|
+
if identity not in combined:
|
|
128
|
+
combined[identity] = {
|
|
129
|
+
"entity": effect["entity"],
|
|
130
|
+
"before": None if before is None else {},
|
|
131
|
+
"after": None if after is None else {},
|
|
132
|
+
}
|
|
133
|
+
net = combined[identity]
|
|
134
|
+
for phase, row in (("before", before), ("after", after)):
|
|
135
|
+
if (net[phase] is None) != (row is None):
|
|
136
|
+
raise ActionRefused("DELTA_ENTITY_IMAGE_DISAGREEMENT")
|
|
137
|
+
if row is not None:
|
|
138
|
+
net[phase].update(row)
|
|
139
|
+
for identity, net in combined.items():
|
|
140
|
+
before, after = net["before"], net["after"]
|
|
141
|
+
if before == after:
|
|
142
|
+
continue
|
|
143
|
+
key = state.key(net["entity"])
|
|
144
|
+
kind = (
|
|
145
|
+
"created"
|
|
146
|
+
if before is None and after is not None
|
|
147
|
+
else "deleted"
|
|
148
|
+
if after is None
|
|
149
|
+
else "updated"
|
|
150
|
+
)
|
|
151
|
+
state.changes.append({"kind": kind, "key": identity})
|
|
152
|
+
if kind == "created":
|
|
153
|
+
created.append(key)
|
|
154
|
+
elif kind == "updated":
|
|
155
|
+
changed.append(key)
|
|
156
|
+
return tuple(created), tuple(changed)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def require_atomic_dispatch(program):
|
|
160
|
+
"""The historical interactive candidate is not CONTRACT-073 admission.
|
|
161
|
+
|
|
162
|
+
The source-owned atomic dispatcher is a separate ABI. Until its complete
|
|
163
|
+
native result/receipt interface is implemented and checked here, no new
|
|
164
|
+
program label can enable the preserved sequential candidate machinery.
|
|
165
|
+
"""
|
|
166
|
+
raise ActionRefused("MANAGED_ATOMIC_DISPATCH_ABI_UNQUALIFIED")
|