1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// SPDX-License-Identifier: BUSL-1.1
//! Protocol-neutral Calvin multi-shard dispatch (static path).
//!
//! This is the session-UNAWARE core extracted from the pgwire
//! `dispatch_calvin_multishard` static (non-OLLP) branch: classify the task
//! set, reject a cross-shard span that is a mid-block single statement (it
//! cannot be buffered atomically), build the static `TxClass`, and route the
//! single submit-and-await to the sequencer-group leader via
//! `submit_calvin_routed`.
//!
//! It takes the session-derived inputs the core needs — the cross-shard
//! transaction mode, the dispatch's position in the transaction lifecycle
//! (autocommit / mid-block statement / COMMIT flush), and the session read-set —
//! as plain parameters, so both the pgwire and native protocol paths can supply
//! them and share one implementation. The function returns a raw
//! `crate::Result<()>`: Calvin's static path produces no Data-Plane payload —
//! its success is the durable, replicated commit acknowledged by
//! `submit_calvin_routed` — so the per-task command tags are synthesised by
//! each protocol from the original task list AFTER this returns `Ok`.
//!
//! The OLLP (dependent-predicate) variant is intentionally NOT handled here: it
//! is still tied to the local `OllpOrchestrator` and completion registry and is
//! not yet leader-routed (a declared follow-up). Callers that may carry a
//! dependent predicate must route that case through their own OLLP path; this
//! helper is the static cross-shard write path only.
use crateResponse;
use crate;
use crateReadSetEntry;
use crateSharedState;
use crateTenantId;
use PhysicalTask;
/// Drive the static Calvin multi-shard path for `tasks`.
///
/// - `cross_shard_mode`: the session's effective cross-shard transaction mode.
/// Only [`CrossShardTxnMode::Strict`] routes through Calvin here; callers are
/// expected to have already gated on this, but it is re-checked defensively.
/// - `position`: where this dispatch sits in the transaction lifecycle. Only a
/// [`TxnDispatchPosition::MidBlockStatement`] cross-shard span is rejected with
/// [`crate::Error::CrossShardInExplicitTransaction`] (it cannot be buffered
/// atomically); [`TxnDispatchPosition::Autocommit`] and the COMMIT
/// [`TxnDispatchPosition::CommitFlush`] both proceed.
/// - `reads`: the session read-set. It widens the dispatch classification and
/// the `TxClass` participants/OCC set in lockstep — a txn that writes shard A
/// but reads shard B enumerates B as a participant. Autocommit callers pass an
/// empty slice.
///
/// On success the Calvin transaction has been submitted and acknowledged by the
/// sequencer leader. Returns the applied Data-Plane [`Response`] when the write
/// carried a RETURNING clause (so the caller can emit its rows), or `None` for a
/// plain write — where the caller synthesises one command tag per task.
pub async