Skip to content

Commit

Permalink
Merge pull request #108 from planetscale/document-fetching-gtids
Browse files Browse the repository at this point in the history
Add information on how to find starting GTIDs to connector
  • Loading branch information
notfelineit authored May 14, 2024
2 parents c7e60f6 + 66aae23 commit 910fcb8
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,29 @@ You can start replication from a specific GTID _per keyspace shard_, by setting
}
```

**Note:** When `starting_gtids` is specified in the configuration file, _and_ a `--state` file is passed, the `--state` file will always take precedence. This is so incremental sync continues working.
**Note:** When `starting_gtids` is specified in the configuration file, _and_ a `--state` file is passed, the `--state` file will always take precedence. This is so incremental sync continues working.

**How to get starting GTIDs**

You can get the latest exectued GTID for every shard by querying your database.
1. Access your PlanetScale database. One way to do so is to use `pscale shell`.
2. Target the keyspace and shard that you would like the latest GTID for by doing `use keyspace/shard`.
- i.e. `use my_sharded_keyspace/-10`
- If your database is _unsharded_, you don't have to target a keyspace or shard. Skip this step.
3. Execute `select @@gtid_executed;`
4. You'll get a result that looks something like:
```
my_sharded_keyspace/-10> select @@gtid_executed\G
*************************** 1. row ***************************
@@`gtid_executed`: 16cec08d-f91b-11ee-8afb-aacaf4984ae5:1-5639808,
b13c2fe0-f91a-11ee-aa81-6251c27c9c24:1-2487289,
fe8e2a3c-f91a-11ee-9812-82f5834c1ba7:1-46602355
1 row in set (0.01 sec)
```
5. Use the GTIDs returned to form the starting GTID for that shard (in this example, shard `-10`):
```
{"my_sharded_keyspace": {"-10": "MySQL56/16cec08d-f91b-11ee-8afb-aacaf4984ae5:1-5639808,b13c2fe0-f91a-11ee-aa81-6251c27c9c24:1-2487289,fe8e2a3c-f91a-11ee-9812-82f5834c1ba7:1-46602355"}}
```
6. Repeat this process for all your shards, if your database is sharded.

**Note**: Remember to prepend the prefix `MySQL56/` onto your starting GTIDs.

0 comments on commit 910fcb8

Please sign in to comment.