Skip to content

Commit 4360c17

Browse files
committed
Update Cassandra DualWrites for using java client
1 parent f3614aa commit 4360c17

File tree

4 files changed

+59
-19
lines changed

4 files changed

+59
-19
lines changed

sources/cassandra/Dockerfile

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
FROM golang:1.24-bullseye AS builder
1+
# --- Go Builder Stage ---
2+
FROM golang:1.24-bullseye AS go-builder
23

34
# Disable cgo to remove gcc dependency
45
ENV CGO_ENABLED=0
56

6-
RUN apt-get update && apt-get install -y git curl
7+
RUN apt-get update && apt-get install -y git
78

89
WORKDIR /app
910

@@ -15,30 +16,44 @@ WORKDIR /app/zdm-proxy/proxy
1516
# Build ZDM Proxy
1617
RUN go build -o zdm-proxy
1718

18-
# --- Cassandra-to-Spanner CQL Proxy ---
19+
# --- Java Builder Stage ---
20+
FROM maven:3.9-eclipse-temurin-17 AS java-builder
21+
1922
WORKDIR /app
2023

21-
RUN git clone "https://github.com/googleapis/go-spanner-cassandra.git"
24+
# Clone the Java Spanner Cassandra repo
25+
# Using specific tag or main branch. For stability, usually better to pin, but instructions enable main.
26+
RUN git clone -b v1.1.0 https://github.com/googleapis/java-spanner-cassandra.git
2227

23-
WORKDIR /app/go-spanner-cassandra
28+
WORKDIR /app/java-spanner-cassandra
2429

25-
# Build CQL Proxy
26-
RUN go build -o cassandra-spanner-proxy
30+
# Build the project to get the shaded jar
31+
RUN mvn clean install -DskipTests
2732

2833
# --- Final Image ---
2934
FROM alpine:3.22
3035

31-
# Install bash, ca-certificates, openssl, and update packages
36+
# Install bash, ca-certificates, openssl, gettext (for envsubst), and Java 17 JRE
3237
RUN apk update && \
3338
apk upgrade && \
34-
apk add --no-cache bash ca-certificates openssl
39+
apk add --no-cache bash ca-certificates openssl gettext openjdk17-jre
3540

3641
EXPOSE 9042 14002
3742

38-
# Copy in the binaries
39-
COPY --from=builder /app/zdm-proxy/proxy/zdm-proxy .
40-
COPY --from=builder /app/go-spanner-cassandra/cassandra-spanner-proxy .
43+
WORKDIR /app
44+
45+
# Copy ZDM Proxy binary
46+
COPY --from=go-builder /app/zdm-proxy/proxy/zdm-proxy .
47+
48+
# Copy Java Spanner Cassandra Proxy JAR and dependencies
49+
# The build produces spanner-cassandra-launcher.jar and a lib/ directory with dependencies.
50+
COPY --from=java-builder /app/java-spanner-cassandra/google-cloud-spanner-cassandra/target/spanner-cassandra-launcher.jar spanner-cassandra-proxy.jar
51+
COPY --from=java-builder /app/java-spanner-cassandra/google-cloud-spanner-cassandra/target/lib ./lib
52+
53+
# Copy configuration template
54+
COPY spanner-cassandra-config.yaml .
4155

56+
# Copy entrypoint
4257
COPY entrypoint.sh /entrypoint.sh
4358
RUN chmod +x /entrypoint.sh
4459

sources/cassandra/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This repository contains components for doing live migrations from Cassandra to
1212
- Handles dual writes to both Cassandra and Spanner
1313
- Ensures data consistency during migration
1414

15-
### 2. Cassandra-Spanner Proxy
15+
### 2. [Spanner Cassandra Java Client](https://github.com/googleapis/java-spanner-cassandra)
1616
- Runs as a sidecar to ZDM proxy
1717
- Translates CQL (Cassandra Query Language) to Spanner API calls
1818
- Enables Cassandra-compatible applications to interact with Spanner
@@ -26,7 +26,7 @@ The migration setup consists of:
2626
- **Origin**: Source Cassandra database
2727
- **Target**: Destination Cloud Spanner database
2828
- **ZDM Proxy**: Manages dual writes and read routing
29-
- **Cassandra-Spanner Proxy**: Translates CQL to Spanner API calls
29+
- **Spanner Cassandra Java Client**: Translates CQL to Spanner API calls
3030
- **Client Application**: Your application that interacts with the databases
3131

3232
## Migration Process
@@ -181,7 +181,7 @@ When planning your production deployment, consider these guidelines:
181181

182182
1. **Prepare Terraform Configuration**
183183

184-
Update your `terraform.tfvars` file with your variables. Take a look at available variables in `variables.tf`. If you need more customization for zdm proxy or cassandra to spanner proxy, update the `variables.tf` and `main.tf` to include the other params.
184+
Update your `terraform.tfvars` file with your variables. Take a look at available variables in `variables.tf`. If you need more customization for zdm proxy or java spanner proxy, update the `variables.tf` and `main.tf` to include the other params.
185185

186186
2. **Initialize and Apply Terraform**
187187

sources/cassandra/entrypoint.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
#!/bin/bash
22

3-
# Start processes and store their PIDs
4-
/cassandra-spanner-proxy --db="projects/$SPANNER_PROJECT/instances/$SPANNER_INSTANCE/databases/$SPANNER_DATABASE" --grpc-channels=500 --tcp="0.0.0.0:9042" &
3+
# Generated configuration file from template using envsubst
4+
# envsubst does not support default values in the template (e.g. ${VAR:-default}).
5+
# We must set the defaults here in the shell before substitution.
6+
export GRPC_CHANNELS=${GRPC_CHANNELS:-4}
7+
export MAX_COMMIT_DELAY=${MAX_COMMIT_DELAY:-0}
8+
9+
# Users should ensure SPANNER_PROJECT, SPANNER_INSTANCE, SPANNER_DATABASE are set.
10+
envsubst < /app/spanner-cassandra-config.yaml > /app/generated-config.yaml
11+
12+
# Start Java Spanner Cassandra Proxy and store PID
13+
# We use the generated config file.
14+
java -DconfigFilePath=/app/generated-config.yaml -jar /app/spanner-cassandra-proxy.jar &
515
cass_pid=$!
16+
617
sleep 5
7-
/zdm-proxy --config="$ZDM_CONFIG" &
18+
19+
# Start ZDM Proxy
20+
/app/zdm-proxy --config="$ZDM_CONFIG" &
821
zdm_pid=$!
922

1023
# Monitor specific PIDs, exit if either of the processes die.
1124
while true; do
1225
if ! kill -0 $cass_pid 2>/dev/null; then
13-
echo "cassandra-to-spanner-proxy (PID $cass_pid) died, shutting down container"
26+
echo "java-spanner-cassandra-proxy (PID $cass_pid) died, shutting down container"
1427
exit 1
1528
fi
1629
if ! kill -0 $zdm_pid 2>/dev/null; then
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
globalClientConfigs:
2+
enableBuiltInMetrics: true
3+
healthCheckEndpoint: "127.0.0.1:8080"
4+
5+
listeners:
6+
- name: "listener_1"
7+
host: "127.0.0.1"
8+
port: 9042
9+
spanner:
10+
databaseUri: "projects/${SPANNER_PROJECT}/instances/${SPANNER_INSTANCE}/databases/${SPANNER_DATABASE}"
11+
numGrpcChannels: ${GRPC_CHANNELS}
12+
maxCommitDelayMillis: ${MAX_COMMIT_DELAY}

0 commit comments

Comments
 (0)