diff --git a/.github/workflows/backend-ferretdb.yml b/.github/workflows/backend-ferretdb.yml deleted file mode 100644 index 9c6ab7fd24..0000000000 --- a/.github/workflows/backend-ferretdb.yml +++ /dev/null @@ -1,168 +0,0 @@ -name: Backend on FerretDB - -# Self-hosted Commonly can run its Mongo layer on FerretDB, which speaks the -# Mongo wire protocol and stores the data in Postgres (the DocumentDB -# extension). Prod stays on MongoDB. This leg runs the backend unit tier -# against FerretDB, and the same harness against MongoDB beside it, so a change -# that only works on Mongo shows up here instead of on a self-hoster's box. -# -# Nightly and on dispatch only, until FerretDB is green. On pull requests its -# failing jobs would mark every backend PR UNSTABLE, and the press takes CLEAN -# PRs only. Add `pull_request` back once the FerretDB legs pass. The FerretDB -# legs never fail the run while it is known red: the step summary lists every -# failing suite per store, with MongoDB run beside it. -# -# The image bundles PostGIS (GPL-2.0-or-later). We pull it by reference as a CI service -# and do not redistribute it. - -on: - schedule: - - cron: '30 8 * * *' - workflow_dispatch: - -concurrency: - group: backend-ferretdb-${{ github.event_name }}-${{ github.ref }} - cancel-in-progress: true - -permissions: - contents: read - -jobs: - backend: - name: Backend on ${{ matrix.store }} (${{ matrix.shard }}/3) - runs-on: ubuntu-latest - timeout-minutes: 60 - continue-on-error: ${{ matrix.store == 'ferretdb' }} - strategy: - fail-fast: false - matrix: - store: [ferretdb, mongo] - shard: [1, 2, 3] - services: - documentdb: - image: ghcr.io/ferretdb/postgres-documentdb:17-0.107.0-ferretdb-2.7.0 - env: - POSTGRES_USER: ferret - POSTGRES_PASSWORD: ferret - POSTGRES_DB: postgres - options: >- - --health-cmd "pg_isready -U ferret" - --health-interval 5s --health-timeout 5s --health-retries 20 - ferretdb: - image: ghcr.io/ferretdb/ferretdb:2.7.0 - env: - FERRETDB_POSTGRESQL_URL: postgres://ferret:ferret@documentdb:5432/postgres - FERRETDB_AUTH: 'false' - ports: - - 27018:27017 - mongo: - image: mongo:7.0.14 - ports: - - 27017:27017 - env: - JWT_SECRET: test-jwt-secret - FRONTEND_URL: http://localhost:3000 - # Read by __tests__/utils/testUtils.js: each suite gets its own database - # on this server instead of an in-memory mongod. - JEST_EXTERNAL_MONGO_URI: ${{ matrix.store == 'ferretdb' && 'mongodb://localhost:27018' || 'mongodb://localhost:27017' }} - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: '22' - cache: npm - cache-dependency-path: backend/package-lock.json - - run: cd backend && npm ci --include=dev - # Backend service suites exercise the real CLI in a subprocess. - - run: cd cli && npm ci --include=dev - - name: Wait for the store - run: | - cd backend - for _ in $(seq 1 60); do - node -e "require('mongoose').connect(process.env.JEST_EXTERNAL_MONGO_URI + '/ping', { serverSelectionTimeoutMS: 2000 }).then(() => process.exit(0), () => process.exit(1))" && exit 0 - sleep 2 - done - echo "store at $JEST_EXTERNAL_MONGO_URI never answered"; exit 1 - - name: Run backend tests - run: | - cd backend - npx jest --forceExit --shard=${{ matrix.shard }}/3 --json --outputFile=jest-results.json - - name: List failing suites - if: always() - run: | - cd backend - if [ ! -f jest-results.json ]; then - echo "### ${{ matrix.store }} shard ${{ matrix.shard }}: no results (jest timed out or crashed)" >> "$GITHUB_STEP_SUMMARY" - exit 0 - fi - node -e " - const r = require('./jest-results.json'); - const failed = r.testResults.filter((t) => t.status === 'failed'); - const lines = ['### ${{ matrix.store }} shard ${{ matrix.shard }}: ' + failed.length + ' failing suites of ' + r.numTotalTestSuites, '']; - for (const t of failed) { - const first = (t.message || '').split('\n').find((l) => /Error|Expected|MongoServerError/.test(l)) || ''; - lines.push('- ' + t.name.replace(process.cwd() + '/', '') + ': ' + first.trim().slice(0, 200).replace(/\u001b\[[0-9;]*m/g, '')); - } - require('fs').appendFileSync(process.env.GITHUB_STEP_SUMMARY, lines.join('\n') + '\n'); - " - - uses: actions/upload-artifact@v4 - if: always() - with: - name: backend-${{ matrix.store }}-${{ matrix.shard }} - path: backend/jest-results.json - if-no-files-found: ignore - - # Auth hot-path latency, each store on its own runner (__tests__/bench). - # Runners vary, so read the two stores' numbers side by side within one run. - bench: - name: Auth bench on ${{ matrix.store }} - if: github.event_name != 'schedule' - runs-on: ubuntu-latest - timeout-minutes: 30 - strategy: - fail-fast: false - matrix: - store: [ferretdb, mongo] - services: - documentdb: - image: ghcr.io/ferretdb/postgres-documentdb:17-0.107.0-ferretdb-2.7.0 - env: - POSTGRES_USER: ferret - POSTGRES_PASSWORD: ferret - POSTGRES_DB: postgres - options: >- - --health-cmd "pg_isready -U ferret" - --health-interval 5s --health-timeout 5s --health-retries 20 - ferretdb: - image: ghcr.io/ferretdb/ferretdb:2.7.0 - env: - FERRETDB_POSTGRESQL_URL: postgres://ferret:ferret@documentdb:5432/postgres - FERRETDB_AUTH: 'false' - ports: - - 27018:27017 - mongo: - image: mongo:7.0.14 - ports: - - 27017:27017 - env: - JWT_SECRET: test-jwt-secret - BENCH_LABEL: ${{ matrix.store }} - BENCH_URI: ${{ matrix.store == 'ferretdb' && 'mongodb://localhost:27018' || 'mongodb://localhost:27017' }} - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: '22' - cache: npm - cache-dependency-path: backend/package-lock.json - - run: cd backend && npm ci --include=dev - - name: Wait for the store - run: | - cd backend - for _ in $(seq 1 60); do - node -e "require('mongoose').connect(process.env.BENCH_URI + '/ping', { serverSelectionTimeoutMS: 2000 }).then(() => process.exit(0), () => process.exit(1))" && exit 0 - sleep 2 - done - echo "store at $BENCH_URI never answered"; exit 1 - - name: Run the bench - run: cd backend && npx jest __tests__/bench --testPathIgnorePatterns=/node_modules/ --forceExit diff --git a/backend/__tests__/bench/authHotPath.bench.js b/backend/__tests__/bench/authHotPath.bench.js index fb4b93cb81..992867a679 100644 --- a/backend/__tests__/bench/authHotPath.bench.js +++ b/backend/__tests__/bench/authHotPath.bench.js @@ -1,7 +1,6 @@ /** - * Auth hot-path latency on one store, for the FerretDB CI leg - * (.github/workflows/backend-ferretdb.yml, bench job). Not part of the suite: - * jest.config.js ignores __tests__/bench/, and the bench job runs it on its own. + * Auth hot-path latency on one store, measured for ADR-034 D7. Not part of the + * suite: jest.config.js ignores __tests__/bench/, so run it by hand. * * BENCH_URI=mongodb://localhost:27018 BENCH_LABEL=ferretdb \ * npx jest __tests__/bench --testPathIgnorePatterns=/node_modules/ diff --git a/backend/__tests__/utils/externalMongoMemoryServer.js b/backend/__tests__/utils/externalMongoMemoryServer.js index 5e377b125c..059f5660c0 100644 --- a/backend/__tests__/utils/externalMongoMemoryServer.js +++ b/backend/__tests__/utils/externalMongoMemoryServer.js @@ -1,9 +1,9 @@ /** - * Stands in for `mongodb-memory-server` when JEST_EXTERNAL_MONGO_URI is set (the - * FerretDB CI leg, .github/workflows/backend-ferretdb.yml). jest.config.js maps + * Stands in for `mongodb-memory-server` when JEST_EXTERNAL_MONGO_URI is set. + * jest.config.js maps * the package here only then, so a suite that starts its own server with - * `MongoMemoryServer.create()` runs against the store under test instead of an - * in-memory mongod that would answer the same on both legs. + * `MongoMemoryServer.create()` runs against that server instead of an in-memory + * mongod. * * Each create() gets its own database on that server, dropped by stop(). * `new MongoMemoryServer(...)` is left as the real class: the one suite that diff --git a/backend/__tests__/utils/testUtils.js b/backend/__tests__/utils/testUtils.js index 67a4e9a616..e4d2f7f605 100644 --- a/backend/__tests__/utils/testUtils.js +++ b/backend/__tests__/utils/testUtils.js @@ -77,10 +77,9 @@ const setupMongoDb = async () => { return; } - // JEST_EXTERNAL_MONGO_URI runs the unit tier against another server, for the - // FerretDB CI leg (self-host stores Mongo data in Postgres through - // FerretDB). Each suite gets its own database and drops it on close. The - // name is new on purpose: the compose files already set TEST_MONGO_URI, + // JEST_EXTERNAL_MONGO_URI runs the unit tier against another server. Each + // suite gets its own database and drops it on close. The name is new on + // purpose: the compose files already set TEST_MONGO_URI, // and `./dev.sh test` must stay in-memory. if (process.env.JEST_EXTERNAL_MONGO_URI) { /* eslint-disable global-require */ diff --git a/backend/jest.config.js b/backend/jest.config.js index e5c4ea4902..f02a118745 100644 --- a/backend/jest.config.js +++ b/backend/jest.config.js @@ -9,7 +9,7 @@ module.exports = { // and rejects `maxWorkers: undefined` ("has to be of type string or number"), so // on CI the key must be absent entirely, not present-and-undefined. ...(process.env.CI ? {} : { maxWorkers: 2 }), - // The FerretDB leg points every suite at one server: suites that start their + // JEST_EXTERNAL_MONGO_URI points every suite at one server: suites that start their // own MongoMemoryServer get a database on it instead (externalMongoMemoryServer). ...(process.env.JEST_EXTERNAL_MONGO_URI ? { moduleNameMapper: { '^mongodb-memory-server$': '/__tests__/utils/externalMongoMemoryServer.js' }, @@ -25,7 +25,7 @@ module.exports = { // (!**/__tests__/utils/**); this makes the two agree. '__tests__/utils/', '__tests__/setup.js', - // Benchmarks run on their own (the FerretDB workflow's bench job). + // Benchmarks run on their own. '__tests__/bench/', ], // Pre-download/cache the mongod binary ONCE before any worker starts so diff --git a/docs/adr/ADR-034-postgres-single-store.md b/docs/adr/ADR-034-postgres-single-store.md index 2c82121b19..7f0b8f79d2 100644 --- a/docs/adr/ADR-034-postgres-single-store.md +++ b/docs/adr/ADR-034-postgres-single-store.md @@ -7,13 +7,12 @@ direction does not settle three things, and each is named where it lives:** the mismatch log that a read cut may tolerate (D3 sets it at zero unexplained mismatches, which may prove too strict for models with clock-derived fields). -**Amended 2026-11-05 (D7).** A self-hosted instance can run its Mongo layer on FerretDB, which -stores it in Postgres, so self-host gets to one database engine before the per-model migration -does. Production stays on MongoDB. D1 to D6 are unchanged as the direction; the model-by-model -work (the dual-store helper and the D6 waves) is paused while D7 ships. **Open in D7:** latency -under real load (the CI bench seeds its store); deadlocks between concurrent writers that don't -upsert; failing suites not yet traced to a group; and the compose and Helm path plus a clean-install -walk, which are not built, so a self-hoster can't pick FerretDB from them yet. +**Amended 2026-11-05 (D7: considered, not adopted).** Running self-host's Mongo layer on FerretDB +was measured and walked, and the founder dropped it the same day: FerretDB's last release is v2.7.0 +(2025-11-10). **Self-host is MongoDB plus Postgres**, and that path is walked nightly. The +migration to Postgres only is paused until the founder reopens it, so the open waves in D6 are not +work in progress. What already shipped stays enforced: the D4 freeze on new Mongo models fails CI, +and `requirePgConfigured` stands. D7 stays below as the record. **Deciders:** founder (direction), eng lead (plan). @@ -27,9 +26,7 @@ walk, which are not built, so a self-hoster can't pick FerretDB from them yet. - **The vector search index** (`services/vectorSearchService.ts`, a local SQLite file with `sqlite-vec`) is derived from pod content and rebuilt from it. It is an index, not a store of record. - **ADR-011** (shell-first): this is kernel work and launch does not wait on it. -- **FerretDB (D7) is a deployment choice for self-host, not the target store.** It changes which - server answers the Mongo wire protocol on an instance that picks it, and nothing about where a - model's data is meant to end up. Code still talks to Mongoose; D1 to D6 still describe the move off it. +- **FerretDB (D7) was considered and not adopted.** No supported install uses it. ## Context: the split, measured at `origin/main` `e2cb8c2fc` (2026-11-02) @@ -182,13 +179,18 @@ step 1 is the only step that edits callers: The waves hold 66 models. `Message` leaves in Wave 0, and the three models added after the first count join Wave 1, which accounts for all 70. The order inside Wave 5 is open. -### D7. Self-host may run the Mongo layer on FerretDB (amended 2026-11-05) +### D7. FerretDB for self-host's Mongo layer: considered, not adopted (2026-11-05) +**Outcome.** Not adopted. Commonly ships no compose or Helm path for it, and a self-hoster shouldn't +pick it. FerretDB has had no release since v2.7.0 (2025-11-10). The DocumentDB project's own gateway +(`pg_documentdb_gw`) was named as an alternative, and that spike was stopped before it produced a +result. What follows records what was measured, in the present tense of that day. + FerretDB 2.7 (Apache-2.0) speaks the Mongo wire protocol and keeps the data in Postgres through -the DocumentDB extension (MIT). A self-hoster then runs Postgres alone: the chat tables and the +the DocumentDB extension (MIT). A self-hoster would then run Postgres alone: the chat tables and the Mongo layer on one engine. Production stays on MongoDB. **Measured.** The backend suite, run on both stores through the same harness (each suite gets its -own database on a real server; `TEST_MONGO_URI`, `.github/workflows/backend-ferretdb.yml`), at +own database on a real server; `JEST_EXTERNAL_MONGO_URI`, `.github/workflows/backend-ferretdb.yml`), at `20c6bfb4` (main as of 2026-11-05 plus that harness, #3492), without the fixes below. CI run 42001537424; #3492 lists every suite: @@ -220,22 +222,16 @@ missing collection errors. The rest of what Commonly leans on behaves the same: `findOneAndUpdate` claims, `$inc`, TTL indexes, partial indexes on equality and `$exists`, `$text`, `$lookup`, pipeline updates, `arrayFilters`, majority write concern. -**Rules for new Mongo-layer code**, so self-host does not rot: no collation, no `$in` (or other +**Rules proposed for new Mongo-layer code, which don't bind now that D7 isn't adopted:** no collation, no `$in` (or other operator) in a partial index filter, and every check for a lost race goes through `isDuplicateKeyError`. A known gap: existing refusals that read `keyPattern` (signup, username -change and a few others) still surface a code-1 refusal as a 500 on FerretDB (#3495 lists them). The -FerretDB workflow (`backend-ferretdb.yml`, #3492) runs the suite on both stores nightly and on -dispatch. It stays off pull requests while FerretDB is red: a failing job marks every backend PR -UNSTABLE even under `continue-on-error`, and the press takes only CLEAN PRs. It moves to pull -requests, as a required check, once it is green. A nightly walk of the self-host path itself, on -both stores, is #3516. +change and a few others) still surface a code-1 refusal as a 500 on FerretDB (#3495 lists them). The FerretDB CI workflow (#3492) was removed when D7 was not adopted. **Constraints.** The DocumentDB extension needs a superuser and `shared_preload_libraries` (`pg_cron`, `documentdb`), so it runs on a Postgres the instance owns, not on a managed one. The `ferretdb/postgres-documentdb` image also bundles PostGIS (GPL-2.0-or-later). Commonly references -that image by tag only in CI (`backend-ferretdb.yml`) and does not redistribute it. Compose and Helm -support is not built yet; when it lands it references the image the same way, and a self-hoster -pulls it from its publisher. +that image by tag only in that CI workflow and did not redistribute it. Compose and Helm support +was drafted in #3506 and not merged. **Auth hot path** (CI bench `backend/__tests__/bench/authHotPath.bench.js`: 5,000 users, 2,000 pods, 3,000 timed runs after 200 warm-up, the same three hand-built indexes on both stores, each store on @@ -250,7 +246,13 @@ trip, not a cold read: | User by username (login) | 0.94 / 1.07 / 1.70 | 0.63 / 0.69 / 0.90 | FerretDB adds about 0.3 to 1 ms at p95 per query, the write the most: inside a request's budget for -a self-hosted instance, and the reason production stays on MongoDB until the Postgres port. +a self-hosted instance. + +**Clean-install walk, 2026-11-05.** The local compose profile with the unmerged FerretDB override +reached sign-up, pods and messages. A bring-your-own agent failed at attach, because issuing a +runtime token writes with a collation (`update.updates.collation` is not supported). With the unmerged +fixes applied (#3491, #3493, #3495 on #3506), Claude Code answered an @mention. None of those PRs +was merged for this decision. ## Risks - **Copy drift is a bug we already have.** The Postgres `pods`, `pod_members` and `users` rows are synced diff --git a/docs/database/DATABASE.md b/docs/database/DATABASE.md index 1af6ca530e..2e3fd09c7b 100644 --- a/docs/database/DATABASE.md +++ b/docs/database/DATABASE.md @@ -366,13 +366,11 @@ and pod" or "one open row per identical request" has to hold under concurrent wr - **Identity gets its own index.** Identical concurrent callers walk the slots in the same order and usually collide on the same slot. They don't when a lower slot frees mid-race, so a second partial unique index on the identity key is what guarantees one open row. -- **Decide which index refused by reading the data, not the error.** FerretDB can answer a - lost race with a code-1 error that has no `keyPattern` (ADR-034). +- **Decide what a refusal means by reading the data, not the error.** A slot refusal doesn't say + whether an identical open row exists; only the rows do. - **Adding a unique index to a collection that already has data:** make it partial on a field only new code writes (`toolCallSlot: { $exists: true }`). Older rows, including any existing duplicates, are never indexed, so the boot-time `autoIndex` build cannot fail on them. - Partial filters use equality and `$exists` only; FerretDB refuses `$in` and other operators - there (ADR-034). ### Pattern: a terminal transition whose side effects can be retried diff --git a/docs/database/POSTGRESQL_MIGRATION.md b/docs/database/POSTGRESQL_MIGRATION.md index c8f871aec7..9b2edeffae 100644 --- a/docs/database/POSTGRESQL_MIGRATION.md +++ b/docs/database/POSTGRESQL_MIGRATION.md @@ -1,7 +1,8 @@ # PostgreSQL Message Storage Migration -> **Where this is heading:** [ADR-034](../adr/ADR-034-postgres-single-store.md) makes Postgres the single -> data store and records the measured split as of 2026-11-02. The table below describes chat only. +> **Where this was heading:** [ADR-034](../adr/ADR-034-postgres-single-store.md) set Postgres as the single +> data store and records the measured split as of 2026-11-02. That migration is paused. The table below +> describes chat only. For schema upgrades and the repository extraction template, see [Versioned PostgreSQL changes](schema-migrations.md).