[MDEV-19158] MariaDB 10.2.22 is writing duplicate entries into binary log Created: 2019-04-03 Updated: 2019-05-20 Resolved: 2019-05-14 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Replication |
| Affects Version/s: | 10.2.22 |
| Fix Version/s: | 10.2.25, 10.3.16, 10.4.5 |
| Type: | Bug | Priority: | Major |
| Reporter: | kilroy | Assignee: | Sujatha Sivakumar (Inactive) |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | None | ||
| Environment: |
Gentoo |
||
| Attachments: |
|
| Description |
|
We have a Master/Master Setup on two servers, but are only writing to one of those servers (so it is essentially Master/Slave) We upgraded from 10.1.* to 10.2.22 last week and starting with the upgrade, we are getting duplicate key errors on the slave. BINLOG=mixed Examing the binary log on the master and the relay log on the slave, we see:
Then one binary blob:
And then in Statement format:
Which fails since it repeats the last statement of the binary blob. If I replay it by hand and leave out the statement block, everything is ok. I have found others to have the same problem. They found this bug starting with 10.2.10 (but it can also be earlier). One example is https://stackoverflow.com/questions/47650166/mariadb-10-2-10-writing-double-binlog-entries-in-mixed-format What adds to the strangeness: Only 1 in 100 inserts triggers this behavior and it only seems to be triggered on clients that access the master from outside the network (additionally, this client has MariaDB client libs from 10.1.*). So maybe it is a timing issue? |
| Comments |
| Comment by Andrei Elkin [ 2019-04-03 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thank you for the report, kilroy! To start analyzing this issue we need 1. the output from {{mysqlbinlog -v --start-position=`the-transaction-begin-offset` --stop-position=`the-next-begin-offset` }} 2. Also do that to a previous transaction (BEGIN..Xid_log_event or a DDL) from the same thread_id=NNN. 3. Give us the table 1-3 show create table In Only 1 in 100 inserts triggers this behavior I read you can reproduce this issue, can you? Cheers, Andrei | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by kilroy [ 2019-04-03 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
And I for myself just need to wait, the customers using the application trigger it. They just triggered it again (at 9:43 GMT). That makes 3 incidents in <3 days. I have anonymized the bin log and the tables and I hope the important parts are still there, I didn't delete any referencing ids but I needed to remove all binlog content since this contains user data... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by kilroy [ 2019-04-03 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
And just another one happened. Its raining now | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by kilroy [ 2019-04-03 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Another 5 happened. All from external writers (host in same subnet over 1gig connection). Now this host has an updated MariaDB client library (10.2.22, too) and the errors are still coming. I have zero issues from local writers (same machine)! I have tested the same queries over and over again from the local machine - everything works fine. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by kilroy [ 2019-04-03 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I have nailed it: We have a corner case in this application where an old function is called sometimes. This case was used for a reeeeeeal old MySQL version workaround. This function does the following: set @@autocommit = 0 .... INSERT (multiple times) UNLOCK ALL TABLES COMMIT This always produces the bug... I have fixed it with real transactions, everything works now. But I think this corner case should be caught anyway, too. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Andrei Elkin [ 2019-04-03 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
kilroy That's a great exploit from your side | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sujatha Sivakumar (Inactive) [ 2019-04-04 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hello Kilroy, I tried creating a function as per your above inputs but it fails. I tried in both 10.1 and 10.2. MariaDB [test]> create table t ( f int ) engine=innodb; MariaDB [test]> DELIMITER $$ Can you please provide the master server version. Since you are able to consistently reproduce can you share the SHOW CREATE FUNCTION output; Thanks | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by kilroy [ 2019-04-04 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
With "function" I meant a normal function (here: Python) which executes these statements in the order mentioned. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Daniel Ragle [ 2019-04-24 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I believe I am also bitten by this bug; I am seeing duplicate insert statements in the binary log after upgrading from 5.5 => 10.3.14 (stepwise upgrade, mysql_upgrade performed with each step). I use binlog_format=MIXED. Here's how I reproduce it, perhaps it can even be reduced further:
Note that the trigger doesn't actually do anything, it just seems to need to exist and reference t3 (likely something having to do with the implied LOCK Now, key statements in the binary log (abbreviated):
The first command is statement-based and is fine. The second is auto-converted to RBR, but it also appears fine. The third transaction is the problem; I copied that block verbatim from the BEGIN through the COMMIT from the binary log. Notice that within the same BEGIN..COMMIT block there is both an RBR insert for the row, as well as a statement insert for the row, both referencing the same PK (the latter via SET INSERT_ID=2). This of course breaks replication on the slave. This is a critical issue for me as we have several constructs like this. If anyone could share a decent work around I would greatly appreciate it. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Daniel Ragle [ 2019-04-24 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Actually just found this one: https://jira.mariadb.org/browse/MDEV-18437 which may be more on point with what I'm seeing. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sujatha Sivakumar (Inactive) [ 2019-04-24 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hello Daniel, Thank you for the latest update. I was able to reproduce the issue on 10.2.22.
Hence I am marking it as verified. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sujatha Sivakumar (Inactive) [ 2019-05-03 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
On debug builds following DBUG_ASSERT is reported on Master:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Daniel Ragle [ 2019-05-03 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
To anyone following this and looking for a work-around: We found that we could bypass the bug by creating a do-nothing temporary table with an AUTO INCREMENT PK prior to the LOCK TABLES, then deleting the temporary table after the UNLOCK TABLES. The temporary table itself does not need to be locked, and nothing needs to be in it. I.E.,
With this construct, unfortunately all of the statements from the LOCK to the UNLOCK are written as RBR; but there is no statement duplication. Possibly the same effect could be achieved via explicitly setting BINLOG_FORMAT=ROW before the LOCK TABLES and back to MIXED afterwards, though as I recall you need SUPER to do that. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sujatha Sivakumar (Inactive) [ 2019-05-10 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hello Andrei, Good morning. The patch is available at https://github.com/MariaDB/server/commit/e28c2408c7447e70d9509c9078f1b93a7cda6078 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Andrei Elkin [ 2019-05-13 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Sujatha, well done, thanks for a nice work! Andrei | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sujatha Sivakumar (Inactive) [ 2019-05-14 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Fix for this issue is pushed in 10.2.25. 10.3 merge will have a minor conflict in sql/handler.h: Please find the 10.3 patch https://github.com/MariaDB/server/commit/86a6a3b8faddc5f8ff1898c5b9a6727f9b584be0 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Daniel Ragle [ 2019-05-19 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
This is listed as being fixed in 10.3.15; however I just updated to that version and I'm still seeing the same behavior from my test script above. Also, I suspect https://jira.mariadb.org/browse/MDEV-18437 should be linked to this one, as I believe they're the same issue. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sujatha Sivakumar (Inactive) [ 2019-05-20 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hello Daniel, Thank you for checking the 10.3.15 release. You are right, the fix missed the 10.3.15 release. Marked |