Note: This tool is not an official Google Cloud product. It is provided for illustration purposes only and should be used as a starting point for creating your own tooling.
A web application for managing Google Cloud Spanner split points with local staging.
- Local Staging: Stage split point changes locally before syncing to Spanner
- Batch Sync: Automatically batches changes to respect Spanner's 100 split points per request limit
- Visual Status: See which splits are synced, pending add, or pending delete
- Safe Deletes: Mark splits for deletion (sets immediate expiration) before syncing
- Backend: FastAPI (Python 3.10+)
- Database: SQLite (local staging)
- Frontend: Jinja2 templates + Alpine.js + TailwindCSS
- Cloud: Google Cloud Spanner SDK
# Create virtual environment (or use conda)
python3 -m venv .venv
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txtCreate a .env file:
PROJECT=your-gcp-project
SPANNER_INSTANCE=your-instance
SPANNER_DATABASE=your-databaseConfigure connection settings through the web interface at /settings.
Authenticate using Application Default Credentials:
gcloud auth application-default login# Development server with auto-reload
uvicorn main:app --reload
# Or specify host/port explicitly
uvicorn main:app --reload --host 0.0.0.0 --port 8000Access the application at http://localhost:8000
If you're developing on a remote machine via VS Code Remote SSH or a cloud VM:
-
Start the server in the VS Code integrated terminal:
uvicorn main:app --reload --port 8000
-
VS Code automatically detects the port and offers to forward it. Look for a notification in the bottom-right corner, or:
- Open the Ports panel (View > Open View > Ports, or click "Ports" in the bottom panel)
- You'll see port 8000 listed
- Click the globe icon or the forwarded address to open in your local browser
-
Alternatively, manually forward the port:
- Open Command Palette (
Ctrl+Shift+P/Cmd+Shift+P) - Run "Forward a Port"
- Enter
8000
- Open Command Palette (
The tunnel allows your local browser to access the web app running on the remote machine.
Before using the app, configure your Spanner connection. You have two options:
Option 1: Environment Variables
Set these environment variables (or create a .env file):
PROJECT=your-gcp-project
SPANNER_INSTANCE=your-instance
SPANNER_DATABASE=your-databaseOption 2: Web UI Settings
- Navigate to Settings in the navigation bar
- Enter your GCP Project ID, Spanner Instance, and Database name
- Click Save Settings
- The app will validate the connection and show available tables
Precedence: Web UI settings take precedence over environment variables. If you configure settings via the UI, those values will be used even if environment variables are set. To revert to using environment variables, clear the values in the Settings page.
View and manage tables that have split points:
- The page lists all tables/indexes with existing or staged split points
- Click on a table name to view its split point details
- Use Refresh to fetch the latest data from Spanner
When viewing a specific table's split points:
-
View existing splits: Shows all split points with their current status
- Synced (green): Exists in Spanner, no pending changes
- Pending Add (yellow): Staged locally, will be added on sync
- Pending Delete (red): Marked for deletion, will expire on sync
-
Add new split points:
- Enter the split key value(s) in the input field
- Click Add Split to stage it locally
- The split appears with "Pending Add" status
-
Delete split points:
- Click the Delete button next to any split
- For synced splits, this marks them as "Pending Delete"
- For pending adds, this removes them from local staging
-
Sync to Spanner:
- Click Sync to push all pending changes to Spanner
- Adds are sent as new split points
- Deletes are sent with immediate expiration time
- Changes are automatically batched (max 100 per request)
- Configure connection in Settings
- Navigate to Tables to see existing split points
- Click a table to view/manage its splits
- Add new splits or mark existing ones for deletion
- Review pending changes (yellow/red status indicators)
- Click Sync to apply all changes to Spanner
- Refresh to verify the changes took effect
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/splits |
List all split points with status |
| POST | /api/splits |
Add a new local split |
| DELETE | /api/splits/{id} |
Remove a local split |
| POST | /api/sync |
Sync pending changes to Spanner |
| GET | /api/settings |
Get current settings |
| POST | /api/settings |
Update settings |
User -> Web UI (Jinja2/Alpine.js)
-> FastAPI API Routes (JSON)
-> SQLite (local staging)
-> Spanner Service (batched API calls)
-> Google Cloud Spanner
Split points flow through three states:
- SYNCED: Exists in Spanner, no local changes
- PENDING_ADD: Staged locally, waiting to be sent to Spanner
- PENDING_DELETE: Exists in Spanner, marked for expiration locally
