pingcap / tidb

TiDB - the open-source, cloud-native, distributed SQL database designed for modern applications.
https://pingcap.com
Apache License 2.0
37.41k stars 5.85k forks source link

Performing full restore and log restore separately will be a disaster #54418

Closed Leavrth closed 3 months ago

Leavrth commented 5 months ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

  1. Start a Log Restore.
  2. Create a table named as test.t1.
  3. Full Backup with backup ts T1.
  4. Insert one row into the cluster.
  5. Wait for log backup task checkpoint to advance.
  6. Restart a new cluster
  7. restore full
  8. restore log restore with start ts T1.

2. What did you expect to see? (Required)

There is one row in the table test.t1.

3. What did you see instead (Required)

There is no row in the table test.t1.

4. What is your TiDB version? (Required)

v6.5, v7.1, v7.5, v8.1

Leavrth commented 5 months ago
                                 time line
                                     |
             start a log task -----> | -----> T0, save table infos at T0, not having table test.t1
                                     |
       create a table test.t1 -----> |
                                     |
                  full backup -----> | -----> T1, save table infos at T1, having table test.t1
                                     |
     insert rows into test.t1 -----> |
                                     |
                                     v
                                 time line
                                     |
                 full restore -----> | -----> downstream having table test.t1
                                     |
                  log restore -----> | -----> use table infos at T0 as based upstream tables' view, however test.t1 is not exist.
                                     |          Therefore, it doesn't know the table id of test.t1, and then doesn't know which data belongs to test.t1
                                     |
                                     v
Leavrth commented 4 months ago

Minimal reproduce step

Backup

# workload 1
mysql --host 127.0.0.1 --port 4000 -u root -e "CREATE TABLE test.t1(id int primary key, a char(20));"

# start a log backup task
tiup br:v8.1.0 log start --task-name pitr -s "local:///root/backups/test1/log" -u 127.0.0.1:2379

# backup full -- BackupTS 450884656681451549
tiup br:v8.1.0 backup full -s "local:///root/backups/test1/full" -u 127.0.0.1:2379

# workload 2
mysql --host 127.0.0.1 --port 4000 -u root -e "CREATE TABLE test.t2(id int primary key, a char(20));"
mysql --host 127.0.0.1 --port 4000 -u root -e "INSERT INTO test.t1 values (1, '1');"

# incremental backup -- BackupTS 450884684363857924
tiup br:v8.1.0 backup full -s "local:///root/backups/test1/incremental" -u 127.0.0.1:2379 --lastbackupts 450884656681451549

# workload 3
mysql --host 127.0.0.1 --port 4000 -u root -e "REPLACE INTO test.t1 values (1, '2');"
mysql --host 127.0.0.1 --port 4000 -u root -e "REPLACE INTO test.t2 values (1, '2');"

Backup Checksum

$ mysql --host 127.0.0.1 --port 4000 -u root -e "SELECT * FROM test.t1;"                               
+----+------+
| id | a    |
+----+------+
|  1 | 2    |
+----+------+

$ mysql --host 127.0.0.1 --port 4000 -u root -e "SELECT * FROM test.t2;"
+----+------+
| id | a    |
+----+------+
|  1 | 2    |
+----+------+

Restore

# full restore
tiup br:v8.1.0 restore full -s "local:///root/backups/test1/full" -u 127.0.0.1:2379

# incremental restore
tiup br:v8.1.0 restore full -s "local:///root/backups/test1/incremental" -u 127.0.0.1:2379

# log restore
tiup br:v8.1.0 restore point -s "local:///root/backups/test1/log" -u 127.0.0.1:2379 --start-ts 450884684363857924

Restore Checksum

# Case - Rewrite TS overrided
$ mysql --host 127.0.0.1 --port 4000 -u root -e "SELECT * FROM test.t1;"
+----+------+
| id | a    |
+----+------+
|  1 | 1    |
+----+------+

# Case - No Rewrite Rule Find
$ mysql --host 127.0.0.1 --port 4000 -u root -e "SELECT count(*) FROM test.t2;"
+----------+
| count(*) |
+----------+
|        0 |
+----------+