@feltdb/core 0.15.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/dist/agent-state.d.ts +20 -0
  2. package/dist/agent-state.d.ts.map +1 -1
  3. package/dist/agent-state.js +36 -0
  4. package/dist/build-identity.json +12 -4
  5. package/dist/cli/commands.js +187 -4
  6. package/dist/cli/publish-engine.js +116 -16
  7. package/dist/collection.d.ts.map +1 -1
  8. package/dist/collection.js +3 -0
  9. package/dist/create/build-identity.json +12 -4
  10. package/dist/create/managed-account.js +93 -35
  11. package/dist/create/package-versions.js +1 -1
  12. package/dist/create/server-source/Cargo.lock +6 -509
  13. package/dist/create/server-source/Cargo.toml +2 -13
  14. package/dist/create/server-source/crates/feltdb-client/Cargo.toml +1 -1
  15. package/dist/create/server-source/crates/feltdb-server/Cargo.toml +1 -1
  16. package/dist/create/server-source/crates/feltdb-server/src/main.rs +255 -12
  17. package/dist/create/server-source/crates/feltdb-wasm/Cargo.toml +1 -1
  18. package/dist/db.d.ts +11 -1
  19. package/dist/db.d.ts.map +1 -1
  20. package/dist/db.js +15 -2
  21. package/dist/error-codes.d.ts +5 -0
  22. package/dist/error-codes.d.ts.map +1 -1
  23. package/dist/error-codes.js +9 -1
  24. package/dist/http-db.d.ts +16 -0
  25. package/dist/http-db.d.ts.map +1 -1
  26. package/dist/http-db.js +36 -6
  27. package/dist/managed-recovery.d.ts +6 -0
  28. package/dist/managed-recovery.d.ts.map +1 -1
  29. package/dist/managed-recovery.js +9 -0
  30. package/dist/studio-app/assets/{feltdb_wasm-BjM1ylL3.js → feltdb_wasm-DtybUY0q.js} +1 -1
  31. package/dist/studio-app/assets/feltdb_wasm_bg-DsgIUwaB.wasm +0 -0
  32. package/dist/studio-app/assets/index-C4OffsZl.js +37 -0
  33. package/dist/studio-app/index.html +1 -1
  34. package/dist/wasm/feltdb_wasm_bg.wasm +0 -0
  35. package/dist/wasm/package.json +1 -1
  36. package/dist/workload.d.ts +55 -3
  37. package/dist/workload.d.ts.map +1 -1
  38. package/dist/workload.js +23 -0
  39. package/dist/workspace/workspace-connection.d.ts.map +1 -1
  40. package/dist/workspace/workspace-connection.js +14 -3
  41. package/package.json +1 -1
  42. package/dist/create/server-source/crates/feltdb/Cargo.lock +0 -175
  43. package/dist/create/server-source/crates/feltdb/Cargo.toml +0 -102
  44. package/dist/create/server-source/crates/feltdb/LICENSE +0 -21
  45. package/dist/create/server-source/crates/feltdb/README.md +0 -75
  46. package/dist/create/server-source/crates/feltdb/benches/baselines/gate-13-redux.json +0 -370
  47. package/dist/create/server-source/crates/feltdb/benches/gate13_baseline.rs +0 -589
  48. package/dist/create/server-source/crates/feltdb/benches/gate13_phase_7_1_release_economics.rs +0 -247
  49. package/dist/create/server-source/crates/feltdb/benches/gate_13_redux.rs +0 -440
  50. package/dist/create/server-source/crates/feltdb/benches/gate_13_regression_runner.rs +0 -275
  51. package/dist/create/server-source/crates/feltdb/benches/gate_14a_concurrent_writer_scaling.rs +0 -381
  52. package/dist/create/server-source/crates/feltdb/benches/gate_14a_production_admission_revalidation.rs +0 -467
  53. package/dist/create/server-source/crates/feltdb/benches/gate_14a_rc2_admission_contract.rs +0 -489
  54. package/dist/create/server-source/crates/feltdb/benches/gate_14a_rc_root_cause.rs +0 -281
  55. package/dist/create/server-source/crates/feltdb/benches/gate_14a_sync1_queued_prototype.rs +0 -606
  56. package/dist/create/server-source/crates/feltdb/benches/gate_14a_sync_economics.rs +0 -531
  57. package/dist/create/server-source/crates/feltdb/benches/gate_14b_causal_backlog_scaling.rs +0 -462
  58. package/dist/create/server-source/crates/feltdb/benches/gate_14c_replication_contract_test.rs +0 -505
  59. package/dist/create/server-source/crates/feltdb/benches/gate_14c_replication_scaling.rs +0 -484
  60. package/dist/create/server-source/crates/feltdb/benches/gate_14d_combined_dimension_scaling.rs +0 -758
  61. package/dist/create/server-source/crates/feltdb/benches/phase_7_1_2_optimization_benchmark.rs +0 -421
  62. package/dist/create/server-source/crates/feltdb/benches/phase_7_1_3_crossover_analysis.rs +0 -329
  63. package/dist/create/server-source/crates/feltdb/src/acceptance_tests.rs +0 -1705
  64. package/dist/create/server-source/crates/feltdb/src/acquisition.rs +0 -286
  65. package/dist/create/server-source/crates/feltdb/src/admission.rs +0 -185
  66. package/dist/create/server-source/crates/feltdb/src/admission_contract_tests.rs +0 -507
  67. package/dist/create/server-source/crates/feltdb/src/adversarial_transport.rs +0 -539
  68. package/dist/create/server-source/crates/feltdb/src/agent_state.rs +0 -320
  69. package/dist/create/server-source/crates/feltdb/src/agent_transition_contract.rs +0 -1545
  70. package/dist/create/server-source/crates/feltdb/src/analytics.rs +0 -521
  71. package/dist/create/server-source/crates/feltdb/src/application.rs +0 -2674
  72. package/dist/create/server-source/crates/feltdb/src/application_runtime.rs +0 -1070
  73. package/dist/create/server-source/crates/feltdb/src/authority.rs +0 -479
  74. package/dist/create/server-source/crates/feltdb/src/authority_failover.rs +0 -847
  75. package/dist/create/server-source/crates/feltdb/src/authorization.rs +0 -1030
  76. package/dist/create/server-source/crates/feltdb/src/authorization_security_tests.rs +0 -1122
  77. package/dist/create/server-source/crates/feltdb/src/bin/feltdb-authority-client.rs +0 -32
  78. package/dist/create/server-source/crates/feltdb/src/bin/feltdb-authority.rs +0 -19
  79. package/dist/create/server-source/crates/feltdb/src/bin/feltdb_node.rs +0 -1474
  80. package/dist/create/server-source/crates/feltdb/src/capabilities/mod.rs +0 -8
  81. package/dist/create/server-source/crates/feltdb/src/capabilities/search.rs +0 -418
  82. package/dist/create/server-source/crates/feltdb/src/capabilities/vector.rs +0 -482
  83. package/dist/create/server-source/crates/feltdb/src/capability.rs +0 -903
  84. package/dist/create/server-source/crates/feltdb/src/cardinality_diagnostics.rs +0 -263
  85. package/dist/create/server-source/crates/feltdb/src/cardinality_endpoint.rs +0 -77
  86. package/dist/create/server-source/crates/feltdb/src/causal_backlog_bound.rs +0 -496
  87. package/dist/create/server-source/crates/feltdb/src/causal_dependency_barrier.rs +0 -2574
  88. package/dist/create/server-source/crates/feltdb/src/causal_dependency_barrier_phase_7_1.rs +0 -212
  89. package/dist/create/server-source/crates/feltdb/src/concurrency_fuzzing.rs +0 -422
  90. package/dist/create/server-source/crates/feltdb/src/consistency_contract.rs +0 -445
  91. package/dist/create/server-source/crates/feltdb/src/content_distribution.rs +0 -465
  92. package/dist/create/server-source/crates/feltdb/src/convergence.rs +0 -634
  93. package/dist/create/server-source/crates/feltdb/src/crash_atomic_boundary.rs +0 -427
  94. package/dist/create/server-source/crates/feltdb/src/crash_injection.rs +0 -376
  95. package/dist/create/server-source/crates/feltdb/src/crash_recovery_tests.rs +0 -365
  96. package/dist/create/server-source/crates/feltdb/src/cron.rs +0 -294
  97. package/dist/create/server-source/crates/feltdb/src/dedup_bound_investigation.rs +0 -483
  98. package/dist/create/server-source/crates/feltdb/src/distributed_indexing.rs +0 -477
  99. package/dist/create/server-source/crates/feltdb/src/distributed_tests.rs +0 -1003
  100. package/dist/create/server-source/crates/feltdb/src/distributed_transactions.rs +0 -1334
  101. package/dist/create/server-source/crates/feltdb/src/durability_guarantees.rs +0 -368
  102. package/dist/create/server-source/crates/feltdb/src/durable_dedup_set.rs +0 -231
  103. package/dist/create/server-source/crates/feltdb/src/durable_operation_identity.rs +0 -482
  104. package/dist/create/server-source/crates/feltdb/src/durable_operation_log.rs +0 -203
  105. package/dist/create/server-source/crates/feltdb/src/durable_sync.rs +0 -317
  106. package/dist/create/server-source/crates/feltdb/src/equality_index.rs +0 -595
  107. package/dist/create/server-source/crates/feltdb/src/execution.rs +0 -426
  108. package/dist/create/server-source/crates/feltdb/src/in_process_transport.rs +0 -214
  109. package/dist/create/server-source/crates/feltdb/src/indexing.rs +0 -776
  110. package/dist/create/server-source/crates/feltdb/src/lib.rs +0 -7365
  111. package/dist/create/server-source/crates/feltdb/src/managed_cas_tests.rs +0 -234
  112. package/dist/create/server-source/crates/feltdb/src/materialization.rs +0 -184
  113. package/dist/create/server-source/crates/feltdb/src/metrics.rs +0 -266
  114. package/dist/create/server-source/crates/feltdb/src/multi_node_convergence.rs +0 -310
  115. package/dist/create/server-source/crates/feltdb/src/multi_operation_transaction.rs +0 -736
  116. package/dist/create/server-source/crates/feltdb/src/observability.rs +0 -379
  117. package/dist/create/server-source/crates/feltdb/src/operation.rs +0 -290
  118. package/dist/create/server-source/crates/feltdb/src/operation_algebra.rs +0 -439
  119. package/dist/create/server-source/crates/feltdb/src/operation_log.rs +0 -349
  120. package/dist/create/server-source/crates/feltdb/src/p1_application_atomicity.rs +0 -332
  121. package/dist/create/server-source/crates/feltdb/src/p1_atomicity_acceptance.rs +0 -718
  122. package/dist/create/server-source/crates/feltdb/src/partition_reconciliation.rs +0 -487
  123. package/dist/create/server-source/crates/feltdb/src/peer_registry.rs +0 -166
  124. package/dist/create/server-source/crates/feltdb/src/permutation_scheduler.rs +0 -289
  125. package/dist/create/server-source/crates/feltdb/src/persistence_reality.rs +0 -566
  126. package/dist/create/server-source/crates/feltdb/src/phase1b_acceptance.rs +0 -3391
  127. package/dist/create/server-source/crates/feltdb/src/phase1c1_acceptance.rs +0 -203
  128. package/dist/create/server-source/crates/feltdb/src/phase1c2_acceptance.rs +0 -261
  129. package/dist/create/server-source/crates/feltdb/src/phase1c3_acceptance.rs +0 -502
  130. package/dist/create/server-source/crates/feltdb/src/phase1c_atomicity_proof.rs +0 -216
  131. package/dist/create/server-source/crates/feltdb/src/phase5_integration.rs +0 -303
  132. package/dist/create/server-source/crates/feltdb/src/phase5_scenarios.rs +0 -323
  133. package/dist/create/server-source/crates/feltdb/src/phase6_adversarial_scenarios.rs +0 -531
  134. package/dist/create/server-source/crates/feltdb/src/phase6_convergence_validator.rs +0 -406
  135. package/dist/create/server-source/crates/feltdb/src/phase6_persistence.rs +0 -436
  136. package/dist/create/server-source/crates/feltdb/src/phase_1c_real_tcp.rs +0 -387
  137. package/dist/create/server-source/crates/feltdb/src/phase_2a_failures.rs +0 -378
  138. package/dist/create/server-source/crates/feltdb/src/phase_2b_network.rs +0 -359
  139. package/dist/create/server-source/crates/feltdb/src/phase_2c_cascading.rs +0 -372
  140. package/dist/create/server-source/crates/feltdb/src/phase_3_durability.rs +0 -404
  141. package/dist/create/server-source/crates/feltdb/src/phase_4_baseline.rs +0 -376
  142. package/dist/create/server-source/crates/feltdb/src/phase_5_soak.rs +0 -461
  143. package/dist/create/server-source/crates/feltdb/src/policy_evaluation.rs +0 -2125
  144. package/dist/create/server-source/crates/feltdb/src/production_api.rs +0 -418
  145. package/dist/create/server-source/crates/feltdb/src/provenance.rs +0 -207
  146. package/dist/create/server-source/crates/feltdb/src/query_execution_diagnostics.rs +0 -126
  147. package/dist/create/server-source/crates/feltdb/src/query_performance.rs +0 -218
  148. package/dist/create/server-source/crates/feltdb/src/read_basis.rs +0 -257
  149. package/dist/create/server-source/crates/feltdb/src/references.rs +0 -404
  150. package/dist/create/server-source/crates/feltdb/src/replay_fuzzing.rs +0 -401
  151. package/dist/create/server-source/crates/feltdb/src/replica_acknowledgements.rs +0 -501
  152. package/dist/create/server-source/crates/feltdb/src/replica_membership.rs +0 -680
  153. package/dist/create/server-source/crates/feltdb/src/replication_manager.rs +0 -163
  154. package/dist/create/server-source/crates/feltdb/src/replication_protocol.rs +0 -133
  155. package/dist/create/server-source/crates/feltdb/src/routing.rs +0 -409
  156. package/dist/create/server-source/crates/feltdb/src/semantic_decision.rs +0 -2029
  157. package/dist/create/server-source/crates/feltdb/src/semantic_query.rs +0 -599
  158. package/dist/create/server-source/crates/feltdb/src/sharding.rs +0 -549
  159. package/dist/create/server-source/crates/feltdb/src/state_conflict_contract.rs +0 -516
  160. package/dist/create/server-source/crates/feltdb/src/state_contract.rs +0 -6003
  161. package/dist/create/server-source/crates/feltdb/src/state_diff_contract.rs +0 -222
  162. package/dist/create/server-source/crates/feltdb/src/state_facade.rs +0 -320
  163. package/dist/create/server-source/crates/feltdb/src/state_hash.rs +0 -291
  164. package/dist/create/server-source/crates/feltdb/src/state_model.rs +0 -4158
  165. package/dist/create/server-source/crates/feltdb/src/state_transition_store.rs +0 -379
  166. package/dist/create/server-source/crates/feltdb/src/state_trigger.rs +0 -673
  167. package/dist/create/server-source/crates/feltdb/src/storage.rs +0 -273
  168. package/dist/create/server-source/crates/feltdb/src/submission.rs +0 -471
  169. package/dist/create/server-source/crates/feltdb/src/sync.rs +0 -495
  170. package/dist/create/server-source/crates/feltdb/src/sync_contract.rs +0 -822
  171. package/dist/create/server-source/crates/feltdb/src/tcp_transport.rs +0 -433
  172. package/dist/create/server-source/crates/feltdb/src/transaction_api.rs +0 -462
  173. package/dist/create/server-source/crates/feltdb/src/transaction_invariants.rs +0 -965
  174. package/dist/create/server-source/crates/feltdb/src/transaction_preconditions.rs +0 -1120
  175. package/dist/create/server-source/crates/feltdb/src/transactions.rs +0 -643
  176. package/dist/create/server-source/crates/feltdb/src/trigger.rs +0 -390
  177. package/dist/create/server-source/crates/feltdb/src/trigger_contract.rs +0 -749
  178. package/dist/create/server-source/crates/feltdb/src/versioned_object_substrate.rs +0 -708
  179. package/dist/create/server-source/crates/feltdb/src/worker_mesh.rs +0 -1269
  180. package/dist/create/server-source/crates/feltdb/src/workflow.rs +0 -713
  181. package/dist/create/server-source/crates/feltdb/src/workflow_acceptance_tests.rs +0 -510
  182. package/dist/create/server-source/crates/feltdb/src/workflow_integration.rs +0 -354
  183. package/dist/create/server-source/crates/feltdb/src/workflow_runtime.rs +0 -594
  184. package/dist/create/server-source/crates/feltdb/src/workload.rs +0 -4222
  185. package/dist/create/server-source/crates/feltdb/src/workload_diagnostics.rs +0 -456
  186. package/dist/create/server-source/crates/feltdb/tests/agent_state_native.rs +0 -1188
  187. package/dist/create/server-source/crates/feltdb/tests/agent_transition_contract_conformance.rs +0 -2884
  188. package/dist/create/server-source/crates/feltdb/tests/authority_process.rs +0 -297
  189. package/dist/create/server-source/crates/feltdb/tests/authority_transaction_identity.rs +0 -534
  190. package/dist/create/server-source/crates/feltdb/tests/bounded_read_contract.rs +0 -132
  191. package/dist/create/server-source/crates/feltdb/tests/branching_evidence.rs +0 -299
  192. package/dist/create/server-source/crates/feltdb/tests/common/mod.rs +0 -96
  193. package/dist/create/server-source/crates/feltdb/tests/compaction_stall_contract.rs +0 -272
  194. package/dist/create/server-source/crates/feltdb/tests/crash_durability_contract.rs +0 -467
  195. package/dist/create/server-source/crates/feltdb/tests/current_revision_authority_evidence.rs +0 -309
  196. package/dist/create/server-source/crates/feltdb/tests/durable_backup_contract.rs +0 -445
  197. package/dist/create/server-source/crates/feltdb/tests/durable_corruption_contract.rs +0 -518
  198. package/dist/create/server-source/crates/feltdb/tests/durable_format_compatibility.rs +0 -392
  199. package/dist/create/server-source/crates/feltdb/tests/feltdb_state_boundary_tests.rs +0 -850
  200. package/dist/create/server-source/crates/feltdb/tests/fixtures/agent_transition_corpus.json +0 -23340
  201. package/dist/create/server-source/crates/feltdb/tests/fixtures/state_conflict_contract_corpus.json +0 -1916
  202. package/dist/create/server-source/crates/feltdb/tests/fixtures/state_diff_contract_corpus.json +0 -1878
  203. package/dist/create/server-source/crates/feltdb/tests/fixtures/trigger_contract_corpus.json +0 -1862
  204. package/dist/create/server-source/crates/feltdb/tests/generalized_version_control_evidence.rs +0 -123
  205. package/dist/create/server-source/crates/feltdb/tests/generalized_version_control_substrate_completion.rs +0 -299
  206. package/dist/create/server-source/crates/feltdb/tests/local_process_ownership.rs +0 -69
  207. package/dist/create/server-source/crates/feltdb/tests/managed_incident_regression.rs +0 -191
  208. package/dist/create/server-source/crates/feltdb/tests/operational_health_contract.rs +0 -278
  209. package/dist/create/server-source/crates/feltdb/tests/pr34_query_collection.rs +0 -234
  210. package/dist/create/server-source/crates/feltdb/tests/pr35_equality_index.rs +0 -947
  211. package/dist/create/server-source/crates/feltdb/tests/pr7_self_authorization_proof.rs +0 -404
  212. package/dist/create/server-source/crates/feltdb/tests/pr8_vocabulary_assessment.rs +0 -916
  213. package/dist/create/server-source/crates/feltdb/tests/pr9_phase2_boundary_tests.rs +0 -1045
  214. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3a_path_a_tests.rs +0 -347
  215. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_authorized_mutations.rs +0 -361
  216. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_role_based_authorization.rs +0 -330
  217. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_simple_auth_delete.rs +0 -93
  218. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_team_delete_role_authorization.rs +0 -622
  219. package/dist/create/server-source/crates/feltdb/tests/pr9_teams_role_based_access.rs +0 -517
  220. package/dist/create/server-source/crates/feltdb/tests/production_certification.rs +0 -1153
  221. package/dist/create/server-source/crates/feltdb/tests/production_contract.rs +0 -771
  222. package/dist/create/server-source/crates/feltdb/tests/production_readiness_contract.rs +0 -1383
  223. package/dist/create/server-source/crates/feltdb/tests/reconciliation_application.rs +0 -868
  224. package/dist/create/server-source/crates/feltdb/tests/reconciliation_wire_format_evidence.rs +0 -221
  225. package/dist/create/server-source/crates/feltdb/tests/replicated_history_contract.rs +0 -417
  226. package/dist/create/server-source/crates/feltdb/tests/resource_scoped_revisions.rs +0 -338
  227. package/dist/create/server-source/crates/feltdb/tests/revision_identity_contract.rs +0 -1039
  228. package/dist/create/server-source/crates/feltdb/tests/revision_model_decision.rs +0 -739
  229. package/dist/create/server-source/crates/feltdb/tests/revision_retention_boundary_evidence.rs +0 -452
  230. package/dist/create/server-source/crates/feltdb/tests/saas_authorization_integration.rs +0 -81
  231. package/dist/create/server-source/crates/feltdb/tests/saas_invitation_lifecycle.rs +0 -438
  232. package/dist/create/server-source/crates/feltdb/tests/semantic_decision.rs +0 -1165
  233. package/dist/create/server-source/crates/feltdb/tests/semantic_query.rs +0 -767
  234. package/dist/create/server-source/crates/feltdb/tests/semantic_query_contract.rs +0 -363
  235. package/dist/create/server-source/crates/feltdb/tests/state_conflict_contract_conformance.rs +0 -1799
  236. package/dist/create/server-source/crates/feltdb/tests/state_diff_contract_conformance.rs +0 -1316
  237. package/dist/create/server-source/crates/feltdb/tests/state_model_integration.rs +0 -358
  238. package/dist/create/server-source/crates/feltdb/tests/state_persistence_integration.rs +0 -365
  239. package/dist/create/server-source/crates/feltdb/tests/state_ref_authority.rs +0 -918
  240. package/dist/create/server-source/crates/feltdb/tests/state_store_boundary_evidence.rs +0 -299
  241. package/dist/create/server-source/crates/feltdb/tests/storage_independent_versioned_object_substrate.rs +0 -328
  242. package/dist/create/server-source/crates/feltdb/tests/sync_divergence_evidence.rs +0 -255
  243. package/dist/create/server-source/crates/feltdb/tests/three_way_input_boundary_evidence.rs +0 -249
  244. package/dist/create/server-source/crates/feltdb/tests/trigger_contract_conformance.rs +0 -994
  245. package/dist/create/server-source/crates/feltdb/tests/workload_envelope_contract.rs +0 -484
  246. package/dist/studio-app/assets/feltdb_wasm_bg-TseJn2Ax.wasm +0 -0
  247. package/dist/studio-app/assets/index-1wd0uKua.js +0 -30
