---
name: ticdc-next-gen-deploy
description: Use when deploying or destroying a TiCDC next-gen test stack with TiUP, especially when you need SSH-based execution, configurable keyspace TiDB count, and optional changefeed creation with auto sink-uri resolution.
---

# TiCDC Next-Gen Deploy

Use this skill for a reusable next-gen deployment flow:

1. start minio and create bucket
2. deploy/patch/start TiDB cluster with `tiup`
3. start keyspace-specific `tidb-server`
4. optionally create TiCDC changefeed
5. optionally destroy deployed components

## Files in this skill

- `scripts/ticdc_next_gen.sh`: unified entrypoint with `deploy` and `destroy`

## Required prerequisites

- Local agent can SSH to target host.
- SSH public key is copied to target host before deployment.
  - Example: `ssh-copy-id -i ~/.ssh/id_rsa.pub -p 22 root@10.2.7.6`
- Target host has required commands:
  - `ssh`
  - `curl` or `wget` (for auto-install when tools are missing)
- Target host should have outbound internet access for downloading installers/binaries from official sources:
  - TiUP installer: `https://tiup-mirrors.pingcap.com/install.sh`
  - MinIO binaries: `https://dl.min.io/...`
- Patch package paths can be provided via:
  - `--patch-tikv`
  - `--patch-tidb`
  - `--patch-pd`
  - `--patch-cdc`
- If `--patch-*` is not provided, the script prompts for each path and verifies file existence on the execution host.

## Deploy

`--host` is required. `10.2.7.6` below is only an example.

### SSH mode (script always SSHes to target host)

```bash
bash skills/ticdc-next-gen-deploy/scripts/ticdc_next_gen.sh deploy \
  --host <deploy-host-ip> \
  --project-dir <project-path-on-target> \
  --keyspace-count 2
```

## Optional changefeed creation

### Explicit sink-uri

```bash
bash skills/ticdc-next-gen-deploy/scripts/ticdc_next_gen.sh deploy \
  --host <deploy-host-ip> \
  --project-dir <project-path-on-target> \
  --keyspace-count 2 \
  --create-changefeed \
  --source-keyspace 1 \
  --changefeed-id test-sink \
  --sink-uri 'mysql://root@127.0.0.1:14002'
```

### Auto-detect sink-uri from deployed keyspace TiDB

Use `--sink-deployed-keyspace <n>` to auto-build:
`mysql://<sink-user>@<sink-host>:<resolved-port>`

Port resolution uses runtime base port (derived from topo or overridden via
`--keyspace-tidb-base-port`) and computes `base_port + keyspace_index`.

```bash
bash skills/ticdc-next-gen-deploy/scripts/ticdc_next_gen.sh deploy \
  --host <deploy-host-ip> \
  --project-dir <project-path-on-target> \
  --keyspace-count 2 \
  --create-changefeed \
  --source-keyspace 1 \
  --changefeed-id test-sink \
  --sink-deployed-keyspace 2
```

## Destroy

`destroy` only removes what this script deploys/starts:

- destroy target TiUP cluster (`--cluster-name`)
- kill `minio`, `tidb-server`, `local-kms`
- cleanup `/tmp/next-gen-with-cdc` and `/tmp/minio/next-gen-cdc`

```bash
bash skills/ticdc-next-gen-deploy/scripts/ticdc_next_gen.sh destroy \
  --host <deploy-host-ip> \
  --project-dir <project-path-on-target>
```

## Notes

- Script generates topo and keyspace config files in `/tmp/next-gen-with-cdc/skill-generated`; it does not modify checked-in files.
- Script does not hardcode a specific deployment IP and requires `--host` input.
- Script always executes on the target host via SSH.
- Script auto-installs missing `tiup`, `minio`, and `mc` on the execution host.
- Keyspace TiDB uses `tidb-server` extracted from `--patch-tidb`; it does not fall back to TiUP component binaries.
- Auto sink-uri for `--sink-deployed-keyspace` defaults to `127.0.0.1` unless `--sink-host` is provided.
- Keyspace TiDB is started in detached mode and remains running after deploy command exits.
- Changefeed creation extracts and uses the `cdc` binary from `--patch-cdc` tar.gz.
- Deploy output prints troubleshooting directories for generated topo/config/log files and extracted patch binaries.
- Generated topo always ensures both `monitoring_servers` and `grafana_servers` are present (auto-appended with default ports if missing).
- If SSH auth fails, the script prints `ssh-copy-id` hint and exits.
