# Bedrock 集群 RPC 原型归档 `codex/cluster-rpc-archive` 保存 Bedrock 早期的三个 Rust RPC 原型,供以后对照契约和传输实现。原型开发已暂停。Bedrock 的逻辑集群工作在 `codex/cluster-research` 的 `crates/clusters` 内继续。[研究分支 PR #33](https://gitea.entroia.com/Zayden-Jung/Bedrock/pulls/33) | 原工作分支 | 值得查看的内容 | 完整版本 | | --- | --- | --- | | `codex/typed-service-bindings` | 同一份 Rust 声明生成 HTTP 客户端和 Axum 路由。部署状态查询接入管理监听器,集成测试覆盖鉴权和无效请求。归档分支默认展示这套源码。 | [`46b85a9`](https://gitea.entroia.com/Zayden-Jung/Bedrock/src/commit/46b85a9d474cafad1034b1d249c736cc8cfa2ce4) | | `codex/typed-service-contracts` | 版本化服务名和稳定的方法编号驱动客户端与服务端分派。进程内测试和回环 TCP 示例展示同一契约如何适配不同传输。 | [`7a7ee45`](https://gitea.entroia.com/Zayden-Jung/Bedrock/src/commit/7a7ee457614461382e3a815a78617dd675dcc48e) | | `codex/cluster-rpc` | 保存整理前的开发现场。HTTP 实现与方法编号版的示例、测试和依赖清单处于混用状态。此版本用于追溯中间改动。 | [`6a81ed9`](https://gitea.entroia.com/Zayden-Jung/Bedrock/src/commit/6a81ed95a177df9c1703009faadc4696e0454855) | 三个链接分别打开各自的源码树。这些提交都在本分支的合并历史中。原型中的 `crates/bedrock-rpc` 记录了当时单独分包的实验;后续实现可参考其中的契约和测试。以下为 HTTP 原型原有的项目说明。 ## Bedrock storage Bedrock stores JSON documents in SQLite, PostgreSQL or MySQL. Each backend has its own module in the `database` crate. SQLite is the default and creates `bedrock.sqlite3` in the current directory on first start. ## Storage boundaries `database` owns the transactional document data, revisions, and snapshots used by the application. `clusters` resolves deployment settings. The `database` connection module selects the SQL driver and read endpoints. The backend modules share document types, validation, and encoding in `common.rs`. Notion describes sharding online PostgreSQL block data by workspace and feeding a downstream S3 data lake from PostgreSQL changes. Bedrock supports named SQL roles and read replicas. The catalog can describe S3 buckets. Object I/O, workspace routing, and data-lake ingestion are future work. [Notion's PostgreSQL sharding](https://www.notion.com/blog/sharding-postgres-at-notion) · [Notion's data lake](https://www.notion.com/blog/building-and-scaling-notions-data-lake) ## Cluster service calls [bedrock-rpc](crates/bedrock-rpc/README.md) generates typed clients, handlers, and Axum routes from a shared Rust declaration. The first contract reads deployment status via `POST /admin/v1/deployment/status` with JSON body `{}` and the admin listener's existing bearer authentication. ## Web backend Run the Axum service with `cargo run --locked -p backend`. One process owns the database connection, loads one deployment configuration, and serves separate routers on the business and optional admin listeners. | Listener | Setting and default | Routes | |---|---|---| | Business | `BEDROCK_BACKEND_LISTEN`, default `127.0.0.1:8080` | `GET /healthz`, `GET /readyz` | | Admin | `BEDROCK_ADMIN_LISTEN`, default `127.0.0.1:8081` when enabled | `GET /healthz`, `GET /readyz`, `GET /admin/v1/status`, `POST /admin/v1/deployment/status` | The business readiness probe checks access to the current deployment revision. Set `BEDROCK_ADMIN_TOKEN` from a private credential source to enable the admin listener. Send it as `Authorization: Bearer ` for the status endpoint. Keep the admin listener on loopback or behind an internal TLS endpoint. The `admin_backend` library reports the deployment, storage driver, read-only mode, and the loaded configuration version for the instance that served the request. `BEDROCK_CONFIG_VERSION` can override the reported version label. The admin router reads the same resolved configuration the process used to open the database. Give every replica the same config file and version label through your deployment process. Run `cargo run --locked -p backend -- --init-storage` for one-shot storage initialization. The release process uses the same mode. ## Database configuration Set `BEDROCK_DB_CONFIG` to a private YAML deployment configuration. See the [multi-storage example](deploy/kubernetes/multi-storage.yaml). TOML and existing JSON files also load through the same configuration model. `resources` lists named backends, each with a `kind` and its own settings. `bindings` maps roles such as `documents` or `attachments` to those resources. The executable logs the configuration version and initializes bound SQL resources at startup. Existing `cluster`, `clusters`, `sql`, `object_storage`, and `sqlite_path` inputs are migrated to this shape when loaded. The database must already exist for PostgreSQL and MySQL. Bedrock creates its own tables and deployment row on a writable startup. Network endpoints use TLS with certificate and hostname verification by default. For a private test database without TLS, set the SQL resource's `tls` to `"disabled"`. A top-level `"read_only": true` opens an existing deployment without initializing it. For SQLite, set the resource's `primary` to the file path. Applications use `database::connect` for the documents role or `database::connect_sql` for an explicitly resolved SQL role. A write batch commits at one new revision if its expected deployment revision still matches. Reads can target the primary or prefer replicas. Use an explicit revision to require that snapshot and fall back when replicas have fallen behind. A tombstone removes a document from subsequent snapshots while preserving earlier revisions. JSON null remains a stored value. For MySQL, use `Connection::mysql_writer` to acquire, renew or release a writer lease. An active lease blocks ordinary writes. Use `commit_with_lease` while holding it. `delete_deployment` requires an active lease, deletes that deployment's documents and permanently retires its ID in the database. See [deployment configuration](deploy/README.md) for the PostgreSQL configuration renderer and deployment-only variables.