When: During a pre-defined DBA maintenance windows
Prerequisites: https://wikitech.wikimedia.org/wiki/MariaDB/Primary_switchover
Affected wikis:: TO-DO
Checklist:
NEW primary: db2191
OLD primary: db2215
- Check configuration differences between new and old primary:
sudo pt-config-diff --defaults-file /root/.my.cnf h=db2215.codfw.wmnet h=db2191.codfw.wmnet
Failover prep:
- Silence alerts on all hosts:
sudo cookbook sre.hosts.downtime --hours 1 -r "Primary switchover x1 T409168" 'A:db-section-x1'
- Set NEW primary with weight 0
sudo dbctl instance db2191 set-weight 0 sudo dbctl config commit -m "Set db2191 with weight 0 T409168"
- Depool NEW from any specific group (API, vslow, dump) if present.
sudo dbctl instance db2191 edit # If some changes were made: sudo dbctl config commit -m "Remove db2191 from API/vslow/dump T409168"
- Topology changes, move all replicas under NEW primary
sudo db-switchover --timeout=25 --only-slave-move db2215 db2191
- Disable puppet on both nodes
sudo cumin 'db2215* or db2191*' 'disable-puppet "primary switchover T409168"'
- Merge gerrit puppet change to promote NEW primary: https://gerrit.wikimedia.org/r/c/operations/puppet/+/1201593
Failover:
- Log the failover:
!log Starting x1 codfw failover from db2215 to db2191 - T409168
- Set section read-only:
sudo dbctl --scope eqiad section x1 ro "Maintenance until 06:15 UTC - T409168" sudo dbctl --scope codfw section x1 ro "Maintenance until 06:15 UTC - T409168" sudo dbctl config commit -m "Set x1 codfw as read-only for maintenance - T409168"
- Check x1 is indeed read-only
- Switch primaries:
sudo db-switchover --skip-slave-move db2215 db2191 echo "===== db2215 (OLD)"; sudo db-mysql db2215 -e 'show slave status\G' echo "===== db2191 (NEW)"; sudo db-mysql db2191 -e 'show slave status\G'
- Promote NEW primary in dbctl, and remove read-only
sudo dbctl --scope codfw section x1 set-master db2191 sudo dbctl --scope eqiad section x1 rw sudo dbctl --scope codfw section x1 rw sudo dbctl config commit -m "Promote db2191 to x1 primary and set section read-write T409168"
- Clean up heartbeat table(s).
sudo db-mysql db2191 heartbeat -e "delete from heartbeat where file like 'db2215%';"
- Restart puppet on both hosts:
sudo cumin 'db2215* or db2191*' 'run-puppet-agent -e "primary switchover T409168"'
Clean up tasks:
- change events for query killer:
curl -sS 'https://gerrit.wikimedia.org/r/plugins/gitiles/operations/software/+/refs/heads/master/dbtools/events_coredb_master.sql?format=TEXT' | base64 -d | sudo db-mysql db2191 curl -sS 'https://gerrit.wikimedia.org/r/plugins/gitiles/operations/software/+/refs/heads/master/dbtools/events_coredb_slave.sql?format=TEXT' | base64 -d | sudo db-mysql db2215
- Merge DNS change: https://gerrit.wikimedia.org/r/1201594
sudo authdns-update
- Update candidate primary dbctl and orchestrator notes
sudo dbctl instance db2215 set-candidate-master --section x1 true sudo dbctl instance db2191 set-candidate-master --section x1 false sudo cumin 'dborch*' 'orchestrator-client -c untag -i db2191 --tag name=candidate' sudo cumin 'dborch*' 'orchestrator-client -c tag -i db2215 --tag name=candidate'
- Check zarcillo was updated
- db-switchover should do this. If it fails, do it manually: https://phabricator.wikimedia.org/P13956
sudo db-mysql db1215 zarcillo -e "select * from masters where section = 'x1';"
- (If needed): Depool db2215 for maintenance.
sudo dbctl instance db2215 depool sudo dbctl config commit -m "Depool db2215 T409168"
- Change db2215 weight to mimic the previous weight db2191 (main/api/vslow/dumps):
sudo dbctl instance db2215 edit
- Update/resolve this ticket.