Bug #116212 fts_delete is not crash-safe if binlog is disabled
Submitted: 24 Sep 9:29 Modified: 24 Sep 11:53
Reporter: Yin Peng (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: FULLTEXT search Severity:S3 (Non-critical)
Version:8.4.2 OS:Any
Assigned to: CPU Architecture:Any
Tags: Contribution

[24 Sep 9:29] Yin Peng
Description:
In function 'fts_commit_table' a new trx object is allocated to handle the insertion of fts_*_deleted.
When binlog is disabled, an inconsistency may occur between fulltext index and clustered index.

How to repeat:
A debug point should be added in function 'fts_commit_table':

diff --git a/storage/innobase/fts/fts0fts.cc b/storage/innobase/fts/fts0fts.cc
index c0e16dfd93d..ba48a628c63 100644
--- a/storage/innobase/fts/fts0fts.cc
+++ b/storage/innobase/fts/fts0fts.cc
@@ -3239,6 +3239,10 @@ dberr_t fts_create_doc_id(dict_table_t *table, dtuple_t *row,
 
   trx_free_for_background(trx);
 
+  DBUG_EXECUTE_IF("fts_sync_cache_and_crash_after_commit_table", {
+    DBUG_SUICIDE();
+  });
+
   return (error);
 }

Run test script(option '--mysqld=--skip-log-bin' should be specified):

create table opening_lines (
       id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
       opening_line TEXT(500),
       author VARCHAR(200),
       title VARCHAR(200),
       FULLTEXT idx (opening_line)
       ) ENGINE=InnoDB;

insert into opening_lines(opening_line,author,title) VALUES
       ('A screaming comes across the sky.','Thomas Pynchon','Gravity\'s Rainbow');
select * from opening_lines WHERE MATCH(opening_line) AGAINST('screaming');

--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
set debug='+d,fts_sync_cache_and_crash_after_commit_table';
--error 2013
delete from opening_lines;
--source include/wait_until_disconnected.inc
--echo # Restart the master server
--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
--source include/wait_until_connected_again.inc

select * from opening_lines;

select * from opening_lines WHERE MATCH(opening_line) AGAINST('screaming');

No row is returned in the result of the full-text search, although there should be one.

Suggested fix:
Use the original trx object if it's active.
[24 Sep 9:29] Yin Peng
Use the original trx object if it's active.

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: patch.txt (text/plain), 1.74 KiB.

[24 Sep 11:53] MySQL Verification Team
Hello yin peng,

Thank you for the report and contribution.

regards,
Umesh