Skip to content

Commit

Permalink
tiflash: add description about behavior after executing ALTER DATABASE (
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot committed May 25, 2023
1 parent 863ea7e commit 60388e2
Showing 1 changed file with 3 additions and 25 deletions.
28 changes: 3 additions & 25 deletions tiflash/create-tiflash-replicas.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ This document introduces how to create TiFlash replicas for tables and for datab

After TiFlash is connected to the TiKV cluster, data replication by default does not begin. You can send a DDL statement to TiDB through a MySQL client to create a TiFlash replica for a specific table:

{{< copyable "sql" >}}

```sql
ALTER TABLE table_name SET TIFLASH REPLICA count;
```
Expand All @@ -25,16 +23,12 @@ If you execute multiple DDL statements on the same table, only the last statemen

Create two replicas for the table:

{{< copyable "sql" >}}

```sql
ALTER TABLE `tpch50`.`lineitem` SET TIFLASH REPLICA 2;
```

Delete the replica:

{{< copyable "sql" >}}

```sql
ALTER TABLE `tpch50`.`lineitem` SET TIFLASH REPLICA 0;
```
Expand All @@ -43,8 +37,6 @@ ALTER TABLE `tpch50`.`lineitem` SET TIFLASH REPLICA 0;

* If the table `t` is replicated to TiFlash through the above DDL statements, the table created using the following statement will also be automatically replicated to TiFlash:

{{< copyable "sql" >}}

```sql
CREATE TABLE table_name like t;
```
Expand All @@ -61,8 +53,6 @@ ALTER TABLE `tpch50`.`lineitem` SET TIFLASH REPLICA 0;

You can check the status of the TiFlash replicas of a specific table using the following statement. The table is specified using the `WHERE` clause. If you remove the `WHERE` clause, you will check the replica status of all tables.

{{< copyable "sql" >}}

```sql
SELECT * FROM information_schema.tiflash_replica WHERE TABLE_SCHEMA = '<db_name>' and TABLE_NAME = '<table_name>';
```
Expand All @@ -76,8 +66,6 @@ In the result of above statement:

Similar to creating TiFlash replicas for tables, you can send a DDL statement to TiDB through a MySQL client to create a TiFlash replica for all tables in a specific database:

{{< copyable "sql" >}}

```sql
ALTER DATABASE db_name SET TIFLASH REPLICA count;
```
Expand All @@ -88,16 +76,12 @@ Examples:

- Create two replicas for all tables in the database `tpch50`:

{{< copyable "sql" >}}

```sql
ALTER DATABASE `tpch50` SET TIFLASH REPLICA 2;
```

- Delete TiFlash replicas created for the database `tpch50`:

{{< copyable "sql" >}}

```sql
ALTER DATABASE `tpch50` SET TIFLASH REPLICA 0;
```
Expand All @@ -108,25 +92,23 @@ Examples:
>
> - After executing the statement, do not set the number of TiFlash replicas or perform DDL operations on this database until **all tables in this database are replicated**. Otherwise, unexpected results might occur, which include:
> - If you set the number of TiFlash replicas to 2 and then change the number to 1 before all tables in the database are replicated, the final number of TiFlash replicas of all the tables is not necessarily 1 or 2.
> - After executing the statement, if you create tables in this database before the completion of the statement execution, TiFlash replicas **may or may not** be created for these new tables.
> - After executing the statement, if you create tables in this database before the completion of the statement execution, TiFlash replicas **might or might not** be created for these new tables.
> - After executing the statement, if you add indexes for tables in the database before the completion of the statement execution, the statement might hang and resume only after the indexes are added.
>
> - If you create tables in this database **after** the completion of the statement execution, TiFlash replicas are not created automatically for these new tables.
>
> - This statement skips system tables, views, temporary tables, and tables with character sets not supported by TiFlash.
### Check replication progress

Similar to creating TiFlash replicas for tables, successful execution of the DDL statement does not mean the completion of replication. You can execute the following SQL statement to check the progress of replication on target tables:

{{< copyable "sql" >}}

```sql
SELECT * FROM information_schema.tiflash_replica WHERE TABLE_SCHEMA = '<db_name>';
```

To check tables without TiFlash replicas in the database, you can execute the following SQL statement:

{{< copyable "sql" >}}

```sql
SELECT TABLE_NAME FROM information_schema.tables where TABLE_SCHEMA = "<db_name>" and TABLE_NAME not in (SELECT TABLE_NAME FROM information_schema.tiflash_replica where TABLE_SCHEMA = "<db_name>");
```
Expand Down Expand Up @@ -229,16 +211,12 @@ When configuring replicas, if you need to distribute TiFlash replicas to multipl

2. After starting a cluster, specify the labels when creating replicas.

{{< copyable "sql" >}}

```sql
ALTER TABLE table_name SET TIFLASH REPLICA count LOCATION LABELS location_labels;
```

For example:

{{< copyable "sql" >}}

```sql
ALTER TABLE t SET TIFLASH REPLICA 2 LOCATION LABELS "zone";
```
Expand Down

0 comments on commit 60388e2

Please sign in to comment.