database.proto 48 KB

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