Merge lp:~stewart/drizzle/bug682563-commit-all-not-true into lp:drizzle/7.0

Proposed by Stewart Smith
Status: Merged
Approved by: Lee Bieber
Approved revision: 2073
Merged at revision: 2101
Proposed branch: lp:~stewart/drizzle/bug682563-commit-all-not-true
Merge into: lp:drizzle/7.0
Diff against target: 451 lines (+359/-10)
7 files modified
drizzled/transaction_services.cc (+9/-2)
plugin/haildb/haildb_engine.cc (+1/-1)
plugin/innobase/handler/ha_innodb.cc (+2/-3)
plugin/pbxt/src/ha_pbxt.cc (+1/-3)
plugin/storage_engine_api_tester/storage_engine_api_tester.cc (+1/-1)
tests/suite/regression/r/682563.result (+159/-0)
tests/suite/regression/t/682563.test (+186/-0)
To merge this branch: bzr merge lp:~stewart/drizzle/bug682563-commit-all-not-true
Reviewer Review Type Date Requested Status
Drizzle Developers Pending
Review via email: mp+45851@code.launchpad.net

Description of the change

TransactionalStorageEngine::doCommit(Session*, bool all) the all was a lie, engines had to check for autocommit and other ick.

This patch fixes that so that you can have a much simpler check in the engine, not having to poke into session flags.

http://hudson.drizzle.org/view/Drizzle-param/job/drizzle-param/703/

To post a comment you must log in.
Revision history for this message
Brian Aker (brianaker) wrote :

Test case?

Revision history for this message
Stewart Smith (stewart) wrote :

I'm working on[1] adapting storage_engine_api_tester to record a history of states so that we can check the right thing is still being called. A simple test-run test will then be able to ensure that the right thing is being called at the right time.

[1] will type 'commit' today

Revision history for this message
Stewart Smith (stewart) wrote :

https://code.launchpad.net/~stewart/drizzle/seapitester-state-history/+merge/46092

implements it. when this branch is merged with that one, the test results don't change - as in, the correct thing is still being called at the correct time.

Revision history for this message
Brian Aker (brianaker) wrote :

As we talked about in IRC, we need a set of SQL tests to make sure this is correct.

Revision history for this message
Brian Aker (brianaker) wrote :

You need to supply SQL regression tests for this patch.

Revision history for this message
Patrick Crews (patrick-crews) wrote :

Running the test suite and checking lcov numbers shows that the affected lines of code are exercised by the test suite. Did not check changes to pbxt or haildb code as this is supposed to be a cursory check.

