database.proto 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  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. service DatabaseService {
  19. // Document operations
  20. rpc Insert(InsertRequest) returns (InsertResponse);
  21. rpc Get(GetRequest) returns (GetResponse);
  22. rpc Update(UpdateRequest) returns (UpdateResponse);
  23. rpc Upsert(UpsertRequest) returns (UpsertResponse);
  24. rpc Delete(DeleteRequest) returns (DeleteResponse);
  25. rpc PatchDocument(PatchDocumentRequest) returns (PatchDocumentResponse);
  26. rpc Exists(ExistsRequest) returns (ExistsResponse);
  27. // Version history operations
  28. rpc GetVersionHistory(GetVersionHistoryRequest) returns (GetVersionHistoryResponse);
  29. rpc GetDocumentVersion(GetDocumentVersionRequest) returns (GetDocumentVersionResponse);
  30. rpc RestoreVersion(RestoreVersionRequest) returns (RestoreVersionResponse);
  31. rpc RestoreToDate(RestoreToDateRequest) returns (RestoreToDateResponse);
  32. // Batch operations
  33. rpc BatchInsert(BatchInsertRequest) returns (BatchInsertResponse);
  34. rpc BatchGet(BatchGetRequest) returns (BatchGetResponse);
  35. rpc BatchDelete(BatchDeleteRequest) returns (BatchDeleteResponse);
  36. // Query operations
  37. rpc Find(FindRequest) returns (FindResponse);
  38. rpc Count(CountRequest) returns (CountResponse);
  39. rpc SimilaritySearch(SimilaritySearchRequest) returns (SimilaritySearchResponse);
  40. // Set operations (Redis compatibility)
  41. rpc SetAdd(SetAddRequest) returns (SetAddResponse);
  42. rpc SetRemove(SetRemoveRequest) returns (SetRemoveResponse);
  43. rpc SetMembers(SetMembersRequest) returns (SetMembersResponse);
  44. rpc SetIsMember(SetIsMemberRequest) returns (SetIsMemberResponse);
  45. // Collection management
  46. rpc CreateCollection(CreateCollectionRequest) returns (CreateCollectionResponse);
  47. rpc DropCollection(DropCollectionRequest) returns (DropCollectionResponse);
  48. rpc ListCollections(ListCollectionsRequest) returns (ListCollectionsResponse);
  49. rpc GetCollectionInfo(GetCollectionInfoRequest) returns (GetCollectionInfoResponse);
  50. // v2.3 — Project management. Projects are top-level namespaces over
  51. // collections. The "default" project is implicit and always exists.
  52. rpc ListProjects(ListProjectsRequest) returns (ListProjectsResponse);
  53. rpc CreateProject(CreateProjectRequest) returns (CreateProjectResponse);
  54. rpc DropProject(DropProjectRequest) returns (DropProjectResponse);
  55. // View management
  56. rpc CreateView(CreateViewRequest) returns (CreateViewResponse);
  57. rpc DropView(DropViewRequest) returns (DropViewResponse);
  58. rpc ListViews(ListViewsRequest) returns (ListViewsResponse);
  59. rpc GetViewInfo(GetViewInfoRequest) returns (GetViewInfoResponse);
  60. // Collection configuration
  61. rpc ConfigureCollection(ConfigureCollectionRequest) returns (ConfigureCollectionResponse);
  62. rpc GetCollectionConfig(GetCollectionConfigRequest) returns (GetCollectionConfigResponse);
  63. rpc MigrateCollectionTimestamps(MigrateCollectionTimestampsRequest) returns (MigrateCollectionTimestampsResponse);
  64. // File operations
  65. rpc UploadFile(stream FileChunk) returns (UploadFileResponse);
  66. rpc DownloadFile(DownloadFileRequest) returns (stream FileChunk);
  67. rpc DeleteFile(DeleteFileRequest) returns (DeleteFileResponse);
  68. rpc GetFileInfo(GetFileInfoRequest) returns (FileInfo);
  69. rpc ListFiles(ListFilesRequest) returns (ListFilesResponse);
  70. // Event subscription
  71. rpc Subscribe(SubscribeRequest) returns (stream DatabaseEvent);
  72. // Health and stats
  73. rpc HealthCheck(HealthCheckRequest) returns (HealthCheckResponse);
  74. rpc GetStats(GetStatsRequest) returns (GetStatsResponse);
  75. rpc GetMemoryStats(GetMemoryStatsRequest) returns (GetMemoryStatsResponse);
  76. // Read-only runtime state control
  77. rpc SetReadOnly(SetReadOnlyRequest) returns (SetReadOnlyResponse);
  78. rpc GetReadOnlyStatus(GetReadOnlyStatusRequest) returns (GetReadOnlyStatusResponse);
  79. }
  80. // ===== Replication Service =====
  81. service DatabaseReplication {
  82. // Bidirectional streaming for real-time sync
  83. rpc SyncStream(stream ReplicationMessage) returns (stream ReplicationMessage);
  84. // Pull missed entries (for recovery)
  85. rpc GetEntriesSince(GetEntriesRequest) returns (stream ReplicationEntry);
  86. // Get current node state
  87. rpc GetNodeState(GetNodeStateRequest) returns (NodeState);
  88. }
  89. // ===== Document Types =====
  90. message Document {
  91. string id = 1;
  92. string collection = 2;
  93. bytes data = 3; // JSON-encoded document data
  94. uint64 version = 4;
  95. uint64 created_at = 5; // Timestamp in milliseconds
  96. uint64 updated_at = 6;
  97. uint64 expires_at = 7; // 0 = no expiration
  98. string node_id = 8; // Origin node for replication
  99. bool encrypted = 9;
  100. repeated string encrypted_fields = 10;
  101. string created_by = 11; // User ID who created the document
  102. string updated_by = 12; // User ID who last updated the document
  103. }
  104. // ===== Document Operations =====
  105. message InsertRequest {
  106. string collection = 1;
  107. bytes data = 2; // JSON document
  108. string id = 3; // Optional, auto-generated if empty
  109. uint32 ttl_seconds = 4; // 0 = use collection default
  110. string actor = 5; // User ID performing the operation (for audit)
  111. }
  112. message InsertResponse {
  113. string id = 1;
  114. uint64 version = 2;
  115. }
  116. message GetRequest {
  117. string collection = 1;
  118. string id = 2;
  119. }
  120. message GetResponse {
  121. Document document = 1;
  122. bool found = 2;
  123. }
  124. message UpdateRequest {
  125. string collection = 1;
  126. string id = 2;
  127. bytes data = 3;
  128. uint64 expected_version = 4; // 0 = no version check (force update)
  129. string actor = 5; // User ID performing the operation (for audit)
  130. }
  131. message UpdateResponse {
  132. uint64 new_version = 1;
  133. bool success = 2;
  134. string error = 3;
  135. }
  136. message UpsertRequest {
  137. string collection = 1;
  138. bytes data = 2;
  139. string id = 3;
  140. uint32 ttl_seconds = 4;
  141. string actor = 5; // User ID performing the operation (for audit)
  142. }
  143. message UpsertResponse {
  144. string id = 1;
  145. uint64 version = 2;
  146. bool inserted = 3; // true if inserted, false if updated
  147. }
  148. message DeleteRequest {
  149. string collection = 1;
  150. string id = 2;
  151. }
  152. message DeleteResponse {
  153. bool deleted = 1;
  154. }
  155. message PatchDocumentRequest {
  156. string collection = 1;
  157. string id = 2;
  158. bytes patch_json = 3; // JSON fields to merge into existing document
  159. string actor = 4; // User ID performing the operation (for audit)
  160. }
  161. message PatchDocumentResponse {
  162. uint64 new_version = 1;
  163. bool success = 2;
  164. string error = 3;
  165. }
  166. message ExistsRequest {
  167. string collection = 1;
  168. string id = 2;
  169. }
  170. message ExistsResponse {
  171. bool exists = 1;
  172. }
  173. // ===== Version History Operations =====
  174. message DocumentVersionEntry {
  175. uint64 version = 1;
  176. bytes data = 2; // JSON-encoded document data at this version
  177. uint64 timestamp = 3; // When this version was created (updatedAt)
  178. string updated_by = 4;
  179. bool encrypted = 5;
  180. repeated string encrypted_fields = 6;
  181. }
  182. message GetVersionHistoryRequest {
  183. string collection = 1;
  184. string id = 2;
  185. uint32 limit = 3; // 0 = all versions
  186. uint32 offset = 4;
  187. }
  188. message GetVersionHistoryResponse {
  189. repeated DocumentVersionEntry versions = 1;
  190. uint64 current_version = 2; // 0 if document is deleted
  191. uint64 total_count = 3;
  192. bool document_deleted = 4;
  193. }
  194. message GetDocumentVersionRequest {
  195. string collection = 1;
  196. string id = 2;
  197. uint64 version = 3;
  198. }
  199. message GetDocumentVersionResponse {
  200. DocumentVersionEntry version_entry = 1;
  201. bool found = 2;
  202. }
  203. message RestoreVersionRequest {
  204. string collection = 1;
  205. string id = 2;
  206. uint64 version = 3; // Version number to restore
  207. string actor = 4; // User performing the restore
  208. }
  209. message RestoreVersionResponse {
  210. uint64 new_version = 1; // The newly created version number
  211. bool success = 2;
  212. string error = 3;
  213. }
  214. message RestoreToDateRequest {
  215. string collection = 1;
  216. string id = 2;
  217. uint64 timestamp = 3; // Find version active at this time (ms since epoch)
  218. string actor = 4;
  219. }
  220. message RestoreToDateResponse {
  221. uint64 restored_version = 1; // Which old version was restored from
  222. uint64 new_version = 2; // The newly created version number
  223. bool success = 3;
  224. string error = 4;
  225. }
  226. // ===== Batch Operations =====
  227. message BatchInsertRequest {
  228. string collection = 1;
  229. repeated BatchInsertItem items = 2;
  230. string actor = 3; // User ID performing the operation (for audit)
  231. }
  232. message BatchInsertItem {
  233. bytes data = 1;
  234. string id = 2;
  235. uint32 ttl_seconds = 3;
  236. }
  237. message BatchInsertResponse {
  238. repeated string ids = 1;
  239. uint32 success_count = 2;
  240. uint32 error_count = 3;
  241. }
  242. message BatchGetRequest {
  243. string collection = 1;
  244. repeated string ids = 2;
  245. }
  246. message BatchGetResponse {
  247. repeated Document documents = 1;
  248. }
  249. message BatchDeleteRequest {
  250. string collection = 1;
  251. repeated string ids = 2;
  252. }
  253. message BatchDeleteResponse {
  254. uint64 deleted_count = 1;
  255. }
  256. // ===== Query Operations =====
  257. message FindRequest {
  258. string collection = 1;
  259. repeated Filter filters = 2;
  260. Sort sort = 3;
  261. uint32 limit = 4; // Default 100
  262. uint32 offset = 5;
  263. repeated string projection = 6; // Fields to include (empty = all)
  264. }
  265. message Filter {
  266. string field = 1;
  267. FilterOp op = 2;
  268. bytes value = 3; // JSON-encoded value
  269. }
  270. enum FilterOp {
  271. FILTER_OP_UNSPECIFIED = 0;
  272. FILTER_OP_EQ = 1;
  273. FILTER_OP_NE = 2;
  274. FILTER_OP_GT = 3;
  275. FILTER_OP_GTE = 4;
  276. FILTER_OP_LT = 5;
  277. FILTER_OP_LTE = 6;
  278. FILTER_OP_IN = 7;
  279. FILTER_OP_CONTAINS = 8;
  280. FILTER_OP_EXISTS = 9;
  281. FILTER_OP_REGEX = 10;
  282. FILTER_OP_SEARCH = 11; // Full-text search across ID and string fields
  283. }
  284. message Sort {
  285. string field = 1;
  286. bool descending = 2;
  287. }
  288. message FindResponse {
  289. repeated Document documents = 1;
  290. uint64 total_count = 2;
  291. bool has_more = 3;
  292. // WAL fallback metrics (for queries that include evicted documents)
  293. bool used_wal_fallback = 4; // True if WAL was scanned for evicted docs
  294. uint32 memory_match_count = 5; // Documents matched from memory
  295. uint32 wal_match_count = 6; // Documents matched from WAL
  296. uint64 memory_search_micros = 7; // Time spent searching memory (µs)
  297. uint64 wal_search_micros = 8; // Time spent loading/searching WAL (µs)
  298. }
  299. message CountRequest {
  300. string collection = 1;
  301. repeated Filter filters = 2;
  302. }
  303. message CountResponse {
  304. uint64 count = 1;
  305. }
  306. message SimilaritySearchRequest {
  307. string collection = 1;
  308. repeated float query_vector = 2;
  309. uint32 top_k = 3;
  310. float min_score = 4;
  311. }
  312. message SimilaritySearchResponse {
  313. repeated SimilarityResult results = 1;
  314. }
  315. message SimilarityResult {
  316. string id = 1;
  317. float score = 2;
  318. bytes data = 3;
  319. }
  320. // ===== Set Operations =====
  321. message SetAddRequest {
  322. string collection = 1;
  323. string set_id = 2;
  324. string member = 3;
  325. }
  326. message SetAddResponse {
  327. bool added = 1; // false if already exists
  328. }
  329. message SetRemoveRequest {
  330. string collection = 1;
  331. string set_id = 2;
  332. string member = 3;
  333. }
  334. message SetRemoveResponse {
  335. bool removed = 1;
  336. }
  337. message SetMembersRequest {
  338. string collection = 1;
  339. string set_id = 2;
  340. }
  341. message SetMembersResponse {
  342. repeated string members = 1;
  343. }
  344. message SetIsMemberRequest {
  345. string collection = 1;
  346. string set_id = 2;
  347. string member = 3;
  348. }
  349. message SetIsMemberResponse {
  350. bool is_member = 1;
  351. }
  352. // ===== Collection Management =====
  353. message CreateCollectionRequest {
  354. string name = 1;
  355. CollectionOptions options = 2;
  356. }
  357. message CollectionOptions {
  358. bool auto_create_id = 1;
  359. uint32 default_ttl_seconds = 2;
  360. bool encrypted = 3;
  361. repeated string sensitive_fields = 4;
  362. uint32 max_versions = 5; // Max version history per document (0 = unlimited)
  363. uint32 vector_dimension = 6; // Dimension of vectors stored in this collection (0 = not a vector collection)
  364. // NEW in v1.7.0 — eviction priority for the collection.
  365. // UNSPECIFIED is treated as NORMAL for backward compatibility.
  366. MemoryPriority memory_priority = 7;
  367. }
  368. enum MemoryPriority {
  369. MEMORY_PRIORITY_UNSPECIFIED = 0; // treated as NORMAL
  370. MEMORY_PRIORITY_LOW = 1;
  371. MEMORY_PRIORITY_NORMAL = 2;
  372. MEMORY_PRIORITY_HIGH = 3;
  373. }
  374. message CreateCollectionResponse {
  375. bool created = 1;
  376. }
  377. message DropCollectionRequest {
  378. string name = 1;
  379. }
  380. message DropCollectionResponse {
  381. bool dropped = 1;
  382. }
  383. message ListCollectionsRequest {
  384. }
  385. message ListCollectionsResponse {
  386. repeated string names = 1;
  387. }
  388. message GetCollectionInfoRequest {
  389. string name = 1;
  390. }
  391. message GetCollectionInfoResponse {
  392. CollectionInfo info = 1;
  393. bool found = 2;
  394. }
  395. message CollectionInfo {
  396. string name = 1;
  397. uint64 document_count = 2;
  398. uint64 size_bytes = 3;
  399. CollectionOptions options = 4;
  400. uint64 created_at = 5;
  401. uint64 updated_at = 6;
  402. uint32 vector_dimension = 7; // Dimension of vectors stored in this collection (0 = not a vector collection)
  403. }
  404. // ===== Project Management (v2.3) =====
  405. //
  406. // Projects are top-level namespaces over collections. Collections live
  407. // inside a project; wire-form "my_app:users" addresses collection "users"
  408. // in project "my_app", bare "users" addresses ("default", "users"). The
  409. // "default" project is implicit and always present.
  410. //
  411. // Stage F ships the RPC surface backed by a filesystem-only placeholder
  412. // (`<dataDir>/projects/<name>/env/`). Stage B replaces the placeholder
  413. // with the real ProjectStore-backed implementation.
  414. message ListProjectsRequest {}
  415. message ListProjectsResponse {
  416. // Alphabetical. Always includes "default".
  417. repeated string projects = 1;
  418. }
  419. message CreateProjectRequest {
  420. string name = 1;
  421. }
  422. message CreateProjectResponse {
  423. // true = newly created, false = already existed (idempotent) OR validation error.
  424. bool created = 1;
  425. // Populated on validation failure (e.g. invalid name). Empty on success
  426. // and on the idempotent "already existed" path.
  427. string error = 2;
  428. }
  429. message DropProjectRequest {
  430. string name = 1;
  431. }
  432. message DropProjectResponse {
  433. bool dropped = 1;
  434. // Populated when the drop is refused — e.g. name == "default",
  435. // unknown project, or filesystem error.
  436. string error = 2;
  437. }
  438. // ===== File Operations =====
  439. message FileChunk {
  440. oneof content {
  441. FileMetadata metadata = 1; // First chunk includes metadata
  442. bytes data = 2; // Subsequent chunks are data
  443. }
  444. }
  445. message FileMetadata {
  446. string id = 1; // Set by server on upload response
  447. string name = 2;
  448. string mime_type = 3;
  449. uint64 size = 4;
  450. string file_type = 5; // "plugin", "document", "generated"
  451. string related_id = 6; // plugin_id, conversation_id, etc.
  452. map<string, string> metadata = 7; // Custom metadata
  453. bool is_public = 8; // Visibility flag
  454. }
  455. message UploadFileResponse {
  456. string id = 1;
  457. uint64 size = 2;
  458. string checksum = 3; // SHA-256
  459. bool deduplicated = 4; // True if blob already existed
  460. }
  461. message DownloadFileRequest {
  462. string id = 1;
  463. }
  464. message DeleteFileRequest {
  465. string id = 1;
  466. }
  467. message DeleteFileResponse {
  468. bool deleted = 1;
  469. }
  470. message GetFileInfoRequest {
  471. string id = 1;
  472. }
  473. message FileInfo {
  474. string id = 1;
  475. string name = 2;
  476. string mime_type = 3;
  477. uint64 size = 4;
  478. string file_type = 5;
  479. string related_id = 6;
  480. string checksum = 7;
  481. uint64 created_at = 8;
  482. map<string, string> metadata = 9;
  483. bool is_public = 10; // Visibility flag
  484. uint32 ref_count = 11; // Blob reference count (informational)
  485. }
  486. message ListFilesRequest {
  487. string file_type = 1; // Filter by type (optional)
  488. string related_id = 2; // Filter by related ID (optional)
  489. uint32 limit = 3;
  490. uint32 offset = 4;
  491. string checksum = 5; // Filter by checksum (for dedup queries)
  492. string name = 6; // Filter by exact filename (optional)
  493. }
  494. message ListFilesResponse {
  495. repeated FileInfo files = 1;
  496. uint64 total_count = 2;
  497. bool has_more = 3;
  498. }
  499. // ===== Event Subscription =====
  500. message SubscribeRequest {
  501. repeated string collections = 1; // Empty = all collections
  502. repeated string patterns = 2; // Glob patterns (e.g., "assistants:*")
  503. bool include_data = 3; // Include document data in events
  504. }
  505. message DatabaseEvent {
  506. EventType type = 1;
  507. string collection = 2;
  508. string document_id = 3;
  509. uint64 timestamp = 4;
  510. string node_id = 5;
  511. bytes data = 6; // JSON document (if include_data)
  512. }
  513. enum EventType {
  514. EVENT_UNKNOWN = 0;
  515. EVENT_INSERT = 1;
  516. EVENT_UPDATE = 2;
  517. EVENT_DELETE = 3;
  518. EVENT_EXPIRE = 4;
  519. EVENT_INVALIDATE = 5;
  520. // NEW in v1.7.0 — memory-pressure observability events.
  521. EVENT_MEMORY_PRESSURE_HIGH = 6; // Emitted when pressure reaches hard threshold
  522. EVENT_MEMORY_EVICTION_BURST = 7; // Emitted when eviction runs a large burst
  523. }
  524. // ===== Replication =====
  525. message ReplicationEntry {
  526. uint64 sequence = 1;
  527. uint64 global_timestamp = 2;
  528. string node_id = 3;
  529. OperationType op = 4;
  530. string collection = 5;
  531. string document_id = 6;
  532. uint64 document_version = 7;
  533. bytes data = 8;
  534. }
  535. enum OperationType {
  536. OP_UNKNOWN = 0;
  537. OP_INSERT = 1;
  538. OP_UPDATE = 2;
  539. OP_DELETE = 3;
  540. OP_UPSERT = 4;
  541. OP_CREATE_COLLECTION = 5;
  542. OP_DROP_COLLECTION = 6;
  543. }
  544. message ReplicationMessage {
  545. oneof content {
  546. ReplicationEntry entry = 1;
  547. Heartbeat heartbeat = 2;
  548. WatermarkUpdate watermark = 3;
  549. SyncRequest sync_request = 4;
  550. }
  551. }
  552. message Heartbeat {
  553. string node_id = 1;
  554. uint64 timestamp = 2;
  555. uint64 sequence = 3;
  556. }
  557. message WatermarkUpdate {
  558. string node_id = 1;
  559. uint64 sequence = 2;
  560. }
  561. message SyncRequest {
  562. uint64 from_sequence = 1;
  563. }
  564. message GetEntriesRequest {
  565. uint64 from_sequence = 1;
  566. uint32 limit = 2;
  567. }
  568. message GetNodeStateRequest {
  569. }
  570. message NodeState {
  571. string node_id = 1;
  572. uint64 current_sequence = 2;
  573. map<string, uint64> peer_watermarks = 3;
  574. uint64 document_count = 4;
  575. repeated string collections = 5;
  576. bool healthy = 6;
  577. // Per-collection sequence tracking for collection discovery
  578. map<string, uint64> collection_sequences = 7;
  579. }
  580. // ===== Health and Stats =====
  581. message HealthCheckRequest {
  582. }
  583. message HealthCheckResponse {
  584. bool healthy = 1;
  585. uint64 uptime_seconds = 2;
  586. uint64 document_count = 3;
  587. uint64 memory_used_bytes = 4;
  588. uint64 wal_size_bytes = 5;
  589. repeated PeerHealth peers = 6;
  590. }
  591. message PeerHealth {
  592. string node_id = 1;
  593. bool connected = 2;
  594. uint64 latency_ms = 3;
  595. uint64 lag_entries = 4;
  596. }
  597. message GetStatsRequest {
  598. }
  599. message GetStatsResponse {
  600. uint64 total_documents = 1;
  601. uint64 total_collections = 2;
  602. uint64 memory_used_bytes = 3;
  603. uint64 wal_sequence = 4;
  604. uint64 wal_size_bytes = 5;
  605. uint64 snapshot_count = 6;
  606. uint64 last_snapshot_sequence = 7;
  607. uint64 insert_count = 8;
  608. uint64 update_count = 9;
  609. uint64 delete_count = 10;
  610. uint64 query_count = 11;
  611. // Memory eviction stats
  612. uint64 evicted_documents = 12; // Documents currently evicted to disk
  613. uint64 total_evictions = 13; // Total eviction operations performed
  614. uint64 recovery_count = 14; // Documents recovered from eviction
  615. // Memory configuration
  616. uint64 max_memory_bytes = 15; // Configured max memory limit
  617. uint32 eviction_threshold_percent = 16; // Start evicting at this % of max
  618. uint32 eviction_target_percent = 17; // Evict down to this % of max
  619. // Operation timing (microseconds) - for performance monitoring
  620. uint64 get_count = 18; // Number of get operations
  621. uint64 get_total_micros = 19; // Total time spent in get operations
  622. uint64 get_max_micros = 20; // Max single get operation time
  623. uint64 insert_total_micros = 21;
  624. uint64 insert_max_micros = 22;
  625. uint64 update_total_micros = 23;
  626. uint64 update_max_micros = 24;
  627. uint64 query_total_micros = 25;
  628. uint64 query_max_micros = 26;
  629. }
  630. // ===== View Operations =====
  631. message ViewDefinition {
  632. string name = 1; // view name (globally unique, cannot start with _)
  633. string collection = 2; // target real collection (must NOT be another view)
  634. repeated string include = 3; // field paths to include (dot-notation for nested)
  635. repeated string exclude = 4; // field paths to exclude (ignored if include is non-empty)
  636. repeated Filter where = 5; // baked-in filters (AND-merged with caller filters)
  637. Sort default_sort = 6; // baked-in default sort (used when caller doesn't specify)
  638. uint64 created_at = 7;
  639. uint64 updated_at = 8;
  640. }
  641. message CreateViewRequest {
  642. string name = 1;
  643. string collection = 2;
  644. repeated string include = 3;
  645. repeated string exclude = 4;
  646. repeated Filter where = 5;
  647. Sort default_sort = 6;
  648. }
  649. message CreateViewResponse {
  650. bool success = 1;
  651. string error = 2;
  652. }
  653. message DropViewRequest {
  654. string name = 1;
  655. }
  656. message DropViewResponse {
  657. bool success = 1;
  658. string error = 2;
  659. }
  660. message ListViewsRequest {}
  661. message ListViewsResponse {
  662. repeated ViewDefinition views = 1;
  663. }
  664. message GetViewInfoRequest {
  665. string name = 1;
  666. }
  667. message GetViewInfoResponse {
  668. ViewDefinition view = 1;
  669. bool found = 2;
  670. }
  671. // ===== Collection Configuration =====
  672. // Per-collection configuration for timestamp precision and other runtime knobs.
  673. // Stored in the _collection_meta system collection.
  674. message CollectionConfig {
  675. // "ms" (default) — _created_at/_updated_at stamped in milliseconds since epoch
  676. // "ns" — _created_at/_updated_at stamped in nanoseconds since epoch
  677. string timestamp_precision = 1;
  678. // Room for future per-collection knobs
  679. }
  680. message ConfigureCollectionRequest {
  681. string collection = 1;
  682. CollectionConfig config = 2;
  683. }
  684. message ConfigureCollectionResponse {
  685. bool success = 1;
  686. string error = 2;
  687. }
  688. message GetCollectionConfigRequest {
  689. string collection = 1;
  690. }
  691. message GetCollectionConfigResponse {
  692. CollectionConfig config = 1;
  693. bool found = 2;
  694. }
  695. message MigrateCollectionTimestampsRequest {
  696. string collection = 1;
  697. string from_precision = 2; // "ms" or "ns"
  698. string to_precision = 3; // "ms" or "ns"
  699. }
  700. message MigrateCollectionTimestampsResponse {
  701. bool success = 1;
  702. string error = 2;
  703. uint64 rows_migrated = 3; // how many documents had their timestamps updated
  704. uint64 rows_skipped = 4; // already in target range (idempotent resume)
  705. }
  706. // ===== Read-Only Control =====
  707. message SetReadOnlyRequest {
  708. bool read_only = 1;
  709. }
  710. message SetReadOnlyResponse {
  711. bool success = 1;
  712. bool was_read_only = 2; // previous state
  713. string error = 3;
  714. }
  715. message GetReadOnlyStatusRequest {}
  716. message GetReadOnlyStatusResponse {
  717. bool read_only = 1;
  718. string reason = 2;
  719. // Recovery outcome details (populated when auto-readonly triggered)
  720. string recovery_outcome = 3; // "trivial_success" | "fresh_install" | "snapshot_fell_back" | "wal_only_replay" | "forced_empty" | "failed"
  721. string expected_snapshot = 4;
  722. string snapshot_used = 5;
  723. string failure_reason = 6;
  724. uint64 wal_entries_replayed = 7;
  725. uint32 snapshots_attempted = 8;
  726. }
  727. // ===== Memory Stats =====
  728. // Added in v1.7.0. Wire-compatible — server-side implementation lands in T9.
  729. message GetMemoryStatsRequest {}
  730. message CollectionMemoryStats {
  731. string collection = 1;
  732. uint64 document_count = 2;
  733. uint64 estimated_bytes = 3;
  734. uint64 evicted_stub_count = 4;
  735. MemoryPriority priority = 5;
  736. }
  737. message GetMemoryStatsResponse {
  738. uint64 total_memory_bytes = 1;
  739. uint64 max_memory_bytes = 2;
  740. uint32 pressure_percent = 3; // current usage / max × 100
  741. string pressure_level = 4; // "normal" | "soft" | "hard" | "emergency"
  742. repeated CollectionMemoryStats collections = 5;
  743. // Most recent eviction
  744. uint64 last_eviction_timestamp = 6; // ms since epoch, 0 if none
  745. uint64 last_eviction_docs = 7;
  746. uint64 last_eviction_bytes_freed = 8;
  747. }