@@ -1,484 +0,0 @@
1
- //! Durability modes and the workload envelope.
2
- //!
3
- //! Two questions, in this order:
4
- //!
5
- //! > **What durability contract can FeltDB provide, and what does each one
6
- //! > cost under a frozen workload?**
7
- //!
8
- //! The order matters. Choosing between `flush` and `fsync` first would be
9
- //! picking an implementation before deciding what a successful write should
10
- //! mean.
11
- //!
12
- //! # What this file asserts, and what it does not
13
- //!
14
- //! Measurements on a shared machine are noisy, so the **tests assert
15
- //! relationships** — a barrier per write costs more than none, grouping sits
16
- //! between them — and never absolute numbers. The numbers themselves belong in
17
- //! `docs/architecture/workload-envelope.md`, recorded as *observed under this
18
- //! frozen workload on this environment* rather than as a capacity claim.
19
- //!
20
- //! Nothing here proves power-loss durability. Issuing `fsync` is not evidence
21
- //! that bytes reached a platter: that depends on the filesystem, the mount
22
- //! options and the drive's write cache, none of which this database can
23
- //! observe. D5 stays Unproven, and that is the honest end state.
24
-
25
- use feltdb::state_model::{RetentionPolicy, StateStore};
26
- use feltdb::{AtomicMutation, DurabilityMode, FeltDb};
27
- use serde_json::json;
28
- use std::collections::HashMap;
29
- use std::path::Path;
30
- use std::sync::Arc;
31
- use std::time::{Duration, Instant};
32
- use tempfile::TempDir;
33
-
34
- // ---------------------------------------------------------------------------
35
- // The frozen workload
36
- // ---------------------------------------------------------------------------
37
-
38
- /// A workload is fixed by its shape, not by a wall-clock budget, so two runs
39
- /// measure the same thing.
40
- #[derive(Debug, Clone, Copy)]
41
- struct Workload {
42
- name: &'static str,
43
- writes: usize,
44
- resources: usize,
45
- payload_bytes: usize,
46
- retention: Option<usize>,
47
- }
48
-
49
- /// What one run of a workload cost.
50
- #[derive(Debug, Clone)]
51
- struct Measurement {
52
- elapsed: Duration,
53
- log_bytes: u64,
54
- /// `log_bytes` without this database's instance id. Every record carries
55
- /// that id, and it is derived from the log's path and printed in unpadded
56
- /// hex, so two logs at different paths can differ in size by a few bytes
57
- /// per record while holding identical databases.
58
- identity_free_log_bytes: u64,
59
- revisions: usize,
60
- }
61
-
62
- impl Measurement {
63
- fn writes_per_second(&self, writes: usize) -> f64 {
64
- writes as f64 / self.elapsed.as_secs_f64().max(f64::EPSILON)
65
- }
66
- }
67
-
68
- fn payload(index: usize, bytes: usize) -> serde_json::Value {
69
- json!({ "n": index, "pad": "x".repeat(bytes) })
70
- }
71
-
72
- /// Run one workload under one durability mode. Deterministic in shape.
73
- fn run(directory: &Path, workload: Workload, mode: DurabilityMode) -> Measurement {
74
- let path = directory.join(format!("{}-{:?}.log", workload.name, mode));
75
- let db = Arc::new(FeltDb::open(&path).unwrap());
76
- db.set_durability_mode(mode);
77
- let store = StateStore::with_feltdb(db.clone()).unwrap();
78
-
79
- for resource in 0..workload.resources {
80
- let key = format!("bench:{resource}");
81
- if let Some(keep) = workload.retention {
82
- store
83
- .set_retention_policy(&key, RetentionPolicy::keep_last(keep))
84
- .unwrap();
85
- }
86
- db.insert(&key, payload(0, workload.payload_bytes)).unwrap();
87
- }
88
-
89
- let start = Instant::now();
90
- for index in 1..=workload.writes {
91
- let key = format!("bench:{}", index % workload.resources);
92
- db.update(&key, payload(index, workload.payload_bytes))
93
- .unwrap();
94
- }
95
- let elapsed = start.elapsed();
96
-
97
- let revisions: usize = (0..workload.resources)
98
- .map(|resource| store.history_of(&format!("bench:{resource}")).len())
99
- .sum();
100
-
101
- let log = std::fs::read_to_string(&path).unwrap();
102
- let instance_id = db.instance_id().unwrap();
103
- let identity_bytes = log.matches(instance_id.as_str()).count() * instance_id.len();
104
-
105
- Measurement {
106
- elapsed,
107
- log_bytes: log.len() as u64,
108
- identity_free_log_bytes: (log.len() - identity_bytes) as u64,
109
- revisions,
110
- }
111
- }
112
-
113
- /// The frozen matrix. Changing any row changes what every recorded number
114
- /// means, so the table lives here rather than being chosen per test.
115
- const WORKLOADS: &[Workload] = &[
116
- Workload {
117
- name: "sequential-unbounded",
118
- writes: 300,
119
- resources: 1,
120
- payload_bytes: 100,
121
- retention: None,
122
- },
123
- Workload {
124
- name: "sequential-keep5",
125
- writes: 300,
126
- resources: 1,
127
- payload_bytes: 100,
128
- retention: Some(5),
129
- },
130
- Workload {
131
- name: "sequential-keep50",
132
- writes: 300,
133
- resources: 1,
134
- payload_bytes: 100,
135
- retention: Some(50),
136
- },
137
- Workload {
138
- name: "many-resources",
139
- writes: 300,
140
- resources: 50,
141
- payload_bytes: 100,
142
- retention: None,
143
- },
144
- ];
145
-
146
- // ---------------------------------------------------------------------------
147
- // Durability modes: the contract, then the cost
148
- // ---------------------------------------------------------------------------
149
-
150
- /// **Every mode states what a successful write guarantees.**
151
- ///
152
- /// The point of the enum is that the contract is readable rather than inferred
153
- /// from an API name. `Flushed` does not claim stable storage; `Synced` claims a
154
- /// barrier was *issued* and explicitly not that it landed; `Grouped` names the
155
- /// window of acknowledged writes that may not have been through one.
156
- #[test]
157
- fn every_durability_mode_states_its_own_guarantee() {
158
- let modes = [
159
- DurabilityMode::Flushed,
160
- DurabilityMode::Synced,
161
- DurabilityMode::Grouped { every: 16 },
162
- ];
163
-
164
- for mode in modes {
165
- let guarantee = mode.guarantee();
166
- assert!(!guarantee.is_empty());
167
- assert!(
168
- !guarantee.contains("power-loss safe") && !guarantee.contains("guaranteed durable"),
169
- "{mode:?} overstates: {guarantee}"
170
- );
171
- }
172
-
173
- // The window each mode leaves is explicit rather than implied.
174
- assert_eq!(DurabilityMode::Flushed.unbarriered_window(), None);
175
- assert_eq!(DurabilityMode::Synced.unbarriered_window(), Some(0));
176
- assert_eq!(
177
- DurabilityMode::Grouped { every: 16 }.unbarriered_window(),
178
- Some(15)
179
- );
180
-
181
- // Only one mode claims a barrier per write, and it still does not claim the
182
- // barrier reached the device.
183
- assert!(DurabilityMode::Synced.guarantee().contains("barrier"));
184
- assert!(DurabilityMode::Synced
185
- .guarantee()
186
- .contains("cannot observe"));
187
- }
188
-
189
- /// **The default is the weakest contract**, so nothing is silently promised.
190
- #[test]
191
- fn the_default_mode_is_the_one_whose_cost_was_already_measured() {
192
- let directory = TempDir::new().unwrap();
193
- let db = FeltDb::open(directory.path().join("default.log")).unwrap();
194
- assert_eq!(db.durability_mode(), DurabilityMode::Flushed);
195
- assert_eq!(DurabilityMode::default(), DurabilityMode::Flushed);
196
- }
197
-
198
- /// **A stronger barrier costs more.**
199
- ///
200
- /// Asserted as an ordering rather than as numbers, because the numbers depend
201
- /// on the machine. Per-write `fsync` runs roughly three to four times slower
202
- /// than flush across every row of the frozen matrix, which is large enough to
203
- /// be a property rather than noise.
204
- ///
205
- /// **Grouping is deliberately not asserted to sit between them.** The
206
- /// measurements do not support it at this scale: on the recorded environment
207
- /// grouped/32 came out *slower* than per-write `fsync` on one workload and
208
- /// faster on the others. An assertion that can flip on a shared machine is
209
- /// worse than no assertion, so the observation is recorded in the envelope
210
- /// document and left unasserted here. What grouping buys — a smaller barrier
211
- /// count for a stated window of unbarriered writes — is a contract property,
212
- /// and that *is* asserted, above.
213
- #[test]
214
- fn a_barrier_per_write_costs_more_than_none() {
215
- let directory = TempDir::new().unwrap();
216
- let workload = WORKLOADS[0];
217
-
218
- // A stall can only invert this ordering by inflating the cheap, flushed
219
- // run, so take the best of several of those against one synced run. The
220
- // minimum is the cost of the mode with scheduler contention taken out;
221
- // repeating the slow synced run would only add load to sibling timing
222
- // tests in this concurrently-run binary.
223
- let synced = run(directory.path(), workload, DurabilityMode::Synced);
224
- let flushed = run(directory.path(), workload, DurabilityMode::Flushed);
225
- let mut best_flushed = flushed.elapsed;
226
- for sample in 0..4 {
227
- // A fresh log per sample: a reused path would append to its history.
228
- let sample_directory = directory.path().join(format!("flushed-{sample}"));
229
- std::fs::create_dir_all(&sample_directory).unwrap();
230
- let repeat = run(&sample_directory, workload, DurabilityMode::Flushed);
231
- best_flushed = best_flushed.min(repeat.elapsed);
232
- }
233
-
234
- assert!(
235
- synced.elapsed > best_flushed,
236
- "a barrier per write must cost something: synced {:?} vs flushed {best_flushed:?}",
237
- synced.elapsed
238
- );
239
-
240
- // Durability is the only thing that changed. The database is identical.
241
- assert_eq!(flushed.revisions, synced.revisions);
242
- assert_eq!(
243
- flushed.identity_free_log_bytes,
244
- synced.identity_free_log_bytes
245
- );
246
- }
247
-
248
- /// Changing the mode changes the contract and nothing else: the same writes
249
- /// produce the same database.
250
- ///
251
- /// Run against **one path**, deliberately. An authority's identity is derived
252
- /// from its path, and a revision records the authority that committed it, so
253
- /// two databases in different directories never share a history digest even
254
- /// with identical logical history. That is correct — provenance is part of what
255
- /// happened — and it means a comparison like this has to reuse the path rather
256
- /// than compare two locations.
257
- #[test]
258
- fn the_durability_mode_does_not_change_what_is_stored() {
259
- let directory = TempDir::new().unwrap();
260
- let path = directory.path().join("same.log");
261
- let mut digests = Vec::new();
262
-
263
- for mode in [
264
- DurabilityMode::Flushed,
265
- DurabilityMode::Synced,
266
- DurabilityMode::Grouped { every: 4 },
267
- ] {
268
- let _ = std::fs::remove_file(&path);
269
- let db = Arc::new(FeltDb::open(&path).unwrap());
270
- db.set_durability_mode(mode);
271
- db.insert("tasks:1", json!({"n": 0})).unwrap();
272
- for n in 1..12 {
273
- db.update("tasks:1", json!({ "n": n })).unwrap();
274
- }
275
- let store = StateStore::with_feltdb(db.clone()).unwrap();
276
- digests.push((db.state_digest().unwrap(), store.history_digest()));
277
- }
278
-
279
- assert_eq!(digests[0], digests[1]);
280
- assert_eq!(digests[0], digests[2]);
281
- }
282
-
283
- /// A grouped database still recovers cleanly, because the flush — not the
284
- /// barrier — is what makes a record survive a process crash.
285
- #[test]
286
- fn every_mode_recovers_to_a_clean_prefix() {
287
- for mode in [
288
- DurabilityMode::Flushed,
289
- DurabilityMode::Synced,
290
- DurabilityMode::Grouped { every: 4 },
291
- ] {
292
- let directory = TempDir::new().unwrap();
293
- let path = directory.path().join("recover.log");
294
- let db = Arc::new(FeltDb::open(&path).unwrap());
295
- db.set_durability_mode(mode);
296
- db.insert("tasks:1", json!({"n": 0})).unwrap();
297
- db.update("tasks:1", json!({"n": 1})).unwrap();
298
- db.update("tasks:1", json!({"n": 2})).unwrap();
299
- drop(db);
300
-
301
- let full = std::fs::read(&path).unwrap();
302
- for cut in (0..=full.len()).step_by(29) {
303
- std::fs::write(&path, &full[..cut]).unwrap();
304
- let db = Arc::new(FeltDb::open(&path).unwrap());
305
- let store = StateStore::with_feltdb(db.clone()).unwrap();
306
- let value = db
307
- .get::<serde_json::Value>("tasks:1")
308
- .unwrap()
309
- .map(|value| value["n"].as_i64().unwrap());
310
- assert_eq!(
311
- store.history_of("tasks:1").len(),
312
- value.map(|n| n as usize + 1).unwrap_or(0),
313
- "{mode:?} at cut {cut}"
314
- );
315
- }
316
- }
317
- }
318
-
319
- /// **Transactions already carry the strongest contract**, whatever the
320
- /// single-record mode is.
321
- ///
322
- /// `append_transaction` issues a barrier unconditionally. So a caller who needs
323
- /// stable-storage semantics for a group of records has had a way to ask for it
324
- /// all along, which is a real option in the trade-off rather than a workaround.
325
- #[test]
326
- fn a_transaction_commits_under_a_barrier_regardless_of_the_mode() {
327
- let directory = TempDir::new().unwrap();
328
- let path = directory.path().join("txn.log");
329
- let db = Arc::new(FeltDb::open(&path).unwrap());
330
- // Even at the weakest single-record contract.
331
- db.set_durability_mode(DurabilityMode::Flushed);
332
-
333
- db.apply_atomic_transaction(
334
- "t1",
335
- None,
336
- &[],
337
- &[AtomicMutation {
338
- capability: "acct".into(),
339
- key: "acct:a".into(),
340
- value: Some(json!({"balance": 1})),
341
- }],
342
- None,
343
- )
344
- .unwrap();
345
-
346
- let value: serde_json::Value = db.get("acct:a").unwrap().unwrap();
347
- assert_eq!(value["balance"], json!(1));
348
- assert_eq!(
349
- db.durability_mode(),
350
- DurabilityMode::Flushed,
351
- "the transaction path is independent of the single-record contract"
352
- );
353
- }
354
-
355
- // ---------------------------------------------------------------------------
356
- // The envelope
357
- // ---------------------------------------------------------------------------
358
-
359
- /// **Retention cost grows with the window, and the log grows with retention.**
360
- ///
361
- /// Both directions of the trade-off the retention work exposed, now measured
362
- /// across the frozen matrix rather than one ad-hoc run. Asserted as ordering.
363
- #[test]
364
- fn the_retention_envelope_has_the_measured_shape() {
365
- let directory = TempDir::new().unwrap();
366
-
367
- // This binary runs its envelope cases concurrently. Use the best of three
368
- // complete, isolated samples so scheduler and filesystem contention cannot
369
- // invert a wall-clock ordering while retaining the frozen workload shape.
370
- let sample = |workload: Workload| {
371
- (0..3)
372
- .map(|index| {
373
- let sample_directory = directory.path().join(format!(
374
- "retention-{}-{index}",
375
- workload.name
376
- ));
377
- std::fs::create_dir_all(&sample_directory).unwrap();
378
- run(&sample_directory, workload, DurabilityMode::Flushed)
379
- })
380
- .min_by_key(|measurement| measurement.elapsed)
381
- .unwrap()
382
- };
383
-
384
- let unbounded = sample(WORKLOADS[0]);
385
- let keep5 = sample(WORKLOADS[1]);
386
- let keep50 = sample(WORKLOADS[2]);
387
-
388
- assert_eq!(unbounded.revisions, 301, "unbounded keeps everything");
389
- assert_eq!(keep5.revisions, 5);
390
- assert_eq!(keep50.revisions, 50);
391
-
392
- assert!(
393
- keep50.elapsed > keep5.elapsed,
394
- "a wider window costs more per write: keep50 {:?} vs keep5 {:?}",
395
- keep50.elapsed,
396
- keep5.elapsed
397
- );
398
- assert!(
399
- keep5.log_bytes > unbounded.log_bytes,
400
- "expiry tombstones inflate the log before compaction: {} vs {}",
401
- keep5.log_bytes,
402
- unbounded.log_bytes
403
- );
404
- }
405
-
406
- /// Spreading writes over many resources does not change what is stored per
407
- /// write, and history stays per-resource.
408
- #[test]
409
- fn many_resources_keep_independent_bounded_histories() {
410
- let directory = TempDir::new().unwrap();
411
- let measurement = run(directory.path(), WORKLOADS[3], DurabilityMode::Flushed);
412
- assert_eq!(
413
- measurement.revisions, 350,
414
- "50 initial writes plus 300 updates, spread evenly"
415
- );
416
- }
417
-
418
- /// Replaying a database costs time proportional to what it holds, and recovery
419
- /// is part of the envelope an operator has to size for.
420
- #[test]
421
- fn restart_cost_is_measurable_and_bounded_by_retention() {
422
- let directory = TempDir::new().unwrap();
423
-
424
- // Two databases with the same writes and different retention.
425
- let unbounded = run(directory.path(), WORKLOADS[0], DurabilityMode::Flushed);
426
- let bounded = run(directory.path(), WORKLOADS[1], DurabilityMode::Flushed);
427
-
428
- let reopen = |name: &str| {
429
- let path = directory
430
- .path()
431
- .join(format!("{name}-{:?}.log", DurabilityMode::Flushed));
432
- let start = Instant::now();
433
- let db = FeltDb::open(&path).unwrap();
434
- let elapsed = start.elapsed();
435
- drop(db);
436
- elapsed
437
- };
438
-
439
- let _ = reopen("sequential-unbounded");
440
- let _ = reopen("sequential-keep5");
441
-
442
- // The claim is that both reopen, and that retention bounds what has to be
443
- // held afterwards — not a timing threshold, which would be noise.
444
- assert!(unbounded.revisions > bounded.revisions * 10);
445
- }
446
-
447
- /// The whole frozen matrix runs under every mode, which is what makes the
448
- /// recorded table reproducible rather than a set of one-off numbers.
449
- #[test]
450
- fn the_frozen_matrix_runs_under_every_durability_mode() {
451
- let directory = TempDir::new().unwrap();
452
- let mut rows = 0;
453
-
454
- for workload in WORKLOADS {
455
- for mode in [
456
- DurabilityMode::Flushed,
457
- DurabilityMode::Grouped { every: 32 },
458
- DurabilityMode::Synced,
459
- ] {
460
- let measurement = run(directory.path(), *workload, mode);
461
- assert!(measurement.writes_per_second(workload.writes) > 0.0);
462
- assert!(measurement.log_bytes > 0);
463
- rows += 1;
464
- }
465
- }
466
-
467
- assert_eq!(rows, WORKLOADS.len() * 3, "every cell of the matrix ran");
468
- }
469
-
470
- /// A measured number is not a capacity claim, and the harness records the
471
- /// workload alongside it so it cannot be quoted without one.
472
- #[test]
473
- fn a_measurement_carries_the_workload_that_produced_it() {
474
- let directory = TempDir::new().unwrap();
475
- let workload = WORKLOADS[1];
476
- let measurement = run(directory.path(), workload, DurabilityMode::Flushed);
477
-
478
- // Everything needed to reproduce or dispute the number.
479
- assert_eq!(workload.writes, 300);
480
- assert_eq!(workload.resources, 1);
481
- assert_eq!(workload.payload_bytes, 100);
482
- assert_eq!(workload.retention, Some(5));
483
- assert!(measurement.writes_per_second(workload.writes).is_finite());
484
- }