database.proto 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  1. // Smartbotic Database Service
  2. // Document-oriented storage with persistence and replication
  3. syntax = "proto3";
  4. package smartbotic.databasepb;
  5. // Error code range: 6000-6999 for Database errors
  6. // 6000: Generic database error
  7. // 6001: Collection not found
  8. // 6002: Document not found
  9. // 6003: Document already exists
  10. // 6004: Version conflict
  11. // 6005: Invalid query
  12. // 6006: File not found
  13. // 6007: File too large
  14. // 6008: Encryption error
  15. // 6009: Replication error
  16. // 6010: Version not found
  17. // ===== Main Database Service =====
  18. // v2.12.0 - REFUSAL DETAIL. Any refused write may carry trailing metadata
  19. // `sbdb-error-detail-bin`: UTF-8 JSON (gRPC base64s a -bin value on the wire)
  20. // that says WHY in a form a program can branch on, whether the refusal came as
  21. // an error status or in-band (status OK, success=false). Keys, all optional:
  22. //
  23. // reason "unique_violation" | "missing_parent" | "delete_restricted"
  24. // | "read_only" | "memory_pressure" | "view_write"
  25. // | "not_found" | "version_conflict" | "invalid_increment"
  26. // | "duplicate_id" (2.12.1) | "file_too_large"
  27. // | "mime_type_not_allowed" (2.12.3)
  28. // code the gRPC status code number - present for in-band
  29. // refusals, whose status is OK
  30. // fields the field(s) concerned: the constrained field(s) of a
  31. // unique violation, the reference field of a missing
  32. // parent, the field an increment could not be applied to
  33. // values object, field -> the value that collided / was refused
  34. // conflicting_id unique violation: the document already holding the value
  35. // relation missing parent: the relation that refused the write
  36. // current_version version conflict: the document's current version
  37. //
  38. // Absent on a server older than 2.12.0. The reason exists because a status
  39. // code alone is ambiguous: FAILED_PRECONDITION means a missing parent, a
  40. // restricted delete AND read-only mode.
  41. service DatabaseService {
  42. // Document operations
  43. rpc Insert(InsertRequest) returns (InsertResponse);
  44. rpc Get(GetRequest) returns (GetResponse);
  45. rpc Update(UpdateRequest) returns (UpdateResponse);
  46. rpc Upsert(UpsertRequest) returns (UpsertResponse);
  47. rpc Delete(DeleteRequest) returns (DeleteResponse);
  48. rpc PatchDocument(PatchDocumentRequest) returns (PatchDocumentResponse);
  49. rpc Exists(ExistsRequest) returns (ExistsResponse);
  50. // Version history operations
  51. rpc GetVersionHistory(GetVersionHistoryRequest) returns (GetVersionHistoryResponse);
  52. rpc GetDocumentVersion(GetDocumentVersionRequest) returns (GetDocumentVersionResponse);
  53. rpc RestoreVersion(RestoreVersionRequest) returns (RestoreVersionResponse);
  54. rpc RestoreToDate(RestoreToDateRequest) returns (RestoreToDateResponse);
  55. // Batch operations
  56. rpc BatchInsert(BatchInsertRequest) returns (BatchInsertResponse);
  57. rpc BatchGet(BatchGetRequest) returns (BatchGetResponse);
  58. rpc BatchDelete(BatchDeleteRequest) returns (BatchDeleteResponse);
  59. // Query operations
  60. rpc Find(FindRequest) returns (FindResponse);
  61. rpc Count(CountRequest) returns (CountResponse);
  62. rpc SimilaritySearch(SimilaritySearchRequest) returns (SimilaritySearchResponse);
  63. // Set operations (Redis compatibility)
  64. rpc SetAdd(SetAddRequest) returns (SetAddResponse);
  65. rpc SetRemove(SetRemoveRequest) returns (SetRemoveResponse);
  66. rpc SetMembers(SetMembersRequest) returns (SetMembersResponse);
  67. rpc SetIsMember(SetIsMemberRequest) returns (SetIsMemberResponse);
  68. // Collection management
  69. rpc CreateCollection(CreateCollectionRequest) returns (CreateCollectionResponse);
  70. rpc DropCollection(DropCollectionRequest) returns (DropCollectionResponse);
  71. rpc ListCollections(ListCollectionsRequest) returns (ListCollectionsResponse);
  72. rpc GetCollectionInfo(GetCollectionInfoRequest) returns (GetCollectionInfoResponse);
  73. // v2.3 — Project management. Projects are top-level namespaces over
  74. // collections. The "default" project is implicit and always exists.
  75. rpc ListProjects(ListProjectsRequest) returns (ListProjectsResponse);
  76. rpc CreateProject(CreateProjectRequest) returns (CreateProjectResponse);
  77. rpc DropProject(DropProjectRequest) returns (DropProjectResponse);
  78. // View management
  79. rpc CreateView(CreateViewRequest) returns (CreateViewResponse);
  80. rpc DropView(DropViewRequest) returns (DropViewResponse);
  81. rpc ListViews(ListViewsRequest) returns (ListViewsResponse);
  82. rpc GetViewInfo(GetViewInfoRequest) returns (GetViewInfoResponse);
  83. // v2.11.0 T6b — relation (referential integrity) management. Admin-only:
  84. // `_relations` is a system collection and a relation names another
  85. // collection's schema, so declaring one is not ordinary per-collection
  86. // write access.
  87. rpc CreateRelation(CreateRelationRequest) returns (CreateRelationResponse);
  88. rpc DropRelation(DropRelationRequest) returns (DropRelationResponse);
  89. rpc ListRelations(ListRelationsRequest) returns (ListRelationsResponse);
  90. rpc GetRelationInfo(GetRelationInfoRequest) returns (GetRelationInfoResponse);
  91. // v2.11.0 T5 — "what would happen if I deleted this?" without deleting
  92. // it. Read-only and gated as an ordinary per-collection read, not admin.
  93. rpc DescribeDelete(DescribeDeleteRequest) returns (DescribeDeleteResponse);
  94. // v2.11.0 T7 — "does this relation's reverse index actually match live
  95. // data?" A relation declared over a collection that already had rows
  96. // before v2.11.0 T7 shipped (or one whose sub-db was lost/restored from
  97. // an older snapshot) can carry postings for parent ids that no longer
  98. // exist. This walks the reverse index and probes each parent id;
  99. // mutates nothing. ⚠ Cost is proportional to the number of DISTINCT
  100. // parents referenced, not collection size, but on a very large child
  101. // collection that is still a full index walk - treat this as an
  102. // operator/migration tool, not something to call on a hot path.
  103. // Admin-only, like the other relation-management RPCs above (NOT gated
  104. // as a per-collection read on `child`, despite being read-only and
  105. // reporting facts about that collection's data): answering requires
  106. // resolving the relation first to learn its `child`, and gating after
  107. // that lookup would make a nonexistent-relation response distinguishable
  108. // from an existing-but-unauthorized one - a probe-able existence oracle,
  109. // which is exactly what gate() exists to prevent elsewhere.
  110. rpc CheckRelation(CheckRelationRequest) returns (CheckRelationResponse);
  111. // Collection configuration
  112. rpc ConfigureCollection(ConfigureCollectionRequest) returns (ConfigureCollectionResponse);
  113. // v2.9.0 — secondary indexes. Declaration is explicit per collection: an
  114. // index costs write throughput, and indexing every field would build useless
  115. // ones (a low-cardinality field like a status enum is slower through an
  116. // index than a scan).
  117. rpc CreateIndex(CreateIndexRequest) returns (CreateIndexResponse);
  118. rpc DropIndex(DropIndexRequest) returns (DropIndexResponse);
  119. rpc ListIndexes(ListIndexesRequest) returns (ListIndexesResponse);
  120. // v2.10.0 — the distinct values an indexed field holds, with row counts.
  121. // Answered from the index, one step per distinct value rather than per row.
  122. rpc GetIndexValues(GetIndexValuesRequest) returns (GetIndexValuesResponse);
  123. rpc GetCollectionConfig(GetCollectionConfigRequest) returns (GetCollectionConfigResponse);
  124. rpc MigrateCollectionTimestamps(MigrateCollectionTimestampsRequest) returns (MigrateCollectionTimestampsResponse);
  125. // File operations
  126. rpc UploadFile(stream FileChunk) returns (UploadFileResponse);
  127. rpc DownloadFile(DownloadFileRequest) returns (stream FileChunk);
  128. rpc DeleteFile(DeleteFileRequest) returns (DeleteFileResponse);
  129. rpc GetFileInfo(GetFileInfoRequest) returns (FileInfo);
  130. rpc ListFiles(ListFilesRequest) returns (ListFilesResponse);
  131. rpc SetFileTtl(SetFileTtlRequest) returns (SetFileTtlResponse);
  132. // Event subscription
  133. rpc Subscribe(SubscribeRequest) returns (stream DatabaseEvent);
  134. // Health and stats
  135. rpc HealthCheck(HealthCheckRequest) returns (HealthCheckResponse);
  136. rpc GetStats(GetStatsRequest) returns (GetStatsResponse);
  137. rpc GetMemoryStats(GetMemoryStatsRequest) returns (GetMemoryStatsResponse);
  138. // Read-only runtime state control
  139. rpc SetReadOnly(SetReadOnlyRequest) returns (SetReadOnlyResponse);
  140. rpc GetReadOnlyStatus(GetReadOnlyStatusRequest) returns (GetReadOnlyStatusResponse);
  141. }
  142. // ===== Replication Service =====
  143. service DatabaseReplication {
  144. // Bidirectional streaming for real-time sync
  145. rpc SyncStream(stream ReplicationMessage) returns (stream ReplicationMessage);
  146. // Pull missed entries (for recovery)
  147. rpc GetEntriesSince(GetEntriesRequest) returns (stream ReplicationEntry);
  148. // Get current node state
  149. rpc GetNodeState(GetNodeStateRequest) returns (NodeState);
  150. }
  151. // ===== Document Types =====
  152. message Document {
  153. string id = 1;
  154. string collection = 2;
  155. bytes data = 3; // JSON-encoded document data
  156. uint64 version = 4;
  157. uint64 created_at = 5; // Timestamp in milliseconds
  158. uint64 updated_at = 6;
  159. uint64 expires_at = 7; // 0 = no expiration
  160. string node_id = 8; // Origin node for replication
  161. bool encrypted = 9;
  162. repeated string encrypted_fields = 10;
  163. string created_by = 11; // User ID who created the document
  164. string updated_by = 12; // User ID who last updated the document
  165. }
  166. // ===== Document Operations =====
  167. message InsertRequest {
  168. string collection = 1;
  169. bytes data = 2; // JSON document
  170. string id = 3; // Optional, auto-generated if empty
  171. uint32 ttl_seconds = 4; // 0 = use collection default
  172. string actor = 5; // User ID performing the operation (for audit)
  173. }
  174. message InsertResponse {
  175. string id = 1;
  176. uint64 version = 2;
  177. }
  178. message GetRequest {
  179. string collection = 1;
  180. string id = 2;
  181. }
  182. message GetResponse {
  183. Document document = 1;
  184. bool found = 2;
  185. }
  186. message UpdateRequest {
  187. string collection = 1;
  188. string id = 2;
  189. bytes data = 3;
  190. uint64 expected_version = 4; // 0 = no version check (force update)
  191. string actor = 5; // User ID performing the operation (for audit)
  192. // v2.8.0 — change the document's expiry as part of the update.
  193. //
  194. // `optional` gives three distinct meanings, which a plain uint32 cannot:
  195. // absent -> leave the existing expiry alone (the default, and what an
  196. // update did implicitly once it stopped WIPING the expiry)
  197. // 0 -> clear the expiry: the document becomes permanent
  198. // N -> expire N seconds from now
  199. //
  200. // Before this, ttl_seconds existed only on Insert/Upsert/BatchInsert, so
  201. // changing a TTL meant rewriting the whole document via upsert.
  202. optional uint32 ttl_seconds = 6;
  203. }
  204. message UpdateResponse {
  205. uint64 new_version = 1;
  206. bool success = 2;
  207. string error = 3;
  208. // v2.12.0 - when success=false, the gRPC status code this refusal WOULD
  209. // carry: NOT_FOUND, ABORTED (version conflict), FAILED_PRECONDITION
  210. // (read-only), RESOURCE_EXHAUSTED (memory pressure), INVALID_ARGUMENT
  211. // (write to a view). These refusals stay in-band (status OK) so clients
  212. // older than 2.12.0 see exactly what they always saw; 0 from an older
  213. // server. The trailing `sbdb-error-detail-bin` adds the reason.
  214. int32 error_code = 4;
  215. }
  216. message UpsertRequest {
  217. string collection = 1;
  218. bytes data = 2;
  219. string id = 3;
  220. uint32 ttl_seconds = 4;
  221. string actor = 5; // User ID performing the operation (for audit)
  222. }
  223. message UpsertResponse {
  224. string id = 1;
  225. uint64 version = 2;
  226. bool inserted = 3; // true if inserted, false if updated
  227. }
  228. message DeleteRequest {
  229. string collection = 1;
  230. string id = 2;
  231. // v2.12.0 - who is deleting, as `actor` is on every other write. Reported
  232. // on the resulting DatabaseEvent (and on the events of any documents a
  233. // relation cascade deletes or nulls because of it). Not stored: the
  234. // document is gone, and its last version in history keeps the updated_by
  235. // of whoever last WROTE it, which is not who deleted it.
  236. string actor = 3;
  237. }
  238. message DeleteResponse {
  239. bool deleted = 1;
  240. }
  241. message PatchDocumentRequest {
  242. string collection = 1;
  243. string id = 2;
  244. bytes patch_json = 3; // JSON fields to merge into existing document
  245. string actor = 4; // User ID performing the operation (for audit)
  246. // v2.8.0 — same three-way semantics as UpdateRequest.ttl_seconds: absent
  247. // leaves the expiry alone, 0 clears it, N sets N seconds from now.
  248. optional uint32 ttl_seconds = 5;
  249. // v2.12.0 - apply only if the document is still at this version: a
  250. // conditional PARTIAL update. updateIfVersion replaces the whole body, so a
  251. // caller that only wants to change one field ("claim this task") would
  252. // have to write back everything it read, reverting any field a concurrent
  253. // writer changed meanwhile. A mismatch is refused with status ABORTED,
  254. // reason "version_conflict" and the current version in the detail.
  255. // Absent = unconditional, as before.
  256. optional uint64 expected_version = 6;
  257. // v2.12.0 - ATOMIC INCREMENT. A JSON object of field -> number to add, in
  258. // the same locked read-modify-write as the merge, so concurrent increments
  259. // never lose an update. Dotted paths descend objects (creating them).
  260. // - an absent or null field counts as 0;
  261. // - integer + integer stays an integer (overflow is refused), anything
  262. // else is a double;
  263. // - a non-numeric stored value, a non-numeric delta, or a field that
  264. // patch_json also sets is refused with INVALID_ARGUMENT, reason
  265. // "invalid_increment", and the field in the detail.
  266. // Nothing is written when any increment is refused. patch_json may be
  267. // empty when only incrementing. The new values come back in
  268. // PatchDocumentResponse.incremented_json.
  269. bytes increments_json = 7;
  270. }
  271. message PatchDocumentResponse {
  272. uint64 new_version = 1;
  273. bool success = 2;
  274. string error = 3;
  275. // v2.12.0 - as UpdateResponse.error_code.
  276. int32 error_code = 4;
  277. // v2.12.0 - JSON object, field -> value AFTER the increments, for every
  278. // field in increments_json. Empty when there were none.
  279. bytes incremented_json = 5;
  280. }
  281. message ExistsRequest {
  282. string collection = 1;
  283. string id = 2;
  284. }
  285. message ExistsResponse {
  286. bool exists = 1;
  287. }
  288. // ===== Version History Operations =====
  289. message DocumentVersionEntry {
  290. uint64 version = 1;
  291. bytes data = 2; // JSON-encoded document data at this version
  292. uint64 timestamp = 3; // When this version was created (updatedAt)
  293. string updated_by = 4;
  294. bool encrypted = 5;
  295. repeated string encrypted_fields = 6;
  296. }
  297. message GetVersionHistoryRequest {
  298. string collection = 1;
  299. string id = 2;
  300. uint32 limit = 3; // 0 = all versions
  301. uint32 offset = 4;
  302. }
  303. message GetVersionHistoryResponse {
  304. repeated DocumentVersionEntry versions = 1;
  305. uint64 current_version = 2; // 0 if document is deleted
  306. uint64 total_count = 3;
  307. bool document_deleted = 4;
  308. }
  309. message GetDocumentVersionRequest {
  310. string collection = 1;
  311. string id = 2;
  312. uint64 version = 3;
  313. }
  314. message GetDocumentVersionResponse {
  315. DocumentVersionEntry version_entry = 1;
  316. bool found = 2;
  317. }
  318. message RestoreVersionRequest {
  319. string collection = 1;
  320. string id = 2;
  321. uint64 version = 3; // Version number to restore
  322. string actor = 4; // User performing the restore
  323. }
  324. message RestoreVersionResponse {
  325. uint64 new_version = 1; // The newly created version number
  326. bool success = 2;
  327. string error = 3;
  328. }
  329. message RestoreToDateRequest {
  330. string collection = 1;
  331. string id = 2;
  332. uint64 timestamp = 3; // Find version active at this time (ms since epoch)
  333. string actor = 4;
  334. }
  335. message RestoreToDateResponse {
  336. uint64 restored_version = 1; // Which old version was restored from
  337. uint64 new_version = 2; // The newly created version number
  338. bool success = 3;
  339. string error = 4;
  340. }
  341. // ===== Batch Operations =====
  342. message BatchInsertRequest {
  343. string collection = 1;
  344. repeated BatchInsertItem items = 2;
  345. string actor = 3; // User ID performing the operation (for audit)
  346. }
  347. message BatchInsertItem {
  348. bytes data = 1;
  349. string id = 2;
  350. uint32 ttl_seconds = 3;
  351. }
  352. message BatchInsertResponse {
  353. repeated string ids = 1;
  354. uint32 success_count = 2;
  355. uint32 error_count = 3;
  356. }
  357. message BatchGetRequest {
  358. string collection = 1;
  359. repeated string ids = 2;
  360. }
  361. message BatchGetResponse {
  362. repeated Document documents = 1;
  363. }
  364. message BatchDeleteRequest {
  365. string collection = 1;
  366. repeated string ids = 2;
  367. string actor = 3; // v2.12.0 - as DeleteRequest.actor, for every id
  368. }
  369. message BatchDeleteResponse {
  370. uint64 deleted_count = 1;
  371. // v2.12.0 - the ids actually deleted, in request order. An id that is
  372. // absent here did not exist. If the call fails partway (a relation
  373. // refuses one id), the status is an error and no response is delivered:
  374. // ids before it may already be gone - re-read to learn which.
  375. repeated string deleted_ids = 2;
  376. }
  377. // ===== Query Operations =====
  378. message FindRequest {
  379. string collection = 1;
  380. repeated Filter filters = 2;
  381. Sort sort = 3;
  382. uint32 limit = 4; // Default 100
  383. uint32 offset = 5;
  384. repeated string projection = 6; // Fields to include (empty = all)
  385. }
  386. message Filter {
  387. string field = 1;
  388. FilterOp op = 2;
  389. bytes value = 3; // JSON-encoded value
  390. }
  391. enum FilterOp {
  392. FILTER_OP_UNSPECIFIED = 0;
  393. FILTER_OP_EQ = 1;
  394. FILTER_OP_NE = 2;
  395. FILTER_OP_GT = 3;
  396. FILTER_OP_GTE = 4;
  397. FILTER_OP_LT = 5;
  398. FILTER_OP_LTE = 6;
  399. FILTER_OP_IN = 7;
  400. FILTER_OP_CONTAINS = 8;
  401. FILTER_OP_EXISTS = 9;
  402. FILTER_OP_REGEX = 10;
  403. FILTER_OP_SEARCH = 11; // Full-text search across ID and string fields
  404. }
  405. message Sort {
  406. string field = 1;
  407. bool descending = 2;
  408. }
  409. message FindResponse {
  410. repeated Document documents = 1;
  411. uint64 total_count = 2;
  412. bool has_more = 3;
  413. // WAL fallback metrics (for queries that include evicted documents)
  414. bool used_wal_fallback = 4; // True if WAL was scanned for evicted docs
  415. uint32 memory_match_count = 5; // Documents matched from memory
  416. uint32 wal_match_count = 6; // Documents matched from WAL
  417. uint64 memory_search_micros = 7; // Time spent searching memory (µs)
  418. uint64 wal_search_micros = 8; // Time spent loading/searching WAL (µs)
  419. }
  420. message CountRequest {
  421. string collection = 1;
  422. repeated Filter filters = 2;
  423. }
  424. message CountResponse {
  425. uint64 count = 1;
  426. }
  427. message SimilaritySearchRequest {
  428. string collection = 1;
  429. repeated float query_vector = 2;
  430. uint32 top_k = 3;
  431. float min_score = 4;
  432. }
  433. message SimilaritySearchResponse {
  434. repeated SimilarityResult results = 1;
  435. }
  436. message SimilarityResult {
  437. string id = 1;
  438. float score = 2;
  439. bytes data = 3;
  440. }
  441. // ===== Set Operations =====
  442. message SetAddRequest {
  443. string collection = 1;
  444. string set_id = 2;
  445. string member = 3;
  446. }
  447. message SetAddResponse {
  448. bool added = 1; // false if already exists
  449. }
  450. message SetRemoveRequest {
  451. string collection = 1;
  452. string set_id = 2;
  453. string member = 3;
  454. }
  455. message SetRemoveResponse {
  456. bool removed = 1;
  457. }
  458. message SetMembersRequest {
  459. string collection = 1;
  460. string set_id = 2;
  461. }
  462. message SetMembersResponse {
  463. repeated string members = 1;
  464. }
  465. message SetIsMemberRequest {
  466. string collection = 1;
  467. string set_id = 2;
  468. string member = 3;
  469. }
  470. message SetIsMemberResponse {
  471. bool is_member = 1;
  472. }
  473. // ===== Collection Management =====
  474. message CreateCollectionRequest {
  475. string name = 1;
  476. CollectionOptions options = 2;
  477. }
  478. message CollectionOptions {
  479. bool auto_create_id = 1;
  480. uint32 default_ttl_seconds = 2;
  481. bool encrypted = 3;
  482. repeated string sensitive_fields = 4;
  483. uint32 max_versions = 5; // Max version history per document (0 = unlimited)
  484. uint32 vector_dimension = 6; // Dimension of vectors stored in this collection (0 = not a vector collection)
  485. // NEW in v1.7.0 — eviction priority for the collection.
  486. // UNSPECIFIED is treated as NORMAL for backward compatibility.
  487. MemoryPriority memory_priority = 7;
  488. }
  489. enum MemoryPriority {
  490. MEMORY_PRIORITY_UNSPECIFIED = 0; // treated as NORMAL
  491. MEMORY_PRIORITY_LOW = 1;
  492. MEMORY_PRIORITY_NORMAL = 2;
  493. MEMORY_PRIORITY_HIGH = 3;
  494. }
  495. message CreateCollectionResponse {
  496. bool created = 1;
  497. }
  498. message DropCollectionRequest {
  499. string name = 1;
  500. }
  501. message DropCollectionResponse {
  502. bool dropped = 1;
  503. }
  504. message ListCollectionsRequest {
  505. // v2.8.0 — restrict the listing to one project namespace, mirroring
  506. // ListViewsRequest. Empty lists every project (operator/CLI use); clients
  507. // always set it, so a workspace never sees another workspace's collection
  508. // names. A collection name is information about the shape of someone else's
  509. // data even when its contents are unreachable.
  510. string project = 1;
  511. }
  512. message ListCollectionsResponse {
  513. repeated string names = 1;
  514. }
  515. message GetCollectionInfoRequest {
  516. string name = 1;
  517. }
  518. message GetCollectionInfoResponse {
  519. CollectionInfo info = 1;
  520. bool found = 2;
  521. }
  522. // What a collection IS: its creation-time options and its size.
  523. //
  524. // Settings changeable after creation are NOT here - timestamp_precision,
  525. // versioning_enabled and relations_enforced are read with GetCollectionConfig
  526. // (see CollectionConfig), which always populates all three on a reply. Their
  527. // absence from this message does not mean they cannot be read.
  528. message CollectionInfo {
  529. string name = 1;
  530. uint64 document_count = 2;
  531. uint64 size_bytes = 3;
  532. CollectionOptions options = 4;
  533. uint64 created_at = 5;
  534. uint64 updated_at = 6;
  535. uint32 vector_dimension = 7; // Dimension of vectors stored in this collection (0 = not a vector collection)
  536. }
  537. // ===== Project Management (v2.3) =====
  538. //
  539. // Projects are top-level namespaces over collections. Collections live
  540. // inside a project; wire-form "my_app:users" addresses collection "users"
  541. // in project "my_app", bare "users" addresses ("default", "users"). The
  542. // "default" project is implicit and always present.
  543. //
  544. // Stage F ships the RPC surface backed by a filesystem-only placeholder
  545. // (`<dataDir>/projects/<name>/env/`). Stage B replaces the placeholder
  546. // with the real ProjectStore-backed implementation.
  547. message ListProjectsRequest {}
  548. message ListProjectsResponse {
  549. // Alphabetical. Always includes "default".
  550. repeated string projects = 1;
  551. }
  552. message CreateProjectRequest {
  553. string name = 1;
  554. }
  555. message CreateProjectResponse {
  556. // true = newly created, false = already existed (idempotent) OR validation error.
  557. bool created = 1;
  558. // Populated on validation failure (e.g. invalid name). Empty on success
  559. // and on the idempotent "already existed" path.
  560. string error = 2;
  561. }
  562. message DropProjectRequest {
  563. string name = 1;
  564. }
  565. message DropProjectResponse {
  566. bool dropped = 1;
  567. // Populated when the drop is refused — e.g. name == "default",
  568. // unknown project, or filesystem error.
  569. string error = 2;
  570. }
  571. // ===== File Operations =====
  572. message FileChunk {
  573. oneof content {
  574. FileMetadata metadata = 1; // First chunk includes metadata
  575. bytes data = 2; // Subsequent chunks are data
  576. }
  577. }
  578. message FileMetadata {
  579. string id = 1; // Set by server on upload response
  580. string name = 2;
  581. string mime_type = 3;
  582. uint64 size = 4;
  583. string file_type = 5; // "plugin", "document", "generated"
  584. string related_id = 6; // plugin_id, conversation_id, etc.
  585. map<string, string> metadata = 7; // Custom metadata
  586. bool is_public = 8; // Visibility flag
  587. // v2.6.0 — owning project. Empty means "default", matching the rule for
  588. // bare collection names. Files are namespaced so that per-project access
  589. // policy has something to attach to.
  590. string project = 9;
  591. // v2.8.0 — relative time-to-live in seconds, applied at upload. Converted
  592. // once to an absolute expiry server-side, so a file's lifetime does not
  593. // restart when it is read or on restart.
  594. //
  595. // `optional` is load-bearing: ABSENT means "inherit the configured default
  596. // for this file type", while an explicitly SET 0 means "never expire" and
  597. // overrides that default. A plain uint32 cannot express the difference,
  598. // which would make it impossible to opt one file out of a retention policy.
  599. optional uint32 ttl_seconds = 10;
  600. }
  601. message UploadFileResponse {
  602. string id = 1;
  603. uint64 size = 2;
  604. string checksum = 3; // SHA-256
  605. bool deduplicated = 4; // True if blob already existed
  606. }
  607. message DownloadFileRequest {
  608. string id = 1;
  609. string project = 2; // v2.6.0 — empty means "default"
  610. }
  611. message DeleteFileRequest {
  612. string id = 1;
  613. string project = 2; // v2.6.0 — empty means "default"
  614. }
  615. message DeleteFileResponse {
  616. bool deleted = 1;
  617. }
  618. message GetFileInfoRequest {
  619. string id = 1;
  620. string project = 2; // v2.6.0 — empty means "default"
  621. }
  622. message FileInfo {
  623. string id = 1;
  624. string name = 2;
  625. string mime_type = 3;
  626. uint64 size = 4;
  627. string file_type = 5;
  628. string related_id = 6;
  629. string checksum = 7;
  630. uint64 created_at = 8;
  631. map<string, string> metadata = 9;
  632. bool is_public = 10; // Visibility flag
  633. uint32 ref_count = 11; // Blob reference count (informational)
  634. string project = 12; // v2.6.0 — owning project
  635. uint64 expires_at = 13; // v2.8.0 — absolute expiry ms, 0 = never
  636. }
  637. message ListFilesRequest {
  638. string file_type = 1; // Filter by type (optional)
  639. string related_id = 2; // Filter by related ID (optional)
  640. uint32 limit = 3;
  641. uint32 offset = 4;
  642. string checksum = 5; // Filter by checksum (for dedup queries)
  643. string name = 6; // Filter by exact filename (optional)
  644. string project = 7; // v2.6.0 — empty means "default"
  645. }
  646. // v2.8.0 — change the expiry of a file that is already stored. A file's TTL was
  647. // otherwise fixed at upload.
  648. message SetFileTtlRequest {
  649. string id = 1;
  650. string project = 2; // empty means "default"
  651. // Absent is invalid here - the call exists to change the expiry, so it must
  652. // say what to. 0 clears the expiry (keep indefinitely); N expires the file N
  653. // seconds from now.
  654. uint32 ttl_seconds = 3;
  655. }
  656. message SetFileTtlResponse {
  657. bool updated = 1; // false if no such file in that project
  658. uint64 expires_at = 2; // the resulting absolute expiry, 0 = never
  659. }
  660. message ListFilesResponse {
  661. repeated FileInfo files = 1;
  662. uint64 total_count = 2;
  663. bool has_more = 3;
  664. }
  665. // ===== Event Subscription =====
  666. message SubscribeRequest {
  667. repeated string collections = 1; // Empty = all collections
  668. repeated string patterns = 2; // Glob patterns (e.g., "assistants:*")
  669. bool include_data = 3; // Include document data in events
  670. }
  671. message DatabaseEvent {
  672. EventType type = 1;
  673. string collection = 2;
  674. string document_id = 3;
  675. uint64 timestamp = 4;
  676. string node_id = 5;
  677. bytes data = 6; // JSON document (if include_data)
  678. // v2.12.0 - who caused this change: the `actor` the write or delete
  679. // request carried. Empty when the request carried none, and for changes
  680. // the database makes itself (TTL expiry). Sent whether or not
  681. // include_data is set.
  682. //
  683. // For a document a relation cascade deleted or nulled, it is the actor of
  684. // the delete that triggered the cascade - the cascade is that caller's
  685. // doing, not whoever last wrote the child.
  686. //
  687. // This is what makes a write-triggered-write loop guard possible: a
  688. // subscriber that reacts to events by writing can tag its own writes and
  689. // recognise them here. Before this an event said nothing about its
  690. // origin; insert/update provenance had to be read back from version
  691. // history after the fact (racing any later write), and a delete's was not
  692. // recorded anywhere.
  693. string actor = 7;
  694. }
  695. enum EventType {
  696. EVENT_UNKNOWN = 0;
  697. EVENT_INSERT = 1;
  698. EVENT_UPDATE = 2;
  699. EVENT_DELETE = 3;
  700. EVENT_EXPIRE = 4;
  701. EVENT_INVALIDATE = 5;
  702. // NEW in v1.7.0 — memory-pressure observability events.
  703. EVENT_MEMORY_PRESSURE_HIGH = 6; // Emitted when pressure reaches hard threshold
  704. EVENT_MEMORY_EVICTION_BURST = 7; // Emitted when eviction runs a large burst
  705. }
  706. // ===== Replication =====
  707. message ReplicationEntry {
  708. uint64 sequence = 1;
  709. uint64 global_timestamp = 2;
  710. string node_id = 3;
  711. OperationType op = 4;
  712. string collection = 5;
  713. string document_id = 6;
  714. uint64 document_version = 7;
  715. bytes data = 8;
  716. }
  717. enum OperationType {
  718. OP_UNKNOWN = 0;
  719. OP_INSERT = 1;
  720. OP_UPDATE = 2;
  721. OP_DELETE = 3;
  722. OP_UPSERT = 4;
  723. OP_CREATE_COLLECTION = 5;
  724. OP_DROP_COLLECTION = 6;
  725. }
  726. message ReplicationMessage {
  727. oneof content {
  728. ReplicationEntry entry = 1;
  729. Heartbeat heartbeat = 2;
  730. WatermarkUpdate watermark = 3;
  731. SyncRequest sync_request = 4;
  732. }
  733. }
  734. message Heartbeat {
  735. string node_id = 1;
  736. uint64 timestamp = 2;
  737. uint64 sequence = 3;
  738. }
  739. message WatermarkUpdate {
  740. string node_id = 1;
  741. uint64 sequence = 2;
  742. }
  743. message SyncRequest {
  744. uint64 from_sequence = 1;
  745. }
  746. message GetEntriesRequest {
  747. uint64 from_sequence = 1;
  748. uint32 limit = 2;
  749. }
  750. message GetNodeStateRequest {
  751. }
  752. message NodeState {
  753. string node_id = 1;
  754. uint64 current_sequence = 2;
  755. map<string, uint64> peer_watermarks = 3;
  756. uint64 document_count = 4;
  757. repeated string collections = 5;
  758. bool healthy = 6;
  759. // Per-collection sequence tracking for collection discovery
  760. map<string, uint64> collection_sequences = 7;
  761. }
  762. // ===== Health and Stats =====
  763. message HealthCheckRequest {
  764. }
  765. message HealthCheckResponse {
  766. bool healthy = 1;
  767. uint64 uptime_seconds = 2;
  768. uint64 document_count = 3;
  769. uint64 memory_used_bytes = 4;
  770. uint64 wal_size_bytes = 5;
  771. repeated PeerHealth peers = 6;
  772. }
  773. message PeerHealth {
  774. string node_id = 1;
  775. bool connected = 2;
  776. uint64 latency_ms = 3;
  777. uint64 lag_entries = 4;
  778. }
  779. message GetStatsRequest {
  780. }
  781. message GetStatsResponse {
  782. uint64 total_documents = 1;
  783. uint64 total_collections = 2;
  784. uint64 memory_used_bytes = 3;
  785. uint64 wal_sequence = 4;
  786. uint64 wal_size_bytes = 5;
  787. uint64 snapshot_count = 6;
  788. uint64 last_snapshot_sequence = 7;
  789. uint64 insert_count = 8;
  790. uint64 update_count = 9;
  791. uint64 delete_count = 10;
  792. uint64 query_count = 11;
  793. // Memory eviction stats
  794. uint64 evicted_documents = 12; // Documents currently evicted to disk
  795. uint64 total_evictions = 13; // Total eviction operations performed
  796. uint64 recovery_count = 14; // Documents recovered from eviction
  797. // Memory configuration
  798. uint64 max_memory_bytes = 15; // Configured max memory limit
  799. uint32 eviction_threshold_percent = 16; // Start evicting at this % of max
  800. uint32 eviction_target_percent = 17; // Evict down to this % of max
  801. // Operation timing (microseconds) - for performance monitoring
  802. uint64 get_count = 18; // Number of get operations
  803. uint64 get_total_micros = 19; // Total time spent in get operations
  804. uint64 get_max_micros = 20; // Max single get operation time
  805. uint64 insert_total_micros = 21;
  806. uint64 insert_max_micros = 22;
  807. uint64 update_total_micros = 23;
  808. uint64 update_max_micros = 24;
  809. uint64 query_total_micros = 25;
  810. uint64 query_max_micros = 26;
  811. }
  812. // ===== View Operations =====
  813. message ViewDefinition {
  814. string name = 1; // view name (globally unique, cannot start with _)
  815. string collection = 2; // target real collection (must NOT be another view)
  816. repeated string include = 3; // field paths to include (dot-notation for nested)
  817. repeated string exclude = 4; // field paths to exclude (ignored if include is non-empty)
  818. repeated Filter where = 5; // baked-in filters (AND-merged with caller filters)
  819. Sort default_sort = 6; // baked-in default sort (used when caller doesn't specify)
  820. uint64 created_at = 7;
  821. uint64 updated_at = 8;
  822. }
  823. message CreateViewRequest {
  824. string name = 1;
  825. string collection = 2;
  826. repeated string include = 3;
  827. repeated string exclude = 4;
  828. repeated Filter where = 5;
  829. Sort default_sort = 6;
  830. }
  831. message CreateViewResponse {
  832. bool success = 1;
  833. string error = 2;
  834. }
  835. message DropViewRequest {
  836. string name = 1;
  837. }
  838. message DropViewResponse {
  839. bool success = 1;
  840. string error = 2;
  841. }
  842. message ListViewsRequest {
  843. // Restrict the listing to one project namespace. Empty lists every
  844. // project (operator/CLI use). Clients always set it so a workspace
  845. // never sees another workspace's views.
  846. string project = 1;
  847. }
  848. message ListViewsResponse {
  849. repeated ViewDefinition views = 1;
  850. }
  851. message GetViewInfoRequest {
  852. string name = 1;
  853. }
  854. message GetViewInfoResponse {
  855. ViewDefinition view = 1;
  856. bool found = 2;
  857. }
  858. // ===== Relation (Referential Integrity) Operations — v2.11.0 T6b =====
  859. //
  860. // A relation says: documents in `child` reference documents in `parent`
  861. // through `child_field` (a dot-path that may resolve to a single id or an
  862. // array of ids). Declarations are persisted in the global `_relations`
  863. // system collection (mirrors `_views`) and are project-qualified like any
  864. // other collection-carrying name. Management is admin-only.
  865. message RelationDefinition {
  866. string name = 1; // relation name, project-qualified
  867. string child = 2; // collection holding the reference, project-qualified
  868. string child_field = 3; // dot-path on the child; may resolve to an array of ids
  869. string parent = 4; // collection being referenced, project-qualified
  870. // "restrict" (default) | "cascade" | "set_null" | "no_action".
  871. //
  872. // ALL FOUR ARE ENFORCED as of v2.11.0, and an unrecognised value is
  873. // REFUSED by CreateRelation rather than coerced to "restrict".
  874. // restrict - the parent delete fails FAILED_PRECONDITION while any
  875. // child still references it.
  876. // cascade - DESTRUCTIVE: children referencing the parent are deleted
  877. // atomically with it. If child_field resolves to an ARRAY,
  878. // the parent id is pulled from the array and the child is
  879. // KEPT (cascade and set_null collapse there). Refused if a
  880. // child is itself protected by its own restrict relation.
  881. // Not recursive.
  882. // set_null - DESTRUCTIVE: the child's reference field is set to null
  883. // and the child is kept. Arrays behave as under cascade.
  884. // no_action - the delete proceeds, the reference is left dangling.
  885. string on_delete = 5;
  886. // ENFORCED as of v2.11.0: a write to the child naming a parent that does
  887. // not exist is rejected with FAILED_PRECONDITION. An empty-string
  888. // reference is a hard rejection.
  889. bool validate_on_write = 6;
  890. uint64 created_at = 7;
  891. uint64 updated_at = 8;
  892. }
  893. message CreateRelationRequest {
  894. string name = 1;
  895. string child = 2;
  896. string child_field = 3;
  897. string parent = 4;
  898. string on_delete = 5; // empty defaults to "restrict"
  899. bool validate_on_write = 6;
  900. }
  901. message CreateRelationResponse {
  902. bool success = 1;
  903. string error = 2;
  904. // v2.11.0 T7 — rows indexed by the bootstrap scan. Declaring a relation
  905. // over a collection that already has rows backfills the reverse index
  906. // immediately (mirrors CreateIndexResponse.rows_indexed), so enforcement
  907. // covers pre-existing children from the moment the relation is declared,
  908. // not only writes made afterwards.
  909. uint64 rows_indexed = 3;
  910. }
  911. message DropRelationRequest {
  912. string name = 1;
  913. }
  914. message DropRelationResponse {
  915. bool success = 1;
  916. string error = 2;
  917. }
  918. message ListRelationsRequest {
  919. // Restrict the listing to one project namespace. Empty lists every
  920. // project (operator/CLI use). Clients always send their own project so
  921. // one workspace never enumerates another's relations.
  922. string project = 1;
  923. }
  924. message ListRelationsResponse {
  925. repeated RelationDefinition relations = 1;
  926. }
  927. message GetRelationInfoRequest {
  928. string name = 1;
  929. }
  930. message GetRelationInfoResponse {
  931. RelationDefinition relation = 1;
  932. bool found = 2;
  933. }
  934. // v2.11.0 T5 — "what would happen if I deleted this?", answered without
  935. // deleting anything. A relational database exposes its constraints through
  936. // DDL you can read; a document store has none, so this has to be a query.
  937. // Gated as an ordinary READ on `collection` (it changes nothing), unlike
  938. // the relation-management RPCs above which are admin-only.
  939. message DescribeDeleteRequest {
  940. string collection = 1;
  941. string id = 2;
  942. }
  943. message RelationImpact {
  944. string relation = 1;
  945. string child_collection = 2;
  946. string child_field = 3;
  947. string on_delete = 4; // restrict | cascade | set_null | no_action
  948. uint64 child_count = 5;
  949. repeated string sample_child_ids = 6; // at most five
  950. bool blocks = 7;
  951. }
  952. message DescribeDeleteResponse {
  953. bool success = 1;
  954. string error = 2;
  955. bool would_be_blocked = 3;
  956. repeated RelationImpact impacts = 4;
  957. }
  958. // v2.11.0 T7 — the bootstrap-scan gap. Declaring a relation with T3 alone
  959. // only maintains the reverse index going FORWARD from writes made after
  960. // declaration; rows already in the child collection were never indexed, so
  961. // enforcement silently missed them. This RPC answers "is that still true
  962. // right now, for this relation" without changing anything.
  963. message CheckRelationRequest {
  964. string name = 1; // relation name, project-qualified like the others
  965. }
  966. // One parent id referenced by the child collection's data, whose parent
  967. // document does not exist.
  968. message DanglingReference {
  969. string parent_id = 1;
  970. uint64 child_count = 2; // children of this parent, from the index
  971. repeated string sample_child_ids = 3; // at most five
  972. }
  973. message CheckRelationResponse {
  974. bool success = 1;
  975. string error = 2;
  976. // Every dangling parent id found, not just the reported sample - so a
  977. // capped `dangling` list below does not silently understate the problem.
  978. uint64 total_dangling = 3;
  979. // Capped (see the server implementation) so a badly out-of-sync relation
  980. // cannot blow up the response size; total_dangling is the true count.
  981. repeated DanglingReference dangling = 4;
  982. }
  983. // ===== Collection Configuration =====
  984. // Per-collection configuration for timestamp precision and other runtime knobs.
  985. // Stored in the _collection_meta system collection.
  986. message CollectionConfig {
  987. // "ms" (default) — _created_at/_updated_at stamped in milliseconds since epoch
  988. // "ns" — _created_at/_updated_at stamped in nanoseconds since epoch
  989. // Empty on a ConfigureCollection request means "leave unchanged".
  990. string timestamp_precision = 1;
  991. // v2.4.5 — version history on/off for an EXISTING collection.
  992. //
  993. // `optional` (proto3 field presence) is load-bearing, not decoration: a
  994. // plain bool defaults to false, so any ConfigureCollection call that meant
  995. // to set only timestamp_precision would silently switch versioning OFF.
  996. // With presence, an absent field means "leave unchanged" and the server
  997. // overlays only what the caller actually set.
  998. //
  999. // Disabling stops NEW versions being recorded; history already on disk
  1000. // stays readable, so this is reversible. Distinct from max_versions=0,
  1001. // which means "unlimited", not "off".
  1002. optional bool versioning_enabled = 2;
  1003. // v2.11.0 T8 — whether declared relations are enforced for this collection.
  1004. //
  1005. // `optional` for the same reason versioning_enabled is: a plain bool
  1006. // defaults to false, so a ConfigureCollection call that meant to set
  1007. // only timestamp_precision would silently switch relation enforcement
  1008. // OFF. With presence, an absent field means "leave unchanged".
  1009. //
  1010. // Defaults to true (enforced) when never explicitly configured -
  1011. // declaring a relation names its child and parent explicitly, so the
  1012. // declaration IS the opt-in.
  1013. optional bool relations_enforced = 3;
  1014. // Room for future per-collection knobs
  1015. }
  1016. message ConfigureCollectionRequest {
  1017. string collection = 1;
  1018. CollectionConfig config = 2;
  1019. }
  1020. message ConfigureCollectionResponse {
  1021. bool success = 1;
  1022. string error = 2;
  1023. }
  1024. // v2.9.0 — secondary index management.
  1025. message CreateIndexRequest {
  1026. // Project-qualified collection name, as every other collection-carrying
  1027. // request takes.
  1028. string collection = 1;
  1029. // Field to index. Dotted paths address nested fields ("nest.deep"), and the
  1030. // document metadata fields (_id, _created_at, _updated_at, _version) are
  1031. // addressable too.
  1032. string field = 2;
  1033. // v2.11.0 T11 — when true, the field carries a UNIQUE constraint: two
  1034. // documents may never hold the same value for it. Declaring this over a
  1035. // collection that already contains duplicate values is REFUSED (see
  1036. // CreateIndexResponse.duplicate_examples) rather than accepted and left
  1037. // silently unenforced against the data that already violates it.
  1038. //
  1039. // v2.12.0 - NULL IS NOT A VALUE for uniqueness: any number of documents
  1040. // may hold null (or omit the field), as in SQL. Before 2.12.0 two nulls
  1041. // collided while two absent fields did not.
  1042. bool unique = 3;
  1043. // v2.12.0 - a COMPOSITE unique constraint over the TUPLE of these fields
  1044. // (two or more; `field` must then be empty and `unique` true). Two
  1045. // documents may not hold the same combination. A document in which any
  1046. // of the fields is absent, null, an object or an array is not constrained
  1047. // - the SQL rule for a NULL in a unique key. Composite constraints back no
  1048. // query (the planner never uses them) and are listed by ListIndexes with
  1049. // `fields` set. Declaring one over existing duplicates is refused with
  1050. // examples, as for a single field.
  1051. repeated string fields = 4;
  1052. }
  1053. message CreateIndexResponse {
  1054. bool success = 1;
  1055. string error = 2;
  1056. // Rows indexed by the backfill. Creating an index over an existing
  1057. // collection populates it, so it is usable immediately rather than only for
  1058. // rows written afterwards.
  1059. uint64 rows_indexed = 3;
  1060. // True when the index already existed - creation is idempotent.
  1061. bool already_existed = 4;
  1062. // v2.11.0 T11 — set when a `unique=true` request was refused because the
  1063. // field already holds duplicate values. `error` explains the refusal;
  1064. // these are up to five example document ids that collide, one entry per
  1065. // colliding value, so the caller can go fix the data rather than guess.
  1066. repeated string duplicate_examples = 5;
  1067. }
  1068. message DropIndexRequest {
  1069. string collection = 1;
  1070. string field = 2;
  1071. // v2.12.0 - drop the composite unique constraint over exactly these
  1072. // fields, in the order they were declared. `field` must then be empty.
  1073. repeated string fields = 3;
  1074. }
  1075. message DropIndexResponse {
  1076. bool success = 1;
  1077. string error = 2;
  1078. }
  1079. message ListIndexesRequest {
  1080. string collection = 1;
  1081. }
  1082. message IndexInfo {
  1083. string field = 1;
  1084. // Distinct values held, and total postings. Both come from the index itself
  1085. // rather than a scan, so an operator can judge selectivity - a field whose
  1086. // postings are concentrated in few values will not be used by the planner.
  1087. uint64 distinct_values = 2;
  1088. uint64 entries = 3;
  1089. // v2.11.0 T11 — true when this index also carries a UNIQUE constraint.
  1090. bool unique = 4;
  1091. // v2.12.0 - set for a COMPOSITE unique constraint: its fields, in order.
  1092. // `field` then holds a display form ("a+b") and `unique` is true.
  1093. repeated string fields = 5;
  1094. }
  1095. message ListIndexesResponse {
  1096. bool success = 1;
  1097. string error = 2;
  1098. repeated IndexInfo indexes = 3;
  1099. }
  1100. message GetIndexValuesRequest {
  1101. string collection = 1;
  1102. string field = 2;
  1103. // Bounded on purpose: reading the values costs one document read each.
  1104. uint32 limit = 3;
  1105. // false walks from the highest value down, so limit=1 gives the maximum.
  1106. bool ascending = 4;
  1107. }
  1108. message IndexValueCount {
  1109. // The value as stored, JSON-encoded.
  1110. string value = 1;
  1111. uint64 count = 2;
  1112. }
  1113. message GetIndexValuesResponse {
  1114. bool success = 1;
  1115. string error = 2;
  1116. repeated IndexValueCount values = 3;
  1117. }
  1118. message GetCollectionConfigRequest {
  1119. string collection = 1;
  1120. }
  1121. message GetCollectionConfigResponse {
  1122. CollectionConfig config = 1;
  1123. bool found = 2;
  1124. }
  1125. message MigrateCollectionTimestampsRequest {
  1126. string collection = 1;
  1127. string from_precision = 2; // "ms" or "ns"
  1128. string to_precision = 3; // "ms" or "ns"
  1129. }
  1130. message MigrateCollectionTimestampsResponse {
  1131. bool success = 1;
  1132. string error = 2;
  1133. uint64 rows_migrated = 3; // how many documents had their timestamps updated
  1134. uint64 rows_skipped = 4; // already in target range (idempotent resume)
  1135. }
  1136. // ===== Read-Only Control =====
  1137. message SetReadOnlyRequest {
  1138. bool read_only = 1;
  1139. }
  1140. message SetReadOnlyResponse {
  1141. bool success = 1;
  1142. bool was_read_only = 2; // previous state
  1143. string error = 3;
  1144. }
  1145. message GetReadOnlyStatusRequest {}
  1146. message GetReadOnlyStatusResponse {
  1147. bool read_only = 1;
  1148. string reason = 2;
  1149. // Recovery outcome details (populated when auto-readonly triggered)
  1150. string recovery_outcome = 3; // "trivial_success" | "fresh_install" | "snapshot_fell_back" | "wal_only_replay" | "forced_empty" | "failed"
  1151. string expected_snapshot = 4;
  1152. string snapshot_used = 5;
  1153. string failure_reason = 6;
  1154. uint64 wal_entries_replayed = 7;
  1155. uint32 snapshots_attempted = 8;
  1156. }
  1157. // ===== Memory Stats =====
  1158. // Added in v1.7.0. Wire-compatible — server-side implementation lands in T9.
  1159. message GetMemoryStatsRequest {}
  1160. message CollectionMemoryStats {
  1161. string collection = 1;
  1162. uint64 document_count = 2;
  1163. uint64 estimated_bytes = 3;
  1164. uint64 evicted_stub_count = 4;
  1165. MemoryPriority priority = 5;
  1166. }
  1167. message GetMemoryStatsResponse {
  1168. uint64 total_memory_bytes = 1;
  1169. uint64 max_memory_bytes = 2;
  1170. uint32 pressure_percent = 3; // current usage / max × 100
  1171. string pressure_level = 4; // "normal" | "soft" | "hard" | "emergency"
  1172. repeated CollectionMemoryStats collections = 5;
  1173. // Most recent eviction
  1174. uint64 last_eviction_timestamp = 6; // ms since epoch, 0 if none
  1175. uint64 last_eviction_docs = 7;
  1176. uint64 last_eviction_bytes_freed = 8;
  1177. // v2.11.0 — TTL expiries a relation is refusing.
  1178. //
  1179. // ttl_blocked_documents is a GAUGE: how many documents are past their TTL
  1180. // right now and NOT being expired because deleting them would break a
  1181. // `restrict` relation (or because the cascade path is refusing while the
  1182. // LMDB mirror is unhealthy/drifted). It falls when a block lifts. Nonzero
  1183. // means those documents are outliving their retention policy - the
  1184. // deliberate alternative to silently orphaning their children.
  1185. //
  1186. // ttl_expiry_blocked_events is a monotonic COUNTER of refusal events, so it
  1187. // keeps rising while a block persists (each blocked document is retried on a
  1188. // slow cadence). Use the gauge for "how bad is it now", the counter for
  1189. // "is this still happening".
  1190. //
  1191. // Both are zero on any install that declares no relations.
  1192. uint64 ttl_blocked_documents = 9;
  1193. uint64 ttl_expiry_blocked_events = 10;
  1194. }