A lifecycle request now covers exactly one instance. A swap of a
member's active FedWiki site records two requests, one for each site,
and groups them in one act whose cause is instances_swapped. The
member's request makes the chosen site active, and the console's request
makes the other site read-only. The console's request names no person.
Only core.record_lifecycle_act writes the link between a request and its
act, and it links only requests its own transaction inserted.
core_writer's table-wide INSERT and UPDATE on core.lifecycle_requests
become grants on the columns the request writers name. The act only ties
the requests together: the console undoes the others itself when one
fails, and a connector applies each request on its own. The two
swap_park_site_id and swap_activate_site_id parameters are gone. The
notices, dismissal and boot settle now find a swap through its act. A
failed swap shows one notice, and dismissing it dismisses both requests.
When a swap is declined because its parked site was deleted, the notice
names the parked site. Settle finishes an act's requests together.
A swap and a return (Keep active on a site a downgrade or an earlier swap
made read-only) both change which site is active. Each takes the
workspace lock at intake. Each is refused with "A change to your active
site is already in progress" while another change of that workspace's
active site is open, whether or not the wait between changes is
configured. A repeat click, or a stale tab posting a stored address, is
answered from the stored request before anything is recorded.
The wait between changes of the active site now starts when a change
succeeds, in the worker step that records the success. Intake no longer
starts it. A change that is declined, fails or never starts leaves the
wait as it was. Before this, such a change locked the member out for the
whole window.
The farm sync keeps a site's downgrade mark only on a row it writes
read-only. Restore of an archived site never counts as a change of the
active site, and the sites card shows Restore on every archived row. A
Restore posted for a row that is no longer archived answers "This site
changed since the list loaded."
Deploy notes. Every step runs against the console database.
1. Before stopping the old release, count the open swaps and the open
returns, read-only (console_reader can run it):
SELECT 'swap' AS kind, count(*) FROM core.lifecycle_requests lr
WHERE lr.status = 'accepted'
AND (lr.workflow_id LIKE 'swap-fedwiki-site-%'
OR lr.parameters ?| ARRAY['swap_park_site_id','swap_activate_site_id'])
UNION ALL
SELECT 'return', count(*) FROM core.lifecycle_requests lr
JOIN fedwiki.sites s ON s.site_id = lr.instance_id
WHERE lr.status = 'accepted' AND lr.operation = 'set_status'
AND lr.parameters->>'status' = 'active'
AND s.force_reduced_at IS NOT NULL
AND lr.workflow_id NOT LIKE 'swap-fedwiki-site-%';
Deploy only when both counts are 0. Then count the marked rows that
are not read-only:
SELECT count(*) FROM fedwiki.sites
WHERE force_reduced_at IS NOT NULL AND status <> 'readonly';
2. Stop every process of the old release. Migration 00040's change of
lock keys needs this step too, if the deployment has not run it yet.
3. Run both counts again, because the old release may have written more
rows before it stopped. In the stop window, as the runtime user, clear
the marks the second count finds:
UPDATE fedwiki.sites SET force_reduced_at = NULL
WHERE force_reduced_at IS NOT NULL AND status <> 'readonly';
4. List the stored parked-site requests that ended declined or failed and
are not dismissed. Then acknowledge them as the runtime user:
SELECT request_id, workspace_id, instance_id, status, reason_code, finished_at
FROM core.lifecycle_requests
WHERE parameters ? 'swap_activate_site_id'
AND status IN ('declined','failed') AND acknowledged_at IS NULL
ORDER BY finished_at;
UPDATE core.lifecycle_requests SET acknowledged_at = NOW()
WHERE parameters ? 'swap_activate_site_id'
AND status IN ('declined','failed') AND acknowledged_at IS NULL;
5. Migrate to 00041 and start the new release.
6. Once every change counted in step 3 has finished, run step 4's
listing again and acknowledge what it finds. A stored swap whose farm
cannot answer keeps retrying, so its parked request can end long after
the start. If a swap counted in step 3 fails, its workspace keeps the
wait the old intake started. Delete that workspace's
fedwiki.site_swap_policy row by hand to let the member change the
active site at once. The delete also erases any earlier wait.
7. Run scripts/db-reader-role.sql again. Until it runs, console_reader
cannot read the three new columns.
Rollback is the previous image on the 00041 schema, once no lifecycle
request is open. Under it, a failed or declined swap recorded by the new
release shows two notices that dismissal does not pair. A new swap
declined because its parked site was deleted reads "<chosen> was
deleted.", which names a site that still exists. After a rollback,
acknowledge two kinds of row by hand, in both cases while
acknowledged_at is NULL:
- rows with act_role = 'consequent' that ended declined or failed;
- rows with act_role = 'asked' and reason_code = 'site_missing' whose own
fedwiki.sites row still exists.
Rolling forward again repeats every step. The migration's Down refuses
once a lifecycle act exists.
Closes#184. Closes#328. Closes#329.