Skip to main content

nodedb_types/sync/wire/
fts.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! FTS index/delete sync messages (client → server / server → client).
4//!
5//! `FtsIndexMsg` carries one document's text content from a Lite client to
6//! Origin for full-text indexing. `FtsDeleteMsg` removes a document from
7//! Origin's inverted index.
8//!
9//! Wire opcodes:
10//! - `0xA6` — `FtsIndex`    (Lite → Origin)
11//! - `0xA7` — `FtsIndexAck` (Origin → Lite)
12//! - `0xA8` — `FtsDelete`   (Lite → Origin)
13//! - `0xA9` — `FtsDeleteAck` (Origin → Lite)
14
15use serde::{Deserialize, Serialize};
16
17use crate::sync::wire::ack_status::AckStatus;
18
19/// FTS index request (Lite → Origin, 0xA6).
20///
21/// Requests that Origin index the concatenated text of a document into its
22/// inverted BM25 index. Origin allocates a surrogate for `(collection, doc_id)`
23/// and calls `InvertedIndex::index_document` on the Data Plane.
24#[derive(
25    Debug, Clone, Serialize, Deserialize, zerompk::ToMessagePack, zerompk::FromMessagePack,
26)]
27pub struct FtsIndexMsg {
28    /// Lite instance ID (for routing and dedup).
29    pub lite_id: String,
30    /// Target collection name.
31    pub collection: String,
32    /// External document identifier.
33    pub doc_id: String,
34    /// Concatenated text to index (all string fields joined by space).
35    pub text: String,
36    /// Monotonic batch ID (Lite-assigned, per-document). Used for ACK correlation.
37    pub batch_id: u64,
38    /// Stable identity of the originating producer. 0 for legacy clients.
39    #[serde(default)]
40    pub producer_id: u64,
41    /// Monotonic epoch counter incremented on every producer restart.
42    #[serde(default)]
43    pub epoch: u64,
44    /// Per-stream monotonic sequence number within the epoch.
45    #[serde(default)]
46    pub seq: u64,
47}
48
49/// FTS index acknowledgment (Origin → Lite, 0xA7).
50#[derive(
51    Debug, Clone, Serialize, Deserialize, zerompk::ToMessagePack, zerompk::FromMessagePack,
52)]
53pub struct FtsIndexAckMsg {
54    /// Collection acknowledged.
55    pub collection: String,
56    /// Document ID from the originating `FtsIndexMsg`.
57    pub doc_id: String,
58    /// Batch ID from the originating `FtsIndexMsg`.
59    pub batch_id: u64,
60    /// `true` if the document was successfully indexed on Origin.
61    pub accepted: bool,
62    /// Rejection detail when `accepted == false`.
63    #[serde(default)]
64    pub reject_reason: Option<String>,
65    /// Highest sequence number from this producer that has been durably applied.
66    #[serde(default)]
67    pub applied_seq: u64,
68    /// Idempotency outcome of the acknowledged message.
69    #[serde(default)]
70    pub status: AckStatus,
71}
72
73/// FTS delete request (Lite → Origin, 0xA8).
74///
75/// Removes the document identified by `doc_id` from Origin's inverted index.
76#[derive(
77    Debug, Clone, Serialize, Deserialize, zerompk::ToMessagePack, zerompk::FromMessagePack,
78)]
79pub struct FtsDeleteMsg {
80    /// Lite instance ID.
81    pub lite_id: String,
82    /// Target collection name.
83    pub collection: String,
84    /// External document identifier to remove.
85    pub doc_id: String,
86    /// Monotonic batch ID for ACK correlation.
87    pub batch_id: u64,
88    /// Stable identity of the originating producer. 0 for legacy clients.
89    #[serde(default)]
90    pub producer_id: u64,
91    /// Monotonic epoch counter incremented on every producer restart.
92    #[serde(default)]
93    pub epoch: u64,
94    /// Per-stream monotonic sequence number within the epoch.
95    #[serde(default)]
96    pub seq: u64,
97}
98
99/// FTS delete acknowledgment (Origin → Lite, 0xA9).
100#[derive(
101    Debug, Clone, Serialize, Deserialize, zerompk::ToMessagePack, zerompk::FromMessagePack,
102)]
103pub struct FtsDeleteAckMsg {
104    /// Collection acknowledged.
105    pub collection: String,
106    /// Document ID from the originating `FtsDeleteMsg`.
107    pub doc_id: String,
108    /// Batch ID from the originating `FtsDeleteMsg`.
109    pub batch_id: u64,
110    /// `true` if the document was successfully removed from Origin's index.
111    pub accepted: bool,
112    /// Rejection detail when `accepted == false`.
113    #[serde(default)]
114    pub reject_reason: Option<String>,
115    /// Highest sequence number from this producer that has been durably applied.
116    #[serde(default)]
117    pub applied_seq: u64,
118    /// Idempotency outcome of the acknowledged message.
119    #[serde(default)]
120    pub status: AckStatus,
121}