From c9e3274dd8f2ab3c6c9a6a5922c8ec5ae55dc4e9 Mon Sep 17 00:00:00 2001 From: Felipe Gutierrez Date: Thu, 19 Nov 2026 14:39:14 -0500 Subject: [PATCH 1/2] ci: run Ideas Board multi-region IT against docker-compose 3-region cluster Adds a 3-node one-per-region (us-east1/us-west1/us-central1) docker-compose cluster and a separate examples-it-multiregion workflow that brings it up, makes defaultdb multi-region, and runs RegionalIdeaIT with CRDB_MULTIREGION=true and CRDB_URL pointed at node1. examples-it.yml (single-node Testcontainers) is untouched. --- .github/workflows/examples-it-multiregion.yml | 67 ++++++++++++ examples/ideas-board/multiregion-compose.yml | 101 ++++++++++++++++++ 2 files changed, 168 insertions(+) create mode 100644 .github/workflows/examples-it-multiregion.yml create mode 100644 examples/ideas-board/multiregion-compose.yml diff --git a/.github/workflows/examples-it-multiregion.yml b/.github/workflows/examples-it-multiregion.yml new file mode 100644 index 0000000..1b217c7 --- /dev/null +++ b/.github/workflows/examples-it-multiregion.yml @@ -0,0 +1,67 @@ +name: examples-it-multiregion + +# Runs the Ideas Board multi-region integration test against a real 3-region +# CockroachDB cluster brought up with docker-compose (one node each in us-east1, +# us-west1, us-central1). This is the only way RegionalIdeaIT actually executes: +# it is @EnabledIfEnvironmentVariable(CRDB_MULTIREGION=true) and reads an external +# cluster from CRDB_URL whose database already has us-east1 and us-west1 added. +# +# The example is a standalone Gradle build (not in the root settings.gradle) that +# depends on the PUBLISHED 0.1.2 library from the Pages Maven feed, so it is run +# with the root Gradle wrapper via -p and resolves the library over the network. +# +# Kept as a separate workflow from examples-it.yml so the single-node Testcontainers +# job is untouched. +on: + pull_request: + paths: + - 'examples/ideas-board/**' + - '.github/workflows/examples-it-multiregion.yml' + push: + branches: [main] + paths: + - 'examples/ideas-board/**' + - '.github/workflows/examples-it-multiregion.yml' + workflow_dispatch: + +jobs: + ideas-board-multiregion-it: + name: Ideas Board multi-region IT (docker-compose cluster) + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 25 (Temurin) + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '25' + cache: gradle + + - name: Start 3-region CockroachDB cluster + working-directory: examples/ideas-board + run: docker compose -f multiregion-compose.yml up -d crdb-us-east1 crdb-us-west1 crdb-us-central1 + + - name: Initialize cluster and configure regions + working-directory: examples/ideas-board + # Hard cap so a cluster that never reaches quorum fails the step (and runs + # the diagnostics below) instead of blocking the job. + run: timeout 420 docker compose -f multiregion-compose.yml run --rm crdb-init + + - name: Run multi-region integration test + env: + CRDB_MULTIREGION: "true" + CRDB_URL: "postgres://root@localhost:26257/defaultdb?sslmode=disable" + run: ./gradlew -p examples/ideas-board test --tests '*RegionalIdeaIT*' --no-daemon --stacktrace + + - name: Cluster diagnostics on failure + if: failure() + working-directory: examples/ideas-board + run: | + docker compose -f multiregion-compose.yml ps + docker compose -f multiregion-compose.yml logs --tail=300 + + - name: Tear down cluster + if: always() + working-directory: examples/ideas-board + run: docker compose -f multiregion-compose.yml down -v diff --git a/examples/ideas-board/multiregion-compose.yml b/examples/ideas-board/multiregion-compose.yml new file mode 100644 index 0000000..42ee21f --- /dev/null +++ b/examples/ideas-board/multiregion-compose.yml @@ -0,0 +1,101 @@ +# 3-node insecure CockroachDB cluster for the Ideas Board multi-region IT. +# +# Each node declares a distinct --locality=region, so the cluster exposes three +# regions (us-east1, us-west1, us-central1). The one-shot `crdb-init` service runs +# `cockroach init` and then makes `defaultdb` multi-region, which is what +# RegionalIdeaIT expects (it is @EnabledIfEnvironmentVariable CRDB_MULTIREGION=true +# and assumes us-east1 and us-west1 are already ADDed to the database). us-central1 +# is added too (superset) to keep this compose a near-verbatim copy of the proven +# go-library one; the Java test only asserts on us-east1 / us-west1. +# +# Only node1's SQL port is published to the host: +# CRDB_URL=postgres://root@localhost:26257/defaultdb?sslmode=disable +# +# Local use: +# docker compose -f multiregion-compose.yml up -d crdb-us-east1 crdb-us-west1 crdb-us-central1 +# docker compose -f multiregion-compose.yml run --rm crdb-init +# CRDB_MULTIREGION=true CRDB_URL=postgres://root@localhost:26257/defaultdb?sslmode=disable \ +# ../../gradlew -p . test --tests '*RegionalIdeaIT*' +# +# Default on-disk stores (ephemeral in the container, wiped by `down -v`) + capped +# caches keep three nodes light enough for a CI runner. (In-memory stores need +# >640 MiB each on v25.1, so on-disk is both simpler and lighter here.) +# Every SQL call sets a statement_timeout and every loop is iteration-bounded, so a +# cluster that never reaches quorum FAILS the init (with node status dumped) instead +# of hanging; the workflow also wraps this service in `timeout 420` as a backstop. +# ponytail: single node per region (RF=3 across 3 nodes), not 3-per-region zone +# survival — enough to prove region-homed writes; scale up only if survival goals +# are what you're testing. + +name: crdb-multiregion-it + +x-crdb: &crdb + image: cockroachdb/cockroach:latest-v25.1 + restart: "no" + +services: + crdb-us-east1: + <<: *crdb + hostname: crdb-us-east1 + command: start --insecure --cache=256MiB --max-sql-memory=256MiB --advertise-addr=crdb-us-east1 --join=crdb-us-east1,crdb-us-west1,crdb-us-central1 --locality=region=us-east1 + ports: + - "26257:26257" + + crdb-us-west1: + <<: *crdb + hostname: crdb-us-west1 + command: start --insecure --cache=256MiB --max-sql-memory=256MiB --advertise-addr=crdb-us-west1 --join=crdb-us-east1,crdb-us-west1,crdb-us-central1 --locality=region=us-west1 + + crdb-us-central1: + <<: *crdb + hostname: crdb-us-central1 + command: start --insecure --cache=256MiB --max-sql-memory=256MiB --advertise-addr=crdb-us-central1 --join=crdb-us-east1,crdb-us-west1,crdb-us-central1 --locality=region=us-central1 + + # One-shot: initialize the cluster, wait for all three regions to join, then make + # defaultdb multi-region. Every SQL call sets a statement_timeout and every loop is + # iteration-bounded, so this service always terminates: exit 0 on success, exit 1 + # (after dumping node status) if the cluster never becomes a healthy 3-region cluster. + crdb-init: + <<: *crdb + depends_on: + - crdb-us-east1 + - crdb-us-west1 + - crdb-us-central1 + entrypoint: ["/bin/bash", "-c"] + command: + - | + set -u + host=crdb-us-east1 + # 1) initialize the cluster (first reachable node); returns fast if refused. + for i in $$(seq 1 30); do + cockroach init --insecure --host="$$host" 2>/tmp/init.err && { echo "cluster initialized"; break; } + grep -q "already been initialized" /tmp/init.err && { echo "cluster already initialized"; break; } + cat /tmp/init.err; echo "init attempt $$i failed, retrying"; sleep 2 + done + # 2) wait until all three region localities are visible cluster-wide. + for i in $$(seq 1 40); do + count=$$(cockroach sql --insecure --host="$$host" --format=csv \ + -e "SET statement_timeout='15s'; SELECT count(DISTINCT region) FROM [SHOW REGIONS FROM CLUSTER]" 2>/tmp/reg.err | tail -n1) + echo "attempt $$i distinct_regions=$$count" + [ "$$count" = "3" ] && { echo "all 3 regions present"; break; } + cat /tmp/reg.err 2>/dev/null || true + sleep 3 + done + # 3) make defaultdb multi-region (idempotent). statement_timeout stops a + # schema change that cannot make progress from hanging the loop. + for i in $$(seq 1 20); do + if cockroach sql --insecure --host="$$host" -e " + SET statement_timeout='30s'; + ALTER DATABASE defaultdb SET PRIMARY REGION 'us-east1'; + ALTER DATABASE defaultdb ADD REGION IF NOT EXISTS 'us-west1'; + ALTER DATABASE defaultdb ADD REGION IF NOT EXISTS 'us-central1'; + "; then + echo "defaultdb is multi-region:" + cockroach sql --insecure --host="$$host" -e "SHOW REGIONS FROM DATABASE defaultdb" + exit 0 + fi + echo "region config attempt $$i failed, retrying"; sleep 3 + done + echo "FAILED to configure multi-region defaultdb; node status:" + cockroach node status --insecure --host="$$host" || true + exit 1 From 566086206cf033eba98cdde40c1124f502414ce3 Mon Sep 17 00:00:00 2001 From: Felipe Gutierrez Date: Thu, 19 Nov 2026 14:43:09 -0500 Subject: [PATCH 2/2] ci: use JDBC URL for RegionalIdeaIT (PGSimpleDataSource.setUrl requires jdbc:postgresql) The first run failed with IllegalArgumentException at RegionalIdeaIT.java:32 (ds.setUrl): the test feeds CRDB_URL straight to PGSimpleDataSource, which rejects the libpq-style postgres:// URL copied from the go example. Switch to jdbc:postgresql://localhost:26257/defaultdb?sslmode=disable&user=root (user=root needed since the JDBC driver otherwise uses the runner's OS user). --- .github/workflows/examples-it-multiregion.yml | 8 +++++++- examples/ideas-board/multiregion-compose.yml | 8 +++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/examples-it-multiregion.yml b/.github/workflows/examples-it-multiregion.yml index 1b217c7..acf4e5a 100644 --- a/.github/workflows/examples-it-multiregion.yml +++ b/.github/workflows/examples-it-multiregion.yml @@ -51,7 +51,13 @@ jobs: - name: Run multi-region integration test env: CRDB_MULTIREGION: "true" - CRDB_URL: "postgres://root@localhost:26257/defaultdb?sslmode=disable" + # RegionalIdeaIT feeds CRDB_URL straight to PGSimpleDataSource.setUrl(), + # which requires a JDBC URL (jdbc:postgresql://...) — the libpq-style + # postgres:// form the go example uses makes setUrl throw + # IllegalArgumentException. user=root is required because the JDBC driver + # otherwise defaults the user to the runner's OS account, which the + # insecure cluster does not have. + CRDB_URL: "jdbc:postgresql://localhost:26257/defaultdb?sslmode=disable&user=root" run: ./gradlew -p examples/ideas-board test --tests '*RegionalIdeaIT*' --no-daemon --stacktrace - name: Cluster diagnostics on failure diff --git a/examples/ideas-board/multiregion-compose.yml b/examples/ideas-board/multiregion-compose.yml index 42ee21f..4906d0a 100644 --- a/examples/ideas-board/multiregion-compose.yml +++ b/examples/ideas-board/multiregion-compose.yml @@ -8,13 +8,15 @@ # is added too (superset) to keep this compose a near-verbatim copy of the proven # go-library one; the Java test only asserts on us-east1 / us-west1. # -# Only node1's SQL port is published to the host: -# CRDB_URL=postgres://root@localhost:26257/defaultdb?sslmode=disable +# Only node1's SQL port is published to the host. RegionalIdeaIT reads a JDBC URL +# (it calls PGSimpleDataSource.setUrl), so CRDB_URL must be the jdbc:postgresql form +# with user=root (the insecure cluster has no account matching the host OS user): +# CRDB_URL=jdbc:postgresql://localhost:26257/defaultdb?sslmode=disable&user=root # # Local use: # docker compose -f multiregion-compose.yml up -d crdb-us-east1 crdb-us-west1 crdb-us-central1 # docker compose -f multiregion-compose.yml run --rm crdb-init -# CRDB_MULTIREGION=true CRDB_URL=postgres://root@localhost:26257/defaultdb?sslmode=disable \ +# CRDB_MULTIREGION=true CRDB_URL='jdbc:postgresql://localhost:26257/defaultdb?sslmode=disable&user=root' \ # ../../gradlew -p . test --tests '*RegionalIdeaIT*' # # Default on-disk stores (ephemeral in the container, wiped by `down -v`) + capped