-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lightning: auto increment value became much larger than expected after physical import with parallel import enabled #56814
Comments
Could you add the output of
What does What was the |
Table Structure with MySQL
Table structure created in TIDB with Auto_ID_CACHE before starting DM,
DM was started with "full" import mode with replication, we used physical import. Auto-increment was fine in TiDB as well since Binlog format was FULL and replication happening from mysql During the day of Cut-over we paused the DM task last ID synced from mysql
When Application was directly pointed to TiDB from application it generated id starting with "730170668"
|
Side note, you might want to use markdown to format code and output: |
I tried to reproduce this, but failed to do so: MySQL 8.0.40 with: CREATE TABLE t1 (id int AUTO_INCREMENT PRIMARY KEY) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
INSERT INTO t1 values (100);
INSERT INTO t1() values (); TiDB v8.1.1 with: CREATE TABLE t1 (id int AUTO_INCREMENT PRIMARY KEY) AUTO_ID_CACHE=1 CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; DM task with Result after stopping the DM task:
|
Hope you tried with the physical import also after making the replication pls insert some via replication and then pause the DM task and make a direct write to TiDB |
Hi @kabileshKabi , thanks for reporting this issue. According to the reproduction steps and other comments, you mentioned both 'DM' and 'Physical Import'(which is a concept of Lightning / Also, please notice that:
|
Hello, @kabileshKabi From your comment above, I found
It seems that you use don't use the same AUTO_INCREMENT between MySQL and TiDB, for TiDB, it may be I tried to reproduce: Step 1For MySQL CREATE TABLE `messages` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `updatedAt` int DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=14430410 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; For TiDB CREATE TABLE `messages` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `updatedAt` int DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=74430410 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; Step 2For MySQL
then start the DM replication For TiDB select * from messages;
+----------+------------+
| id | updatedAt |
+----------+------------+
| 14430410 | 1730085690 |
+----------+------------+ Step 3stop the DM replication For TiDB
Then select in TiDB select * from messages;
+----------+------------+
| id | updatedAt |
+----------+------------+
| 14430410 | 1730085690 |
| 74460410 | 1730086179 |
+----------+------------+ you can see different id here. I guess this meets the expectation? please correct me if I am wrong @bb7133 @dveeden |
If this is the original create table syntax, it's expected that the next ID allocated starts from But I'm not sure if this syntax is generated manually or by DM. |
@siddontang your previous comment is the issue i exactly face, when directly Inserted in TiDB the Autoincrement ID gets leaped |
Below Are the exact steps followed: Till this point ID is matching between MySQL and TiDB On the day of cut-over we paused the DM task replication and pointed the writes directly to TiDB --> This is when we see the jump in Auti-increment ID. |
@kabileshKabi About 'Physical Import' of DM, is it some argument or configuration of DM? I didn't find such a thing in DM document. |
These are the configs exactly used in DM @bb7133 task-mode: all |
@kabileshKabi Thanks! I confirmed that DM with physical import actually used 'Lightning import' code, so probably this is caused by #56476. We'll try to confirm and reproduce it. BTW, the version of DM you're using is also v8.1.1, right? |
yes its version 8.1.1 @bb7133 |
@bb7133 i have read thru the bug #56476 here the auto-increment is not getting updated as n+1 post migration data with DM using physical loading causing duplicate error while pointing application or writes. In my case the ID is getting jumped to a higher valuer on its own and goes as n+1 from there, hope the issue is clear now |
DM physical mode integrates lightning, in this case lightning will set the auto_incr_id allocator after physical import, but from above info your table is using clustered index, the id shouldn't jump, I will try to reproduce it locally. @kabileshKabi also can you paste the result of |
I try import a similar table with clustered index and AUTO_ID_CACHE=1 using lightning(as DM only uses calls lightning, so it should make no difference), data source file is about 150M and have 330000 rows, after import no ID jump
|
this is the current structure in TiDB
|
Have you used the physical-import can you pls confirm ? |
yes @siddontang you are correct |
yes, physical mode of lightning, I will try DM physical mode too, although they uses same code actually @kabileshKabi
|
This was given to depict the current auto-increment value post cut-over with TiDB and also to show that auto-id-cache has been enabled
|
reproduced locally. the cause is DM enabled parallel-import to support the case of Shard Merge where there will be multiple workers importing to same target table, and in that case we have a
the ID is still that sequence, but have a jump. how is this affects your application? |
BTW: for performance reasons when using |
@D3Hunter application is completely dependent on the auto-generated ID from DB, since we had seen a complete it had caused lot of data mismatch as a sequence is lost. Is there any work around to stop this behaviour of DM, also if there any ETA for this fix? |
a workaround is to use DM with logical import or you can dump the data using dumpling and import using lightning with the fix PR should be filed within this week, but we have a releasing schedule for bug fix versions, if you are urgent you can apply for a hotfix through supporters. |
Bug Report
We made a cut-over to TiDB
The table is Messages table with Auto increment on "ID"
to maintain the ID sequence the table was created with "auto_id_cache" as below
**) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT=730234878 /T![auto_id_cache] AUTO_ID_CACHE=1 /
In the MySQL last sequence was "14609942" but in TiDB ID was incremented by a vast number "730170668" pl find as below
mysql> select id,updatedAt from messages where id >=14609942 limit 10;
+-----------+------------+
| id | updatedAt |
+-----------+------------+
| 14609942 | 1729291247 | ----> MySQL
| 730170668 | 1729313914 | -----> TIDB
| 730170669 | 1729313914 |
| 730170670 | 1729313914 |
| 730170671 | 1729313914 |
| 730170672 | 1729313914 |
| 730170673 | 1729313914 |
| 730170674 | 1729313914 |
| 730170675 | 1729313914 |
| 730170676 | 1729313914 |
+-----------+------------+
the TIDB has added or incremented the value on its own, This is a critical bug making TiDB unusable in production
1. Minimal reproduce step (Required)
1,Create the table structure same as MySQL also have auto_id_cache=1 to maintain compatibility.
2, Migrate the data to TiDB using DM and setup replication. till this point ID would be matching
3, Stop or Pause the DM
4, Point the application directly to use TiDB, you can see a huge jump in auto increment value.
2. What did you expect to see? (Required)
we expected the same sequence to be continue with TiDB, making it compatible
3. What did you see instead (Required)
we see a complete new ID sequence has been introduced, breaking the application
4. What is your TiDB version? (Required)
Release Version: v8.1.1
Edition: Community
Git Commit Hash: a7df4f9
Git Branch: HEAD
UTC Build Time: 2024-08-22 05:49:03
GoVersion: go1.21.13
Race Enabled: false
Check Table Before Drop: false
Store: tikv
The text was updated successfully, but these errors were encountered: