mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
`snap set wekan database=mongodb|ferretdb` is gone, and so is `snap run wekan.database`. WeKan runs on FerretDB on every platform; MongoDB is in the amd64/arm64 snaps to be READ while a migration is owed. A setting could say something the data did not support, and every way it could was a report: set to mongodb it kept a site on the database the snap migrates away from, for good, because nothing ever set it back - including instances a failed migration or a wrong staleness guess had put there; set to ferretdb with no FerretDB present it would have served an empty site, so the guard against that had to exist anyway; and each script carried its own copy of "which database is this, then". snap-src/bin/database-role replaces it. One helper, asked by wekan-control, mongodb-control, ferretdb-control, migration-pending, attachment-repair and the configure hook, answering from the data: a FerretDB with something in it and a migration that has finished means ferretdb, MongoDB data with the migration still owed means mongodb. An interrupted migration is told from a finished one by the importer's checkpoint, so a partial FerretDB resumes and a finished one whose marker went missing is not migrated over again (#6585). An empty FerretDB beside a MongoDB full of boards is never served. The explanatory page is no longer a dead end: when this snap cannot read the MongoDB files but a FerretDB copy is there, the copy is served - older beats unreadable - and the page says the snap keeps trying rather than giving a command to type. A snap that still has the old setting is told once that it is ignored, and it is unset. docs/Platforms/FOSS/Container/Snap/Migration-to-FerretDB.md is the design in one page: all text data to SQLite, CollectionFS and Meteor-Files attachments to the filesystem, the card History with it, which MongoDB versions can be read, when it runs, what happens when it fails, and how two copies are reconciled. The Admin Panel, Snap and CPU-platform docs point there instead of documenting a setting that no longer exists. Nine guards updated; each says in it which decision changed and why. Thanks to xet7 !
132 lines
6.1 KiB
JavaScript
132 lines
6.1 KiB
JavaScript
'use strict';
|
|
|
|
// #6525: upgrading a Snap from 6.09 to 10.37 migrated MongoDB -> FerretDB
|
|
// successfully and then served 503 until the admin ran `snap restart wekan` by
|
|
// hand. WeKan sat in its startup loop printing "MongoDB not ready yet, retrying
|
|
// in 5 seconds..." against a MongoDB that the migration had just shut down for
|
|
// good.
|
|
//
|
|
// Cause: mongodb-control ends with `exec bash $SNAP/bin/migration-control`, so
|
|
// migration-control IS the wekan.mongodb service process. When the switch ran
|
|
// `snapctl stop --disable <snap>.mongodb`, systemd stopped the service THIS
|
|
// script runs in — SIGTERM, script dead at that line — and the
|
|
// `snapctl restart <snap>.wekan` that came AFTER it never ran. The reporter's log
|
|
// shows it exactly: "Migration succeeded. Switching to FerretDB" at 13:15:12,
|
|
// "Terminated" one second later, then minutes of WeKan waiting for MongoDB.
|
|
//
|
|
// Fix: hand WeKan over to FerretDB BEFORE stopping MongoDB — the one command that
|
|
// can terminate this process goes last — and have wekan-control notice a
|
|
// mid-wait switch itself, so the restart is not the only way out of that loop.
|
|
//
|
|
// Run: node tests/snapMigrationSwitchOrder.test.cjs
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { spawnSync } = require('child_process');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) {
|
|
fn();
|
|
passed += 1;
|
|
console.log(' ok -', name);
|
|
}
|
|
|
|
const root = path.join(__dirname, '..');
|
|
const read = p => fs.readFileSync(path.join(root, p), 'utf8');
|
|
|
|
const migration = read('snap-src/bin/migration-control');
|
|
const mongodbControl = read('snap-src/bin/mongodb-control');
|
|
const wekanControl = read('snap-src/bin/wekan-control');
|
|
|
|
// The switch block inside finish_success.
|
|
const finish = migration.slice(
|
|
migration.indexOf('finish_success() {'),
|
|
migration.indexOf('discard_partial_ferretdb()'));
|
|
|
|
console.log('snapMigrationSwitchOrder:');
|
|
|
|
test('migration-control really is the mongodb service (why order matters)', () => {
|
|
assert.ok(/exec bash "\$SNAP\/bin\/migration-control"/.test(mongodbControl),
|
|
'mongodb-control execs migration-control, so stopping wekan.mongodb kills it');
|
|
});
|
|
|
|
test('WeKan is handed to FerretDB BEFORE MongoDB is stopped', () => {
|
|
const startFerret = finish.indexOf('start --enable "${svc}.ferretdb"');
|
|
const restartWekan = finish.indexOf('restart "${svc}.wekan"');
|
|
const stopMongo = finish.indexOf('stop --disable "${svc}.mongodb"');
|
|
assert.ok(startFerret >= 0 && restartWekan >= 0 && stopMongo >= 0,
|
|
'all three service commands must be present');
|
|
assert.ok(startFerret < restartWekan,
|
|
'FerretDB must be running before WeKan is restarted onto it');
|
|
assert.ok(restartWekan < stopMongo,
|
|
'restarting WeKan must come BEFORE stopping MongoDB: the stop terminates this ' +
|
|
'very process, so anything after it never runs (that is #6525)');
|
|
});
|
|
|
|
test('stopping MongoDB is the LAST service command in the switch', () => {
|
|
const stopMongo = finish.indexOf('stop --disable "${svc}.mongodb"');
|
|
const after = finish.slice(stopMongo + 1);
|
|
assert.ok(!/snapctl (start|restart|stop) /.test(after),
|
|
'no snapctl service command may follow the stop that kills this process');
|
|
});
|
|
|
|
test('the traps are disarmed before the self-terminating stop', () => {
|
|
const disarm = finish.lastIndexOf('trap - EXIT INT TERM');
|
|
const stopMongo = finish.indexOf('stop --disable "${svc}.mongodb"');
|
|
assert.ok(disarm >= 0, 'finish_success must disarm the traps');
|
|
assert.ok(disarm < stopMongo,
|
|
'otherwise being stopped logs "Interrupted (snap refresh, stop or reboot)" ' +
|
|
'after a migration that SUCCEEDED, and runs cleanup for nothing');
|
|
});
|
|
|
|
test('the switch is still verified and recorded before any of it', () => {
|
|
// Guard the safety property the reorder must not have disturbed: nothing is
|
|
// switched until a non-empty FerretDB SQLite is confirmed.
|
|
const verify = finish.indexOf('ferretdb-has-data');
|
|
// `snapctl set database=ferretdb` is gone with the setting; the MARKER is what
|
|
// records the switch now, and bin/database-role reads it. Same order, same
|
|
// property: nothing moves until a non-empty FerretDB SQLite is confirmed.
|
|
const mark = finish.indexOf('touch "$MARKER"');
|
|
const startFerret = finish.indexOf('start --enable "${svc}.ferretdb"');
|
|
assert.ok(verify >= 0 && verify < mark && mark < startFerret,
|
|
'verify the SQLite, then record the migration as done, then move the services');
|
|
});
|
|
|
|
test('wekan-control leaves the wait loop when the database is switched under it', () => {
|
|
const loop = wekanControl.slice(
|
|
wekanControl.indexOf('Waiting for MongoDB replica set primary...'),
|
|
wekanControl.indexOf('MongoDB replica set primary is ready.'));
|
|
assert.ok(/database-role/.test(loop),
|
|
'the loop must ask again which database should be running - bin/database-role, ' +
|
|
'from the data - and not only use the value it sampled at startup');
|
|
assert.ok(/exec "\$0"/.test(loop),
|
|
'on a switch it must re-exec onto FerretDB instead of waiting for a MongoDB ' +
|
|
'that is never coming back');
|
|
const check = loop.indexOf('snapctl get database');
|
|
const retry = loop.indexOf('MongoDB not ready yet, retrying');
|
|
assert.ok(check < retry,
|
|
'check for the switch before sleeping another round');
|
|
});
|
|
|
|
test('both scripts are still valid shell', () => {
|
|
for (const p of ['snap-src/bin/migration-control', 'snap-src/bin/wekan-control']) {
|
|
const r = spawnSync('bash', ['-n', path.join(root, p)], { encoding: 'utf8' });
|
|
assert.strictEqual(r.status, 0, `bash -n ${p} failed: ${r.stderr}`);
|
|
}
|
|
});
|
|
|
|
test('the other switch site already had the right order (negative)', () => {
|
|
// mongodb-control has the same three commands for the "a completed migration
|
|
// exists" case. It was already correct; keep it that way.
|
|
const block = mongodbControl.slice(
|
|
mongodbControl.indexOf('A completed FerretDB migration exists'));
|
|
const restartWekan = block.indexOf('restart "${svc}.wekan"');
|
|
const stopMongo = block.indexOf('stop --disable "${svc}.mongodb"');
|
|
assert.ok(restartWekan >= 0 && stopMongo >= 0);
|
|
assert.ok(restartWekan < stopMongo,
|
|
'mongodb-control must also restart WeKan before stopping MongoDB');
|
|
});
|
|
|
|
console.log(`\nsnapMigrationSwitchOrder: ${passed} tests passed`);
|