Files
wekan/snap-src/bin/migration-pending
T
Lauri Ojansivu bb76e7bf10 Snap: remove the database setting. There is one answer, and it is FerretDB.
`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 !
2026-08-12 22:25:18 +03:00

71 lines
3.6 KiB
Bash
Executable File

#!/bin/bash
# Exit 0 if a one-time MongoDB -> FerretDB v1 migration is pending for this snap,
# else exit 1. "Pending" = existing MongoDB (WiredTiger) data is present in
# $SNAP_COMMON, the migration has not completed yet, and the tools to do it
# (ferretdb binary, bundled node, the migrator script) are all available.
MARKER="$SNAP_COMMON/.migration-to-ferretdb-done"
DBPATH="$SNAP_COMMON"
[ -f "$MARKER" ] && exit 1
# #6585: a snap that is ALREADY on FerretDB, with data in it, has nothing pending.
# The MongoDB files in $SNAP_COMMON are what it was migrated FROM - the migration
# never deletes them, on purpose - so "MongoDB data is present" says nothing about
# whether a migration is still owed. Without this, only the marker did, and an
# instance whose marker is gone (a re-migration was forced, or it was migrated by a
# snap old enough not to have written one) is dragged back to those files on every
# start: mongodb-control hands off to migration-control, which probes them with
# every reader it has, and when none can open them writes .mongodb-data-too-old and
# WeKan serves "Wekan cannot open the existing database" - while the boards and
# cards are sitting in FerretDB, readable, and nothing is wrong with them.
#
# "Already on FerretDB" is a question about the DATA, not about a setting - and
# there is no setting any more. bin/database-role answers it the same way for
# every script in the snap: a FerretDB with something in it, and a migration that
# has finished (or no MongoDB data to migrate). An empty files/db is exactly the
# case the migration exists for, and it still runs.
if [ "$(bash "$SNAP/bin/database-role" 2>/dev/null)" = "ferretdb" ]; then
exit 1
fi
# An admin can pause auto-migration while a problem is being looked at:
# `snap set wekan migrate=off`. That is the only way it stops - a FAILED migration
# does not stop it any more, it schedules a retry (see the record below). Retry now
# with `snap run wekan.migrate`.
[ "$(snapctl get migrate 2>/dev/null)" = "off" ] && exit 1
# A previous attempt FAILED. It is retried - every WeKan snap is meant to end up on
# FerretDB - but not on every start, or a migration that cannot succeed yet would
# re-hijack every boot. migration-control writes the record; this decides when the
# next attempt is due:
#
# * a different snap revision than the one that failed -> retry NOW. The next
# release is the most likely thing to have fixed it, and waiting a day after
# installing the fix is a day of not being migrated.
# * otherwise wait, doubling from one hour to a maximum of one day.
#
# `snap run wekan.migrate` deletes this file, so a manual retry is never delayed.
RETRY="$SNAP_COMMON/.migration-retry"
if [ -f "$RETRY" ]; then
r_attempts="$(sed -n 's/^attempts=\([0-9]*\)$/\1/p' "$RETRY" 2>/dev/null)"
r_when="$(sed -n 's/^when=\([0-9]*\)$/\1/p' "$RETRY" 2>/dev/null)"
r_revision="$(sed -n 's/^revision=\(.*\)$/\1/p' "$RETRY" 2>/dev/null)"
[ -n "$r_attempts" ] || r_attempts=1
[ -n "$r_when" ] || r_when=0
if [ -n "${SNAP_REVISION:-}" ] && [ -n "$r_revision" ] && [ "$SNAP_REVISION" != "$r_revision" ]; then
: # a new revision: retry now
else
wait_s=3600
i=1
while [ "$i" -lt "$r_attempts" ] && [ "$wait_s" -lt 86400 ]; do
wait_s=$((wait_s * 2)); i=$((i + 1))
done
[ "$wait_s" -gt 86400 ] && wait_s=86400
now="$(date +%s)"
[ $((now - r_when)) -lt "$wait_s" ] && exit 1
fi
fi
[ -x "$SNAP/ferretdb" ] || exit 1
[ -x "$SNAP/bin/node" ] || exit 1
[ -f "$SNAP/bin/migrate-mongodb-to-ferretdb.mjs" ] || exit 1
if [ -f "$DBPATH/WiredTiger" ] || ls "$DBPATH"/collection-*.wt >/dev/null 2>&1; then
exit 0
fi
exit 1