-
Notifications
You must be signed in to change notification settings - Fork 504
PS-10287 [8.0]: Add automatic table definition recovery after crash on ALTER #5761
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
Open
inikep
wants to merge
1
commit into
percona:release-8.0.44-35
Choose a base branch
from
inikep:PS-10287-8.0
base: release-8.0.44-35
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+269
−16
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
mysql-test/suite/rocksdb/r/recovery_after_alter_crash.result
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # Include helper scripts to check if RocksDB and debug sync features are available | ||
| # 1. Disable query logging temporarily to suppress expected warnings during test | ||
| # 2. Create a test table with MyRocks engine, a primary key, and one secondary index | ||
| CREATE TABLE t ( | ||
| i INT PRIMARY KEY, | ||
| c1 INT, | ||
| c2 INT, | ||
| KEY k1 (c1) | ||
| ) ENGINE=ROCKSDB; | ||
| # 3. Insert sample data into the table | ||
| INSERT INTO t VALUES (1, 10, 100), (2, 20, 200), (3, 30, 300); | ||
| # 4. Set debug sync to simulate crash after RocksDB commits an ALTER operation | ||
| SET SESSION debug='+d,crash_commit_after_prepare'; | ||
| # 5. Expect the server to crash when committing the ALTER statement | ||
| ALTER TABLE t ADD INDEX k2 (c2), ALGORITHM=INPLACE; | ||
| ERROR HY000: Lost connection to MySQL server during query | ||
| # 6. Wait until the server is fully disconnected due to the crash | ||
| # 7. Restart the MySQL server; MyRocks should automatically rebuild the corrupted table definition | ||
| # restart | ||
| # 8. Verify that the data in the table is intact after reconstruction | ||
| SELECT * FROM t ORDER BY i; | ||
| i c1 c2 | ||
| 1 10 100 | ||
| 2 20 200 | ||
| 3 30 300 | ||
| # 9. Verify that the table structure is consistent and not corrupted | ||
| ANALYZE TABLE t; | ||
| Table Op Msg_type Msg_text | ||
| test.t analyze status OK | ||
| # 10. Check that the original index (k1) exists and can be used in queries | ||
| EXPLAIN SELECT * FROM t WHERE c1 = 200; | ||
| id select_type table partitions type possible_keys key key_len ref rows filtered Extra | ||
| 1 SIMPLE t NULL ref k1 k1 5 const 1 100.00 NULL | ||
| Warnings: | ||
| Note 1003 /* select#1 */ select `test`.`t`.`i` AS `i`,`test`.`t`.`c1` AS `c1`,`test`.`t`.`c2` AS `c2` from `test`.`t` where (`test`.`t`.`c1` = 200) | ||
| # 11. Assert that RocksDB successfully reconstructed the corrupted table | ||
| include/assert_grep.inc [RocksDB table reconstruction finished] | ||
| # 12. Attempt to add a new index k2 on column c2 using the INPLACE algorithm. | ||
| # This command causes a server crash when `rocksdb_validate_tables=1`, which is the default setting | ||
| ALTER TABLE t ADD INDEX k2 (c2), ALGORITHM=INPLACE; | ||
| # 13. Clean up the test table | ||
| DROP TABLE t; |
1 change: 1 addition & 0 deletions
1
mysql-test/suite/rocksdb/t/recovery_after_alter_crash-master.opt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| --loose-rocksdb_validate_tables=2 |
56 changes: 56 additions & 0 deletions
56
mysql-test/suite/rocksdb/t/recovery_after_alter_crash.test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| --echo # Include helper scripts to check if RocksDB and debug sync features are available | ||
| --source include/have_rocksdb.inc | ||
| --source include/have_debug_sync.inc | ||
|
|
||
| --echo # 1. Disable query logging temporarily to suppress expected warnings during test | ||
| --disable_query_log | ||
| CALL mtr.add_suppression("Plugin rocksdb reported: 'Table '.*' definition differs between MyRocks .* ADD INDEX'"); | ||
| --enable_query_log | ||
|
|
||
| --echo # 2. Create a test table with MyRocks engine, a primary key, and one secondary index | ||
| CREATE TABLE t ( | ||
| i INT PRIMARY KEY, | ||
| c1 INT, | ||
| c2 INT, | ||
| KEY k1 (c1) | ||
| ) ENGINE=ROCKSDB; | ||
|
|
||
| --echo # 3. Insert sample data into the table | ||
| INSERT INTO t VALUES (1, 10, 100), (2, 20, 200), (3, 30, 300); | ||
|
|
||
| --echo # 4. Set debug sync to simulate crash after RocksDB commits an ALTER operation | ||
| SET SESSION debug='+d,crash_commit_after_prepare'; | ||
|
|
||
| --echo # 5. Expect the server to crash when committing the ALTER statement | ||
| --source include/expect_crash.inc | ||
| --error CR_SERVER_LOST | ||
| ALTER TABLE t ADD INDEX k2 (c2), ALGORITHM=INPLACE; | ||
|
|
||
| --echo # 6. Wait until the server is fully disconnected due to the crash | ||
| --source include/wait_until_disconnected.inc | ||
|
|
||
| --echo # 7. Restart the MySQL server; MyRocks should automatically rebuild the corrupted table definition | ||
| --source include/start_mysqld.inc | ||
|
|
||
| --echo # 8. Verify that the data in the table is intact after reconstruction | ||
| SELECT * FROM t ORDER BY i; | ||
|
|
||
| --echo # 9. Verify that the table structure is consistent and not corrupted | ||
| ANALYZE TABLE t; | ||
|
|
||
| --echo # 10. Check that the original index (k1) exists and can be used in queries | ||
| EXPLAIN SELECT * FROM t WHERE c1 = 200; | ||
|
|
||
| --echo # 11. Assert that RocksDB successfully reconstructed the corrupted table | ||
| --let $assert_text = RocksDB table reconstruction finished | ||
| --let $assert_file = $MYSQLTEST_VARDIR/log/mysqld.1.err | ||
| --let $assert_select = Reconstruction of the corrupted table .* has finished. | ||
| --let $assert_count = 1 | ||
| --source include/assert_grep.inc | ||
|
|
||
| --echo # 12. Attempt to add a new index k2 on column c2 using the INPLACE algorithm. | ||
| --echo # This command causes a server crash when `rocksdb_validate_tables=1`, which is the default setting | ||
| ALTER TABLE t ADD INDEX k2 (c2), ALGORITHM=INPLACE; | ||
|
|
||
| --echo # 13. Clean up the test table | ||
| DROP TABLE t; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this allocation throws, we will have
new_key_descrleaked.May be use
std::unique_ptr<Rdb_tbl_def> new_tdefandstd::unique_ptr<Rdb_key_def[]> new_key_descr?