Merge lp:~longbow/percona-server/bug_898306_5.1 into lp:percona-server/5.1

Proposed by Valentine Gostev
Status: Merged
Approved by: Valentine Gostev
Approved revision: no longer in the source branch.
Merged at revision: 416
Proposed branch: lp:~longbow/percona-server/bug_898306_5.1
Merge into: lp:percona-server/5.1
Diff against target: 173 lines (+120/-0)
6 files modified
Percona-Server/mysql-test/r/percona_innodb_fake_changes_bug_898306.result (+40/-0)
Percona-Server/mysql-test/t/percona_innodb_fake_changes_bug_898306.test (+58/-0)
Percona-Server/sql/handler.h (+6/-0)
Percona-Server/sql/sql_insert.cc (+9/-0)
Percona-Server/storage/innodb_plugin/handler/ha_innodb.cc (+6/-0)
Percona-Server/storage/innodb_plugin/handler/ha_innodb.h (+1/-0)
To merge this branch: bzr merge lp:~longbow/percona-server/bug_898306_5.1
Reviewer Review Type Date Requested Status
Alexey Kopytov (community) Approve
Review via email: mp+88859@code.launchpad.net

This proposal supersedes a proposal from 2012-01-17.

Description of the change

Added test and fix (Mark's patch) for bug 898306

To post a comment you must log in.
Revision history for this message
Valentine Gostev (longbow) wrote : Posted in a previous version of this proposal
Revision history for this message
Oleg Tsarev (tsarev) wrote : Posted in a previous version of this proposal

Please add description of changes to commit message.

For example, this part of patch important

133 + /* Avoid the infinite loop
134 + * 1) get dup key on fake insert
135 + * 2) do nothing on fake delete
136 + * 3) goto #1
137 + */

And also important

review: Needs Fixing
Revision history for this message
Alexey Kopytov (akopytov) wrote : Posted in a previous version of this proposal

The code itself looks good, but the style and test case need a few tweaks. Indentation and comments should match the server and InnoDB code style.

And the additional connection created in the test is not really used, so it should be removed. A comment header in the test referencing the bug number would also be useful.

review: Needs Fixing
Revision history for this message
Alexey Kopytov (akopytov) wrote : Posted in a previous version of this proposal

My previous comments were addressed rather selectively:

1. Still no comment header in the test case.
2. Wrong comments style in sql_insert.cc.
3. Wrong indentation in ha_innodb.cc (spaces instead of tabs).

review: Needs Fixing
Revision history for this message
Alexey Kopytov (akopytov) wrote :

OK to merge.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'Percona-Server/mysql-test/r/percona_innodb_fake_changes_bug_898306.result'
2--- Percona-Server/mysql-test/r/percona_innodb_fake_changes_bug_898306.result 1970-01-01 00:00:00 +0000
3+++ Percona-Server/mysql-test/r/percona_innodb_fake_changes_bug_898306.result 2012-01-17 14:13:06 +0000
4@@ -0,0 +1,40 @@
5+DROP TABLE IF EXISTS t1;
6+CREATE TABLE t1 (a INT primary key, b int, unique key (b)) ENGINE=InnoDB;
7+INSERT INTO t1 VALUES (1,1);
8+SET autocommit=1;
9+SET innodb_fake_changes=1;
10+# Confirm that duplicate key errors on REPLACE works
11+REPLACE INTO t1 VALUES (1,1);
12+ERROR HY000: Got error 131 during COMMIT
13+REPLACE INTO t1 VALUES (1,2);
14+ERROR HY000: Got error 131 during COMMIT
15+# Confirm that duplicate key errors are OK
16+BEGIN;
17+REPLACE INTO t1 VALUES (1,2);
18+SELECT * from t1;
19+a b
20+1 1
21+REPLACE INTO t1 VALUES (1,1);
22+SELECT * from t1;
23+a b
24+1 1
25+ROLLBACK;
26+BEGIN;
27+REPLACE INTO t1 VALUES (2,1);
28+ERROR 23000: Duplicate entry '1' for key 'b'
29+INSERT INTO t1 VALUES (1,1);
30+ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
31+INSERT INTO t1 VALUES (1,2);
32+ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
33+INSERT INTO t1 VALUES (2,1);
34+ERROR 23000: Duplicate entry '1' for key 'b'
35+ROLLBACK;
36+INSERT INTO t1 VALUES (1,1) ON DUPLICATE KEY UPDATE b=b+10;
37+ERROR HY000: Got error 131 during COMMIT
38+INSERT INTO t1 VALUES (1,2) ON DUPLICATE KEY UPDATE b=b+10;
39+ERROR HY000: Got error 131 during COMMIT
40+SET innodb_fake_changes=0;
41+SELECT * from t1;
42+a b
43+1 1
44+DROP TABLE t1;
45
46=== added file 'Percona-Server/mysql-test/t/percona_innodb_fake_changes_bug_898306.test'
47--- Percona-Server/mysql-test/t/percona_innodb_fake_changes_bug_898306.test 1970-01-01 00:00:00 +0000
48+++ Percona-Server/mysql-test/t/percona_innodb_fake_changes_bug_898306.test 2012-01-17 14:13:06 +0000
49@@ -0,0 +1,58 @@
50+# Test case for Bug #898306: innodb_fake_changes doesn't handle duplicate keys on REPLACE
51+# https://bugs.launchpad.net/percona-server/+bug/898306
52+# Test ensures that REPLACE statement behaviour respects innodb_fake_changes feature
53+--source include/have_innodb_plugin.inc
54+
55+--disable_warnings
56+DROP TABLE IF EXISTS t1;
57+--enable_warnings
58+
59+CREATE TABLE t1 (a INT primary key, b int, unique key (b)) ENGINE=InnoDB;
60+INSERT INTO t1 VALUES (1,1);
61+
62+SET autocommit=1;
63+SET innodb_fake_changes=1;
64+
65+--echo # Confirm that duplicate key errors on REPLACE works
66+
67+--error ER_ERROR_DURING_COMMIT
68+REPLACE INTO t1 VALUES (1,1);
69+
70+--error ER_ERROR_DURING_COMMIT
71+REPLACE INTO t1 VALUES (1,2);
72+
73+--echo # Confirm that duplicate key errors are OK
74+
75+BEGIN;
76+REPLACE INTO t1 VALUES (1,2);
77+SELECT * from t1;
78+REPLACE INTO t1 VALUES (1,1);
79+SELECT * from t1;
80+ROLLBACK;
81+
82+BEGIN;
83+
84+--error ER_DUP_ENTRY
85+REPLACE INTO t1 VALUES (2,1);
86+
87+--error ER_DUP_ENTRY
88+INSERT INTO t1 VALUES (1,1);
89+
90+--error ER_DUP_ENTRY
91+INSERT INTO t1 VALUES (1,2);
92+
93+--error ER_DUP_ENTRY
94+INSERT INTO t1 VALUES (2,1);
95+
96+ROLLBACK;
97+
98+--error ER_ERROR_DURING_COMMIT
99+INSERT INTO t1 VALUES (1,1) ON DUPLICATE KEY UPDATE b=b+10;
100+
101+--error ER_ERROR_DURING_COMMIT
102+INSERT INTO t1 VALUES (1,2) ON DUPLICATE KEY UPDATE b=b+10;
103+
104+SET innodb_fake_changes=0;
105+SELECT * from t1;
106+
107+DROP TABLE t1;
108
109=== modified file 'Percona-Server/sql/handler.h'
110--- Percona-Server/sql/handler.h 2011-11-24 02:01:07 +0000
111+++ Percona-Server/sql/handler.h 2012-01-17 14:13:06 +0000
112@@ -1655,6 +1655,12 @@
113
114 void update_global_table_stats();
115 void update_global_index_stats();
116+
117+ /**
118+ Return true when innodb_fake_changes was set for the current transaction
119+ on this handler
120+ */
121+ virtual my_bool is_fake_change_enabled(THD *thd) { return FALSE; }
122
123 #define CHF_CREATE_FLAG 0
124 #define CHF_DELETE_FLAG 1
125
126=== modified file 'Percona-Server/sql/sql_insert.cc'
127--- Percona-Server/sql/sql_insert.cc 2011-11-24 01:59:48 +0000
128+++ Percona-Server/sql/sql_insert.cc 2012-01-17 14:13:06 +0000
129@@ -1579,6 +1579,15 @@
130 trg_error= 1;
131 goto ok_or_after_trg_err;
132 }
133+
134+ /*
135+ Avoid the infinite loop
136+ 1) get dup key on fake insert
137+ 2) do nothing on fake delete
138+ 3) goto #1
139+ */
140+ if (table->file->is_fake_change_enabled(thd))
141+ goto ok_or_after_trg_err;
142 /* Let us attempt do write_row() once more */
143 }
144 }
145
146=== modified file 'Percona-Server/storage/innodb_plugin/handler/ha_innodb.cc'
147--- Percona-Server/storage/innodb_plugin/handler/ha_innodb.cc 2011-11-24 16:33:30 +0000
148+++ Percona-Server/storage/innodb_plugin/handler/ha_innodb.cc 2012-01-17 14:13:06 +0000
149@@ -795,6 +795,12 @@
150 return(*(trx_t**) thd_ha_data(thd, innodb_hton_ptr));
151 }
152
153+my_bool
154+ha_innobase::is_fake_change_enabled(THD* thd)
155+{
156+ trx_t* trx = thd_to_trx(thd);
157+ return (trx && trx->fake_changes);
158+}
159 /********************************************************************//**
160 Call this function when mysqld passes control to the client. That is to
161 avoid deadlocks on the adaptive hash S-latch possibly held by thd. For more
162
163=== modified file 'Percona-Server/storage/innodb_plugin/handler/ha_innodb.h'
164--- Percona-Server/storage/innodb_plugin/handler/ha_innodb.h 2011-11-24 02:00:38 +0000
165+++ Percona-Server/storage/innodb_plugin/handler/ha_innodb.h 2012-01-17 14:13:06 +0000
166@@ -136,6 +136,7 @@
167 int close(void);
168 double scan_time();
169 double read_time(uint index, uint ranges, ha_rows rows);
170+ my_bool is_fake_change_enabled(THD *thd);
171 bool is_corrupt() const;
172
173 int write_row(uchar * buf);

Subscribers

People subscribed via source and target branches