Skip to content
Source
Sign inSign up

Add a replica server

Site administration

Add a replica server

The replica server of a region is new, or you rebuilt it after it lost its disk. The primary sends a repository to a replica only when the refs of that repository move, so the new server has no repositories yet. Copy them to it before the Worker sends it any read.

4 min read

The regions are us, eu and asia, and each has one server. gitd, install.sh and the Worker know only these three regions, so a server in a fourth region needs a change of the code first.

You need:

  • The setup of Set up the git servers: the shared secret in ~/gitd-secret, your SSH key, and Go.

  • GITD_IP_US, GITD_IP_EU and GITD_IP_ASIA set to the addresses of the servers, as in step 2 of the setup. Use the address of the new server for its region.

  • psql, and neonctl signed in to the Neon organization of the forge. The rows of the forge are in Postgres on Neon (README.md, "Database"). Step 4 reads the list of repositories there. Put the URL of its database in PG_URL. The URL holds a password, so keep it in your shell only:

    PG_URL="$(neonctl connection-string main --project-id tiny-unit-38538247 --role-name app --database-name source)"

Write down the time when you start, to know how long the new replica takes to serve reads.

The steps below use eu as the region of the new server. Use your region in its place.

1. Create the server

Create it as in step 2 of the setup: Debian 13, your SSH key, apps/gitd/deploy/cloud-init.yaml as its user data, and a firewall that lets in only SSH.

2. Install gitd on the new server, with no tunnel

sh apps/gitd/deploy/install.sh install eu "$GITD_IP_EU" ~/gitd-secret

With no tunnel token, the Worker cannot reach the new server yet. So no read goes to it while it has no repositories.

3. Install the other servers again

Each server keeps the address, the host key and the SSH key of its two peers. Install the other servers again, so that they let the new server in and send to it. Install the primary last. sh apps/gitd/deploy/install.sh primary prints its region.

sh apps/gitd/deploy/install.sh install asia "$GITD_IP_ASIA" ~/gitd-secret
sh apps/gitd/deploy/install.sh install us "$GITD_IP_US" ~/gitd-secret
  • gitd restarts on each server. A restart waits up to 60 seconds for the open requests to end.
  • With no tunnel token, the tunnel of a server does not change.

4. Copy each repository to the new server

  1. List the repositories on the git servers:

    psql "$PG_URL" -c "SELECT id FROM repos WHERE git_primary IS NOT NULL"
  2. Copy each one. The primary sends it to every replica, and the command waits until each replica has it:

    sh apps/gitd/deploy/install.sh replicate <repo id>

    The command prints one line for each region, for example eu: 200 7. 200 is the answer of the replica, and 7 is the version of the repository that it has.

5. Connect the tunnel

  1. If the region has no tunnel and no VPC service yet, create them as in step 3 of the setup. If the region keeps its tunnel, save its token in ~/gitd-eu.tunnel as in that step.

  2. Install gitd again, with the tunnel token:

    sh apps/gitd/deploy/install.sh install eu "$GITD_IP_EU" ~/gitd-secret ~/gitd-eu.tunnel
    rm ~/gitd-eu.tunnel
  3. If the web Worker has no GITD_EU binding yet, add it as in step 4 of the setup, and merge the change to main.

6. Make sure that the new server serves reads

  1. Ask gitd on the new server how it is. It answers with its region, its role, and "behind":false:

    ssh -i ~/.ssh/source_git_ed25519 root@"$GITD_IP_EU" curl -fsS 127.0.0.1:8420/healthz
  2. Open the code page of a repository on the git servers from a browser in Europe, or clone it from a computer there.

  3. On the analytics server, count the requests that the new server answered in the last 10 minutes:

    clickhouse-client --password "$(cat /root/.clickhouse-admin)" --query "SELECT JSONExtractString(properties, 'kind') AS kind, count() FROM analytics.events WHERE event = 'gitd.request' AND JSONExtractString(properties, 'region') = 'eu' AND timestamp >= now() - INTERVAL 10 MINUTE GROUP BY kind"

    Rows of the kinds read-* (page reads) and git-upload-pack (clones and fetches) are reads that the Worker sent. Rows of git-info-refs can also come from the checks of install.sh in step 4.

Done

The new server serves the reads of its region, and it gets each new push from the primary. Write down the time of the first read, for the comparison.