Handle a ShapeSubscribe message. Registers the shape in the registry, evaluates the initial dataset via the provided `snapshot_provider`, and returns a ShapeSnapshot frame. The `snapshot_provider` callback bridges to the Data Plane: it receives the shape definition and current LSN, dispatches the appropriate query (DocumentScan for document shapes, GraphHop for graph shapes, collection scan for
(
session_id: &str,
tenant_id: u64,
msg: &ShapeSubscribeMsg,
registry: &ShapeRegistry,
current_lsn: u64,
snapshot_provider: F,
)
| 95 | /// callback is synchronous because the SPSC bridge response is collected |
| 96 | /// before this function is called. |
| 97 | pub fn handle_subscribe<F>( |
| 98 | session_id: &str, |
| 99 | tenant_id: u64, |
| 100 | msg: &ShapeSubscribeMsg, |
| 101 | registry: &ShapeRegistry, |
| 102 | current_lsn: u64, |
| 103 | snapshot_provider: F, |
| 104 | ) -> Option<SyncFrame> |
| 105 | where |
| 106 | F: FnOnce(&ShapeDefinition, u64) -> ShapeSnapshotData, |
| 107 | { |
| 108 | let shape = msg.shape.clone(); |
| 109 | let shape_id = shape.shape_id.clone(); |
| 110 | |
| 111 | registry.subscribe(session_id, tenant_id, shape.clone()); |
| 112 | |
| 113 | // Query the Data Plane for the initial dataset matching this shape. |
| 114 | let snapshot_data = snapshot_provider(&shape, current_lsn); |
| 115 | |
| 116 | let snapshot = ShapeSnapshotMsg { |
| 117 | shape_id, |
| 118 | data: snapshot_data.data, |
| 119 | snapshot_lsn: current_lsn, |
| 120 | doc_count: snapshot_data.doc_count, |
| 121 | }; |
| 122 | |
| 123 | info!( |
| 124 | session = session_id, |
| 125 | shape_id = %msg.shape.shape_id, |
| 126 | lsn = current_lsn, |
| 127 | doc_count = snapshot.doc_count, |
| 128 | "shape subscribed, snapshot sent" |
| 129 | ); |
| 130 | |
| 131 | SyncFrame::try_encode(SyncMessageType::ShapeSnapshot, &snapshot) |
| 132 | } |
| 133 | |
| 134 | /// Handle a ShapeUnsubscribe message. |
| 135 | pub fn handle_unsubscribe(session_id: &str, msg: &ShapeUnsubscribeMsg, registry: &ShapeRegistry) { |