Test cases appear satisfactory.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'drizzled/transaction_services.cc'
2--- drizzled/transaction_services.cc 2011-01-13 18:43:55 +0000
3+++ drizzled/transaction_services.cc 2011-01-17 01:31:15 +0000
4@@ -576,6 +576,13 @@
5 TransactionContext::ResourceContexts &resource_contexts= trans->getResourceContexts();
6
7 bool is_real_trans= normal_transaction || session->transaction.all.getResourceContexts().empty();
8+ bool all= normal_transaction;
9+
10+ /* If we're in autocommit then we have a real transaction to commit
11+ (except if it's BEGIN)
12+ */
13+ if (! session_test_options(session, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
14+ all= true;
15
16 if (resource_contexts.empty() == false)
17 {
18@@ -590,7 +597,7 @@
19
20 if (resource->participatesInXaTransaction())
21 {
22- if ((err= resource_context->getXaResourceManager()->xaCommit(session, normal_transaction)))
23+ if ((err= resource_context->getXaResourceManager()->xaCommit(session, all)))
24 {
25 my_error(ER_ERROR_DURING_COMMIT, MYF(0), err);
26 error= 1;
27@@ -602,7 +609,7 @@
28 }
29 else if (resource->participatesInSqlTransaction())
30 {
31- if ((err= resource_context->getTransactionalStorageEngine()->commit(session, normal_transaction)))
32+ if ((err= resource_context->getTransactionalStorageEngine()->commit(session, all)))
33 {
34 my_error(ER_ERROR_DURING_COMMIT, MYF(0), err);
35 error= 1;
36
37=== modified file 'plugin/haildb/haildb_engine.cc'
38--- plugin/haildb/haildb_engine.cc 2011-01-10 09:41:44 +0000
39+++ plugin/haildb/haildb_engine.cc 2011-01-17 01:31:15 +0000
40@@ -409,7 +409,7 @@
41 ib_err_t err;
42 ib_trx_t *transaction= get_trx(session);
43
44- if (all || (!session_test_options(session, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
45+ if (all)
46 {
47 err= ib_trx_commit(*transaction);
48
49
50=== modified file 'plugin/innobase/handler/ha_innodb.cc'
51--- plugin/innobase/handler/ha_innodb.cc 2011-01-15 07:04:48 +0000
52+++ plugin/innobase/handler/ha_innodb.cc 2011-01-17 01:31:15 +0000
53@@ -2571,9 +2571,8 @@
54 trx_search_latch_release_if_reserved(trx);
55 }
56
57- if (all
58- || (!session_test_options(session, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) {
59-
60+ if (all)
61+ {
62 /* We were instructed to commit the whole transaction, or
63 this is an SQL statement end and autocommit is on */
64
65
66=== modified file 'plugin/pbxt/src/ha_pbxt.cc'
67--- plugin/pbxt/src/ha_pbxt.cc 2010-12-24 07:15:43 +0000
68+++ plugin/pbxt/src/ha_pbxt.cc 2011-01-17 01:31:15 +0000
69@@ -5723,13 +5723,11 @@
70 return xt_ha_pbxt_thread_error_for_mysql(thd, xt_ha_thd_to_self(thd), false);
71 }
72
73-int PBXTStorageEngine::doCommit(drizzled::Session* thd, bool)
74+int PBXTStorageEngine::doCommit(drizzled::Session* thd, bool real_commit)
75 {
76 int err = 0;
77 XTThreadPtr self = (XTThreadPtr) *thd->getEngineData(pbxt_hton);
78
79- bool real_commit = !session_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN);
80-
81 XT_PRINT1(self, "PBXTStorageEngine::doCommit(real_commit = %s)\n", real_commit ? "true" : "false");
82
83 if (real_commit && self) {
84
85=== modified file 'plugin/storage_engine_api_tester/storage_engine_api_tester.cc'
86--- plugin/storage_engine_api_tester/storage_engine_api_tester.cc 2011-01-13 05:06:12 +0000
87+++ plugin/storage_engine_api_tester/storage_engine_api_tester.cc 2011-01-17 01:31:15 +0000
88@@ -490,7 +490,7 @@
89
90 int SEAPITester::doCommit(Session *session, bool all)
91 {
92- if (all || (!session_test_options(session, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
93+ if (all)
94 {
95 ENGINE_NEW_STATE("COMMIT");
96 ENGINE_NEW_STATE("::SEAPITester()");
97
98=== added file 'tests/suite/regression/r/682563.result'
99--- tests/suite/regression/r/682563.result 1970-01-01 00:00:00 +0000
100+++ tests/suite/regression/r/682563.result 2011-01-17 01:31:15 +0000
101@@ -0,0 +1,159 @@
102+A
103+CREATE TABLE t1 (a int);
104+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
105+BEGIN;
106+INSERT INTO t1 values (1);
107+B
108+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
109+BEGIN;
110+SELECT * from t1;
111+a
112+A
113+INSERT INTO t1 values (2);
114+B
115+SELECT * from t1;
116+a
117+COMMIT;
118+BEGIN;
119+SELECT * FROM t1;
120+a
121+A
122+COMMIT;
123+B
124+SELECT * from t1 order by a;
125+a
126+1
127+2
128+COMMIT;
129+BEGIN;
130+SELECT * from t1 order by a;
131+a
132+1
133+2
134+DROP TABLE t1;
135+SET AUTOCOMMIT= 0;
136+SHOW STATUS LIKE 'Handler_commit%';
137+Variable_name Value
138+Handler_commit 0
139+BEGIN;
140+SHOW STATUS LIKE 'Handler_commit%';
141+Variable_name Value
142+Handler_commit 0
143+DROP SCHEMA IF EXISTS boundaries;
144+Warnings:
145+Note 1008 Can't drop schema 'boundaries'; schema doesn't exist
146+SHOW STATUS LIKE 'Handler_commit%';
147+Variable_name Value
148+Handler_commit 1
149+COMMIT;
150+SHOW STATUS LIKE 'Handler_commit%';
151+Variable_name Value
152+Handler_commit 1
153+SET AUTOCOMMIT= 1;
154+SHOW STATUS LIKE 'Handler_commit%';
155+Variable_name Value
156+Handler_commit 1
157+BEGIN;
158+DROP SCHEMA IF EXISTS boundaries;
159+Warnings:
160+Note 1008 Can't drop schema 'boundaries'; schema doesn't exist
161+COMMIT;
162+SHOW STATUS LIKE 'Handler_commit%';
163+Variable_name Value
164+Handler_commit 2
165+CREATE TABLE commit_test (a int);
166+SHOW STATUS LIKE 'Handler_commit%';
167+Variable_name Value
168+Handler_commit 2
169+INSERT into commit_test VALUES (10);
170+SHOW STATUS LIKE 'Handler_commit%';
171+Variable_name Value
172+Handler_commit 2
173+INSERT into commit_test VALUES (10), (20);
174+SHOW STATUS LIKE 'Handler_commit%';
175+Variable_name Value
176+Handler_commit 2
177+INSERT into commit_test VALUES (10);
178+SHOW STATUS LIKE 'Handler_commit%';
179+Variable_name Value
180+Handler_commit 2
181+BEGIN;
182+INSERT into commit_test VALUES (10);
183+SHOW STATUS LIKE 'Handler_commit%';
184+Variable_name Value
185+Handler_commit 2
186+COMMIT;
187+SHOW STATUS LIKE 'Handler_commit%';
188+Variable_name Value
189+Handler_commit 3
190+BEGIN;
191+INSERT into commit_test VALUES (10);
192+SHOW STATUS LIKE 'Handler_commit%';
193+Variable_name Value
194+Handler_commit 3
195+ROLLBACK;
196+SHOW STATUS LIKE 'Handler_commit%';
197+Variable_name Value
198+Handler_commit 3
199+BEGIN;
200+INSERT into commit_test VALUES (10);
201+SHOW STATUS LIKE 'Handler_commit%';
202+Variable_name Value
203+Handler_commit 3
204+COMMIT;
205+SHOW STATUS LIKE 'Handler_commit%';
206+Variable_name Value
207+Handler_commit 4
208+SET AUTOCOMMIT= 0;
209+INSERT into commit_test VALUES (10);
210+INSERT into commit_test VALUES (10);
211+SHOW STATUS LIKE 'Handler_commit%';
212+Variable_name Value
213+Handler_commit 4
214+drop table commit_test;
215+SHOW STATUS LIKE 'Handler_commit%';
216+Variable_name Value
217+Handler_commit 5
218+DROP TABLE IF EXISTS t1_trx, t1_non_trx;
219+SET AUTOCOMMIT= 0;
220+CREATE TABLE t1_trx (
221+k VARCHAR(10) NOT NULL
222+, v VARCHAR(10) NOT NULL
223+, PRIMARY KEY (k)
224+) ENGINE=InnoDB;
225+CREATE TEMPORARY TABLE t1_non_trx (
226+k VARCHAR(10) NOT NULL
227+, v VARCHAR(10) NOT NULL
228+, PRIMARY KEY (k)
229+) ENGINE=MyISAM;
230+START TRANSACTION;
231+INSERT INTO t1_trx VALUES ('key1','value1');
232+INSERT INTO t1_trx VALUES ('key2','value2');
233+INSERT INTO t1_non_trx VALUES ('key1','value1');
234+INSERT INTO t1_non_trx VALUES ('key2','value2');
235+ROLLBACK;
236+Warnings:
237+Warning 1196 Some non-transactional changed tables couldn't be rolled back
238+Expected warning about non-trx data changes not being rolled back
239+SELECT * FROM t1_trx;
240+k v
241+SELECT * FROM t1_non_trx;
242+k v
243+key1 value1
244+key2 value2
245+START TRANSACTION;
246+INSERT INTO t1_trx VALUES ('key1','value1');
247+INSERT INTO t1_trx VALUES ('key2','value2');
248+SELECT t1_trx.k, t1_trx.v
249+FROM t1_trx
250+INNER JOIN t1_non_trx ON t1_trx.k = t1_non_trx.k;
251+k v
252+key1 value1
253+key2 value2
254+ROLLBACK;
255+SELECT t1_trx.k, t1_trx.v
256+FROM t1_trx
257+INNER JOIN t1_non_trx ON t1_trx.k = t1_non_trx.k;
258+k v
259+DROP TABLE t1_trx;
260+DROP TABLE t1_non_trx;
261
262=== added file 'tests/suite/regression/t/682563.test'
263--- tests/suite/regression/t/682563.test 1970-01-01 00:00:00 +0000
264+++ tests/suite/regression/t/682563.test 2011-01-17 01:31:15 +0000
265@@ -0,0 +1,186 @@
266+connect (a,localhost,root,,);
267+connect (b,localhost,root,,);
268+
269+connection a;
270+--echo A
271+CREATE TABLE t1 (a int);
272+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
273+BEGIN;
274+INSERT INTO t1 values (1);
275+
276+connection b;
277+--echo B
278+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
279+BEGIN;
280+SELECT * from t1;
281+
282+connection a;
283+--echo A
284+INSERT INTO t1 values (2);
285+
286+connection b;
287+--echo B
288+SELECT * from t1;
289+COMMIT;
290+BEGIN;
291+SELECT * FROM t1;
292+
293+connection a;
294+--echo A
295+COMMIT;
296+
297+connection b;
298+--echo B
299+SELECT * from t1 order by a;
300+COMMIT;
301+BEGIN;
302+SELECT * from t1 order by a;
303+
304+DROP TABLE t1;
305+
306+disconnect a;
307+disconnect b;
308+connection default;
309+# This is a test of various SQL statements
310+# and looks at the statement and transaction
311+# boundaries (start/end) to ensure they are sane
312+
313+SET AUTOCOMMIT= 0;
314+
315+# Expect 0 commit count since nothing
316+# has yet happened...
317+
318+SHOW STATUS LIKE 'Handler_commit%';
319+
320+BEGIN;
321+
322+# Expect 0 commit count since nothing
323+# has yet been committed...
324+
325+SHOW STATUS LIKE 'Handler_commit%';
326+
327+DROP SCHEMA IF EXISTS boundaries;
328+
329+# Expect 1 commit count since above DROP SCHEMA
330+# will implicitly call COMMIT.
331+#
332+# When we get transactional DDL, should be 0.
333+SHOW STATUS LIKE 'Handler_commit%';
334+
335+COMMIT;
336+
337+# Expect 1 commit count since
338+# an explicit call to COMMIT was made
339+# even though nothing was changed...
340+
341+SHOW STATUS LIKE 'Handler_commit%';
342+
343+
344+## Enable AUOTOCOMMIT
345+#
346+SET AUTOCOMMIT= 1;
347+
348+SHOW STATUS LIKE 'Handler_commit%';
349+BEGIN;
350+DROP SCHEMA IF EXISTS boundaries;
351+COMMIT;
352+
353+SHOW STATUS LIKE 'Handler_commit%';
354+CREATE TABLE commit_test (a int);
355+SHOW STATUS LIKE 'Handler_commit%';
356+INSERT into commit_test VALUES (10);
357+SHOW STATUS LIKE 'Handler_commit%';
358+INSERT into commit_test VALUES (10), (20);
359+SHOW STATUS LIKE 'Handler_commit%';
360+INSERT into commit_test VALUES (10);
361+SHOW STATUS LIKE 'Handler_commit%';
362+
363+BEGIN;
364+
365+INSERT into commit_test VALUES (10);
366+SHOW STATUS LIKE 'Handler_commit%';
367+
368+COMMIT;
369+
370+SHOW STATUS LIKE 'Handler_commit%';
371+BEGIN;
372+
373+INSERT into commit_test VALUES (10);
374+SHOW STATUS LIKE 'Handler_commit%';
375+
376+ROLLBACK;
377+
378+SHOW STATUS LIKE 'Handler_commit%';
379+BEGIN;
380+
381+
382+INSERT into commit_test VALUES (10);
383+SHOW STATUS LIKE 'Handler_commit%';
384+
385+COMMIT;
386+SHOW STATUS LIKE 'Handler_commit%';
387+
388+SET AUTOCOMMIT= 0;
389+INSERT into commit_test VALUES (10);
390+INSERT into commit_test VALUES (10);
391+
392+
393+SHOW STATUS LIKE 'Handler_commit%';
394+drop table commit_test;
395+SHOW STATUS LIKE 'Handler_commit%';
396+# Tests a number of things related to transactions:
397+#
398+# 1. Interaction of more than one engine in a transaction
399+# 2. Correct commit and rollback behaviour
400+# 3. XA protocol communication and recovery
401+
402+--disable_warnings
403+DROP TABLE IF EXISTS t1_trx, t1_non_trx;
404+--enable_warnings
405+
406+SET AUTOCOMMIT= 0;
407+
408+CREATE TABLE t1_trx (
409+ k VARCHAR(10) NOT NULL
410+, v VARCHAR(10) NOT NULL
411+, PRIMARY KEY (k)
412+) ENGINE=InnoDB;
413+
414+CREATE TEMPORARY TABLE t1_non_trx (
415+ k VARCHAR(10) NOT NULL
416+, v VARCHAR(10) NOT NULL
417+, PRIMARY KEY (k)
418+) ENGINE=MyISAM;
419+
420+START TRANSACTION;
421+
422+INSERT INTO t1_trx VALUES ('key1','value1');
423+INSERT INTO t1_trx VALUES ('key2','value2');
424+
425+INSERT INTO t1_non_trx VALUES ('key1','value1');
426+INSERT INTO t1_non_trx VALUES ('key2','value2');
427+
428+ROLLBACK;
429+
430+--echo Expected warning about non-trx data changes not being rolled back
431+
432+SELECT * FROM t1_trx;
433+SELECT * FROM t1_non_trx;
434+
435+START TRANSACTION;
436+
437+INSERT INTO t1_trx VALUES ('key1','value1');
438+INSERT INTO t1_trx VALUES ('key2','value2');
439+
440+SELECT t1_trx.k, t1_trx.v
441+FROM t1_trx
442+INNER JOIN t1_non_trx ON t1_trx.k = t1_non_trx.k;
443+
444+ROLLBACK;
445+
446+SELECT t1_trx.k, t1_trx.v
447+FROM t1_trx
448+INNER JOIN t1_non_trx ON t1_trx.k = t1_non_trx.k;
449+
450+DROP TABLE t1_trx;
451+DROP TABLE t1_non_trx;

Subscribers

People subscribed via source and target branches