Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update MongoDB to work for Router #549

Merged
merged 2 commits into from
Dec 16, 2021
Merged

Update MongoDB to work for Router #549

merged 2 commits into from
Dec 16, 2021

Conversation

karlbaker02
Copy link
Contributor

@karlbaker02 karlbaker02 commented Dec 15, 2021

This PR updates MongoDB 2.6 to work for Router, by specifying a replica set config using the name of the MongoDB container defined in docker-compose.yml. It also fixes the replicate-mongodb.sh script to correctly restore back-ups of router / draft-router (using MongoDB 2.6 and not 3.6).

The sleep 60 added when restoring MongoDB 2.6 databases allows the replica set to initialise (see the following screenshot):

Screenshot 2021-12-15 at 15 12 06

This PR also addresses the issues raised in #533.

Karl Baker added 2 commits December 15, 2021 16:47
This commit adds a definition for the replica set config to use for MongoDB 2.6. Previously in this repo we initialised a replica set without specifying any config, which has the effect of creating a config using the container id of said container running MongoDB 2.6. The issue here is that this replica set config is persisted to the `govuk-docker_mongo-2.6` volume, meaning that when the current container is eventually removed and a new container created to run MongoDB 2.6 the replica set won't be properly provisioned as it references the wrong container id.

To get around this problem in govuk-docker, this commit specifies the replica set config to use during initialisation and uses the name of the container to route to, rather than the container id; through this change, the replica set config can remain persisted in the associated volume whilst containers come and go, all whilst enabling these new instances to take part in the replica set. This isn't a problem with MongoDB 2.6 in production as we're not running it in containers.

For clarity, the replica set is used by Router to poll for updates to Routes, using the `optime` property from `rs.status()` to determine if it holds an up-to-date copy of routes; for more context [see this commit](alphagov/router@678ef63) and [RFC](https://github.com/alphagov/govuk-rfcs/blob/main/rfc-135-updating-routes-in-router.md).
This commit updates the `replicate-mongodb.sh` script to work for the `router` and `draft-router` databases. Specifically, Router uses MongoDB 2.6, but the replication script previously made no provision for this and so wouldn't have worked for these databases.

When restoring a back-up of either `router` or `draft-router` using MongoDB 2.6, a `sleep 60` has been added to allow for the replica set to properly initialise, as described by MongoDB when you run `rs.initiate()`; whilst I can't find any documentation related to this on the MongoDB docs, there are references to it elsewhere (see [here](https://medium.com/@ManagedKube/deploy-a-mongodb-cluster-in-steps-9-using-docker-49205e231319) and [here](https://www.ceondo.com/notes/mongodb/)).
@karlbaker02 karlbaker02 merged commit f378e9c into main Dec 16, 2021
@karlbaker02 karlbaker02 deleted the fix-router branch December 16, 2021 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants