# TiCDC Next-Gen Deployment Skill

This repository includes TiCDC next-gen deployment scripts and a reusable automation skill.

## Manual Deployment Flow

1. `bash start-minio.sh`
2. `bash start-cluster.sh`
3. `bash start-keyspace1-tidb.sh`
4. `bash start-keyspace2-tidb.sh`
5. Extract `cdc` from patch package and create a changefeed:

```bash
<path-to-extracted-cdc>/cdc cli changefeed --server=127.0.0.1:18300 \
  -k keyspace1 \
  create \
  --sink-uri=mysql://root@127.0.0.1:14002 \
  -c test-sink
```

## Automated Skill

The skill is located at `skills/ticdc-next-gen-deploy`.

Unified entrypoint:

```bash
bash skills/ticdc-next-gen-deploy/scripts/ticdc_next_gen.sh --help
```

### Use Through Agent Natural Language

You can ask the agent to execute this skill directly in plain language.

Examples:

1. Deploy:

```text
Use ticdc-next-gen-deploy to deploy on host 10.2.7.6.
Project dir is /root/project, keyspace count is 2.
Patch files:
  --patch-tikv /root/tikv-server.tar.gz
  --patch-tidb /root/tidb-server.tar.gz
  --patch-pd /root/pd-server.tar.gz
  --patch-cdc /root/cdc.tar.gz
```

2. Deploy and create changefeed to deployed keyspace2:

```text
Use ticdc-next-gen-deploy to deploy on 10.2.7.6 with 2 keyspaces and create a changefeed.
Source keyspace is 1, sink is deployed keyspace 2, changefeed id is test-sink.
Patch files are in /root: tikv-server.tar.gz, tidb-server.tar.gz, pd-server.tar.gz, cdc.tar.gz.
```

3. Destroy:

```text
Use ticdc-next-gen-deploy to destroy the environment on 10.2.7.6,
project dir /root/project, cluster name next-gen-cluster.
```

Notes:

- If patch paths are not provided, the script will prompt for them and verify file existence.
- If `tiup`, `minio`, or `mc` is missing, the script will auto-install them on the execution host.

### Typical Usage

`--host` must be provided by the user. `10.2.7.6` below is only an example.

Deploy (the script always SSHes into the target host):

```bash
bash skills/ticdc-next-gen-deploy/scripts/ticdc_next_gen.sh deploy \
  --host 10.2.7.6 \
  --project-dir /root/project \
  --keyspace-count 2 \
  --create-changefeed \
  --source-keyspace 1 \
  --sink-deployed-keyspace 2 \
  --changefeed-id test-sink
```

Destroy deployment (only components created/started by this script):

```bash
bash skills/ticdc-next-gen-deploy/scripts/ticdc_next_gen.sh destroy \
  --host 10.2.7.6 \
  --project-dir /root/project
```

## Prerequisites

- Passwordless SSH is configured (the script prints an `ssh-copy-id` hint when SSH auth fails).
- Target host has `ssh`, plus `curl` or `wget` (used for auto-installing missing tools).
- Target host has outbound internet access to download official installers/binaries (TiUP, MinIO, mc).
- 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.
- The script auto-installs missing `tiup`, `minio`, and `mc` on the current 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` uses `127.0.0.1` by default (override with `--sink-host` if needed).
- Keyspace TiDB processes are started in detached mode and keep running after the deploy script exits.
- Changefeed creation uses the `cdc` binary extracted 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).
