Commit Graph
4 Commits
Author SHA1 Message Date
Lauri Ojansivu bc79de8c57 Database health: a collection scan row names the command, the operators per field and the queryHash.
A row said only which fields a slow query filtered on, which is not enough
to find the query in the code or to run explain(). It now shows the command
(for a slow getMore, the query it continues, instead of 'filter on nothing'),
the operators used on each field - never values - and MongoDB's queryHash.

Thanks to Raymond-Voogt and xet7 !

Fixes #6856,
2026-11-02 11:31:47 +02:00
Lauri Ojansivu b87858baaf Problems / Database: report queries without an index and a high read rate.
The database health probe (server/lib/databaseHealth.js) saw restarts, slow
storage and a full disk, but not what made one instance slow: a 10 GB
collection scanned three times per search, and an hourly job reading all
1.1 million cards (#6824, #6825). Both were visible only in MongoDB's own
log, as "Slow query" lines with COLLSCAN, and in serverStatus: 1.6 billion
documents read in two hours.

Two more checks, every 5 minutes with the others:

- db.collection-scan: the "Slow query" lines MongoDB keeps (getLog
  'global'), newer than the last probe, where a query read a whole
  collection of at least 10,000 documents. Grouped by collection and the
  field names filtered on - never values - with count, documents read and
  time. Small tables read whole by design (settings, roles) and internal
  namespaces are left out. Needs the getLog privilege; without it, and on
  FerretDB, the check finds nothing and is skipped.
- db.scan-rate: serverStatus.metrics.queryExecutor.scannedObjects between
  two probes above 50,000 documents per second. A database restart, which
  resets the counter, is not counted.

Both are rows in Admin Panel / Problems / Database with what to do;
docs/Databases/MongoDB/Storage-Requirements.md lists them.

tests/databaseHealthScans.test.cjs drives the log parsing and the rate,
including that a filter's values never reach the row. From the reporter's
patch.

Thanks to Raymond-Voogt and xet7 !

Fixes #6826.
2026-10-27 21:19:51 +02:00
Lauri Ojansivu faaa83ed09 Explain and remediate the MongoDB 8.2 crash loop that follows a full disk.
A reported test environment (mongo:8.2.2 in Kubernetes) filled its data
volume: the checkpoint's fdatasync returned ENOSPC, WiredTiger panicked and
mongod aborted - and then it kept failing on every start, with the disk long
since freed. MongoDB 8.2 keeps a throwaway WiredTiger instance under
<dbPath>/_tmp/spilldb for queries that spill to disk and empties it itself on
each start; after the abort that emptying failed ("Failed to clear dbpath of
the internal WiredTiger instance: Directory not empty"), mongod opened the
half-emptied directory, found no version file, reported "Failed to open the
spill WiredTiger instance ... database corruption detected" and fasserted.
Nothing retries, so the pod restarts forever. The data itself is intact;
deleting that one directory is the whole fix.

- snap-src/bin/mongodb-control deletes _tmp/spilldb before every mongod
  start (no mongod is running at that point, and mongod recreates it), and
  its start-failure handler recognises the log line and names the directory.
  The snap ships MongoDB 7 today, so this is a no-op until it does not.
- Admin Panel / Problems: the db.restart row now says what a "No space left
  on device" abort means for a full disk as well as for a network
  filesystem, and both it and db.disk-space name the exact spill directory
  to delete when MongoDB 8.2 will not start afterwards. The probe looks the
  data directory up once and passes it to both rows.
- docs/Databases/MongoDB/Storage-Requirements.md gets the log signature of
  both stages, why the second one never ends, the one command, what must
  not be touched, and that Docker/Kubernetes users run it themselves since
  the database container is MongoDB's own image.
- tests/databaseHealth.test.cjs pins the spill path, both rows' advice, the
  probe wiring, the snap's pre-start deletion (before the first start, after
  the running-instance check, and the only recursive delete apart from the
  existing FerretDB reset) and the documentation.

Thanks to xet7 !
2026-09-11 21:31:10 +03:00
Lauri Ojansivu 03ffb56a5e Index card_comment_reactions, and document why MongoDB's data directory must be local.
From a reported MongoDB crash series (.tools/crash: WeKan and MongoDB in one
Kubernetes pod, the database volume on an SMB/DFS share):

- The crash itself is WiredTiger's checkpoint fsync() returning ENOSPC
  ("No space left on device" with 519 MB used and 10 GiB free) on the
  network share, followed by a fatal assertion and abort - every checkpoint,
  so a restart loop. That is the storage, not WeKan: MongoDB requires a
  local filesystem with real fsync semantics under its data directory.
  docs/Databases/MongoDB/Storage-Requirements.md now says so, shows what
  the log looks like when it is not, and what to do (local block volume;
  attachments may still live on a share; MONGO_URL over TCP is fine).
- The WeKan-side finding in the same logs: card_comment_reactions had no
  index at all, and every board open queried it by `cardId: { $in: [...] }`
  and by `boardId` as a full collection scan - 3,397 COLLSCANs of that one
  collection in the last crash log, up to 1.6 s each, the bulk of its
  "Slow query" lines. server/models/cardCommentReactions.js now ensures
  indexes on cardId, boardId and cardCommentId at startup, like every other
  per-card collection.

tests/cardCommentReactionsIndexes.test.cjs pins both.

Thanks to xet7 !
2026-09-11 11:23:53 +03:00