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
// SPDX-License-Identifier: BUSL-1.1
//! `RegistryAssignRemoteSurrogate` — bridges the cluster `AssignSurrogate`
//! trigger to a node-local `SurrogateAssigner::assign` (F1b).
//!
//! `nodedb-cluster` cannot depend on `nodedb` (circular), so the assign logic
//! lives here and is exposed to the transport via the
//! [`nodedb_cluster::AssignRemoteSurrogate`] hook. The `RaftLoop` is built
//! `with_assign_remote_surrogate(Arc::new(RegistryAssignRemoteSurrogate { .. }))`.
//!
//! # What it does
//!
//! This handler only ever runs on the home vShard's LEADER (the coordinator
//! routes the `AssignSurrogateRequest` there precisely so the assign is local to
//! the data's home node). On `on_assign_surrogate`, the leader:
//! 1. runs `SurrogateAssigner::assign(database_id, tenant_id, collection, pk)` —
//! a LOCAL assign that allocates from this node's HiLo batch on the first call
//! and returns the persisted binding on every later call;
//! 2. because the leader IS the home node, that value is the AUTHORITATIVE
//! surrogate the home node stores under: first-wins, idempotent, the same one
//! every coordinator that routes here will receive;
//! 3. maps `Ok(surrogate)` → [`AssignSurrogateResponse`] with `error: None` and
//! `Err` → a typed [`TypedClusterError::Internal`] (surrogate `0`) — never a
//! silent drop.
//!
//! # Plane discipline
//!
//! This runs on the leader's Control Plane (the Tokio transport reactor). The
//! `SurrogateAssigner` is a synchronous `Send + Sync` facade; the call neither
//! touches storage I/O / io_uring directly nor spawns a Data-Plane task.
use Arc;
use ;
use crateSharedState;
use crate;
/// `nodedb`-side implementation of [`nodedb_cluster::AssignRemoteSurrogate`].
///
/// Holds the node's [`SharedState`] so it can reach the `SurrogateAssigner`. The
/// assign runs against THIS node's allocator; the coordinator only routes here
/// when this node is the endpoint key's home vShard leader, so the local value is
/// the authoritative one.