Merge lp:~yan.zhang/codership-mysql/5.5 into lp:codership-mysql/5.5

Proposed by Yan Zhang
Status: Merged
Merged at revision: 4014
Proposed branch: lp:~yan.zhang/codership-mysql/5.5
Merge into: lp:codership-mysql/5.5
Diff against target: 292 lines (+88/-17)
8 files modified
sql/sql_class.h (+1/-0)
sql/sql_parse.cc (+33/-5)
sql/sys_vars.cc (+14/-2)
sql/transaction.cc (+1/-1)
sql/wsrep_mysqld.cc (+6/-4)
sql/wsrep_mysqld.h (+10/-1)
sql/wsrep_var.cc (+21/-3)
sql/wsrep_var.h (+2/-1)
To merge this branch: bzr merge lp:~yan.zhang/codership-mysql/5.5
Reviewer Review Type Date Requested Status
Alex Yurchenko Needs Fixing
Review via email: mp+225727@code.launchpad.net

Description of the change

add wsrep_causal_mask to control optional causal check to auto_commit UPDATE/DELETE.

variable name is not finalized yet, 'wsrep_causal_level' or 'wsrep_synchronous_level' would be fine too. I need your opinion.

To post a comment you must log in.
Revision history for this message
Alex Yurchenko (ayurchen) wrote :

General comment: as we discussed in chat, 'causal' is the bad word here, we definitely want to get rid of it (except for 'wsrep_causal_reads' variable that stays for backward compatibility). We are still undecided whether it should be 'wsrep_synchronous_reads' or 'wsrep_syncronous_wait', but not 'causal' for sure, so it should be gone, both from the option name and from the code.
Not sure that 'mask' should be present in the name as well, it is a type of a variable, not its purpose. You don't say 'wsrep_node_address_string', you just say 'wsrep_node_address'.

review: Needs Fixing
Revision history for this message
Yan Zhang (yan.zhang) wrote :

comment replied. and about new variable name, how about:
1. wsrep_sync_reads (new name for wsrep_causal_reads)
2. wsrep_sync_wait (bitmask).

lp:~yan.zhang/codership-mysql/5.5 updated
4008. By Yan Zhang

References lp:1277053 renaming wsrep_casual_mask to wsrep_sync_wait and some related enums

4009. By Yan Zhang

Merge trunk

Revision history for this message
Alex Yurchenko (ayurchen) wrote :

I think you would agree that it is still not ready

review: Needs Fixing
lp:~yan.zhang/codership-mysql/5.5 updated
4010. By Yan Zhang

References lp:1277053 do some refactor according to review.
1. remove duplicated checks.
2. add optional causal check to autocommit INSERT and REPLACE stmt.
3. rename some related functions.

4011. By Yan Zhang

merge trunk

Revision history for this message
Alex Yurchenko (ayurchen) wrote :

Some minor fixes are still needed.

review: Needs Fixing
lp:~yan.zhang/codership-mysql/5.5 updated
4012. By Yan Zhang

References lp:1277053 remove 'wsrep_sync_wait_by_mask', use 'wsrep_sync_wait' with default parameter value.
change description of 'wsrep_causal_reads'.

Revision history for this message
Yan Zhang (yan.zhang) wrote :
Revision history for this message
Alex Yurchenko (ayurchen) wrote :

some cleanups still needed

Revision history for this message
Alex Yurchenko (ayurchen) wrote :

and I would leave it to compiler to decide about inlining - just give it a chance... WSREP_DEBUG of course is a mean macro, but other than that - this function is going to be called for every request.

Revision history for this message
Yan Zhang (yan.zhang) wrote :

inline this function is little bit tricky.

Because in wsrep_mysqld.h 'struct THD' is forward declared which means we can not access its members. We can put '#include <sql_class.h>' which contains definition of 'struct THD' into wsrep_mysqld.h, but unfortunately there is '#include <wsrep_mysqld.h>' in sql_class.h too which causes cross reference of header files.

so what I plan is to put all inline functions into a separate header file 'wsrep_mysqld_inl.h'. Any compilation unit who needs any inline function in this file could include this header file.

lp:~yan.zhang/codership-mysql/5.5 updated
4013. By Yan Zhang

References lp:1277053 some cleanups. move 'wsrep_sync_wait' to wsrep_mysqld_inl.h for inline

Revision history for this message
Alex Yurchenko (ayurchen) wrote :

1. I'll be damned if that compiles ;) wsrep_mysqld.cc should fail compilation.
2. wsrep_sync_wait is a part of the same interface provided by wsrep integration layer as, e.g. enum_wsrep_sync_wait which is in wsrep_mysqld.h. Why did you decide to put it in a separate header? It would be logical to keep them together. If it is to reduce compilation overhead, then probably it should be named more descriptively.

Revision history for this message
Yan Zhang (yan.zhang) wrote :

1. there are several recent patches(4011,4012,4013) in trunk cause conflict with my branch. My branch just contains the code in trunk up to 4010. Maybe that's why compilation fails. I'll handle that conflict.

2. The mainly reason is header file cross reference. I have to put wsrep_sync_wait into header file(wsrep_mysqld.h) for inline. Since I use some specific fields in 'THD' structure(which is defined sql_class.h) in wsrep_sync_wait, I have to include sql_class.h in wsrep_mysql.h too. But unfortunately sql_class.h already includes wsrep_mysql.h. So wsrep_mysql.h will include sql_class.h, and sql_class.h will include wsrep_mysql.h, that's header file cross reference situation which will make compilation fail.

Although actually we can make it compiles by moving '#include <wsrep_mysqld.h>' in sql_class.h to the position after definition of 'THD' structure, it's just much more ugly.

Revision history for this message
Alex Yurchenko (ayurchen) wrote :

1. Just look at the patch. There are merge artifacts.
2. You're right, this is quite ugly. Sorry for pushing you into that. I think this moving of wsrep_sync_wait() definition to header file was not a good idea after all.

I'll leave it for you to decide what to do about it and merge to trunk. All the principal issues have been resolved IMO.

lp:~yan.zhang/codership-mysql/5.5 updated
4014. By Yan Zhang

References lp:1277053 cancel inlining function 'wsrep_sync_wait'

Revision history for this message
Yan Zhang (yan.zhang) wrote :

OK. I'd like not to inline 'wsrep_sync_wait' function atm, and put definition of it back to 'wsrep_mysqld.cc'

lp:~yan.zhang/codership-mysql/5.5 updated
4015. By Yan Zhang

merge trunk to r4013

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'sql/sql_class.h'
2--- sql/sql_class.h 2014-04-28 16:57:30 +0000
3+++ sql/sql_class.h 2014-08-12 03:33:55 +0000
4@@ -520,6 +520,7 @@
5 #ifdef WITH_WSREP
6 my_bool wsrep_on;
7 my_bool wsrep_causal_reads;
8+ uint wsrep_sync_wait;
9 ulong wsrep_retry_autocommit;
10 #endif
11 double long_query_time_double;
12
13=== modified file 'sql/sql_parse.cc'
14--- sql/sql_parse.cc 2014-07-30 21:09:47 +0000
15+++ sql/sql_parse.cc 2014-08-12 03:33:55 +0000
16@@ -2393,7 +2393,7 @@
17 case SQLCOM_SHOW_STATUS_PROC:
18 case SQLCOM_SHOW_STATUS_FUNC:
19 #ifdef WITH_WSREP
20- if (WSREP_CLIENT(thd) && wsrep_causal_wait(thd)) goto error;
21+ if (WSREP_CLIENT(thd) && wsrep_sync_wait(thd)) goto error;
22 #endif /* WITH_WSREP */
23 if ((res= check_table_access(thd, SELECT_ACL, all_tables, FALSE,
24 UINT_MAX, FALSE)))
25@@ -2405,7 +2405,7 @@
26 system_status_var old_status_var= thd->status_var;
27 thd->initial_status_var= &old_status_var;
28 #ifdef WITH_WSREP
29- if (WSREP_CLIENT(thd) && wsrep_causal_wait(thd)) goto error;
30+ if (WSREP_CLIENT(thd) && wsrep_sync_wait(thd)) goto error;
31 #endif /* WITH_WSREP */
32 if (!(res= check_table_access(thd, SELECT_ACL, all_tables, FALSE,
33 UINT_MAX, FALSE)))
34@@ -2444,7 +2444,7 @@
35 #endif /* WITH_WSREP */
36 case SQLCOM_SELECT:
37 #ifdef WITH_WSREP
38- if (WSREP_CLIENT(thd) && wsrep_causal_wait(thd)) goto error;
39+ if (WSREP_CLIENT(thd) && wsrep_sync_wait(thd)) goto error;
40 case SQLCOM_SHOW_VARIABLES:
41 case SQLCOM_SHOW_CHARSETS:
42 case SQLCOM_SHOW_COLLATIONS:
43@@ -3035,7 +3035,7 @@
44 #else
45 {
46 #ifdef WITH_WSREP
47- if (WSREP_CLIENT(thd) && wsrep_causal_wait(thd)) goto error;
48+ if (WSREP_CLIENT(thd) && wsrep_sync_wait(thd)) goto error;
49 #endif /* WITH_WSREP */
50
51 /*
52@@ -3094,7 +3094,7 @@
53 {
54 DBUG_ASSERT(first_table == all_tables && first_table != 0);
55 #ifdef WITH_WSREP
56- if (WSREP_CLIENT(thd) && wsrep_causal_wait(thd)) goto error;
57+ if (WSREP_CLIENT(thd) && wsrep_sync_wait(thd)) goto error;
58 #endif /* WITH_WSREP */
59
60 if (check_table_access(thd, SELECT_ACL, all_tables,
61@@ -3105,6 +3105,10 @@
62 break;
63 }
64 case SQLCOM_UPDATE:
65+#ifdef WITH_WSREP
66+ if (WSREP_CLIENT(thd) &&
67+ wsrep_sync_wait(thd, WSREP_SYNC_WAIT_BEFORE_UPDATE_DELETE)) goto error;
68+#endif /* WITH_WSREP */
69 {
70 ha_rows found= 0, updated= 0;
71 DBUG_ASSERT(first_table == all_tables && first_table != 0);
72@@ -3144,6 +3148,10 @@
73 /* if we switched from normal update, rights are checked */
74 if (up_result != 2)
75 {
76+#ifdef WITH_WSREP
77+ if (WSREP_CLIENT(thd) &&
78+ wsrep_sync_wait(thd, WSREP_SYNC_WAIT_BEFORE_UPDATE_DELETE)) goto error;
79+#endif /* WITH_WSREP */
80 if ((res= multi_update_precheck(thd, all_tables)))
81 break;
82 }
83@@ -3213,6 +3221,10 @@
84 break;
85 }
86 case SQLCOM_REPLACE:
87+#ifdef WITH_WSREP
88+ if (WSREP_CLIENT(thd) &&
89+ wsrep_sync_wait(thd, WSREP_SYNC_WAIT_BEFORE_INSERT_REPLACE)) goto error;
90+#endif /* WITH_WSREP */
91 #ifndef DBUG_OFF
92 if (mysql_bin_log.is_open())
93 {
94@@ -3248,6 +3260,10 @@
95 }
96 #endif
97 case SQLCOM_INSERT:
98+#ifdef WITH_WSREP
99+ if (WSREP_CLIENT(thd) &&
100+ wsrep_sync_wait(thd, WSREP_SYNC_WAIT_BEFORE_INSERT_REPLACE)) goto error;
101+#endif /* WITH_WSREP */
102 {
103 DBUG_ASSERT(first_table == all_tables && first_table != 0);
104 if ((res= insert_precheck(thd, all_tables)))
105@@ -3281,6 +3297,10 @@
106 }
107 case SQLCOM_REPLACE_SELECT:
108 case SQLCOM_INSERT_SELECT:
109+#ifdef WITH_WSREP
110+ if (WSREP_CLIENT(thd) &&
111+ wsrep_sync_wait(thd, WSREP_SYNC_WAIT_BEFORE_INSERT_REPLACE)) goto error;
112+#endif /* WITH_WSREP */
113 {
114 select_result *sel_result;
115 DBUG_ASSERT(first_table == all_tables && first_table != 0);
116@@ -3373,6 +3393,10 @@
117 break;
118 }
119 case SQLCOM_DELETE:
120+#ifdef WITH_WSREP
121+ if (WSREP_CLIENT(thd) &&
122+ wsrep_sync_wait(thd, WSREP_SYNC_WAIT_BEFORE_UPDATE_DELETE)) goto error;
123+#endif /* WITH_WSREP */
124 {
125 DBUG_ASSERT(first_table == all_tables && first_table != 0);
126 if ((res= delete_precheck(thd, all_tables)))
127@@ -3388,6 +3412,10 @@
128 break;
129 }
130 case SQLCOM_DELETE_MULTI:
131+#ifdef WITH_WSREP
132+ if (WSREP_CLIENT(thd) &&
133+ wsrep_sync_wait(thd, WSREP_SYNC_WAIT_BEFORE_UPDATE_DELETE)) goto error;
134+#endif /* WITH_WSREP */
135 {
136 DBUG_ASSERT(first_table == all_tables && first_table != 0);
137 TABLE_LIST *aux_tables= thd->lex->auxiliary_table_list.first;
138
139=== modified file 'sql/sys_vars.cc'
140--- sql/sys_vars.cc 2014-06-19 09:19:53 +0000
141+++ sql/sys_vars.cc 2014-08-12 03:33:55 +0000
142@@ -3465,9 +3465,21 @@
143 CMD_LINE(OPT_ARG), DEFAULT(TRUE));
144
145 static Sys_var_mybool Sys_wsrep_causal_reads(
146- "wsrep_causal_reads", "Enable \"strictly synchronous\" semantics for read operations",
147+ "wsrep_causal_reads", "(DEPRECATED) setting this variable is equivalent to setting wsrep_sync_wait READ flag",
148 SESSION_VAR(wsrep_causal_reads),
149- CMD_LINE(OPT_ARG), DEFAULT(FALSE));
150+ CMD_LINE(OPT_ARG), DEFAULT(FALSE),
151+ NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
152+ ON_UPDATE(wsrep_causal_reads_update));
153+
154+static Sys_var_uint Sys_wsrep_sync_wait(
155+ "wsrep_sync_wait", "Ensure \"synchronous\" read view before executing an operation of the type specified by bitmask: 1 - READ(includes SELECT, SHOW and BEGIN/START TRANSACTION); 2 - UPDATE and DELETE; 4 - INSERT and REPLACE",
156+ SESSION_VAR(wsrep_sync_wait),
157+ CMD_LINE(OPT_ARG),
158+ VALID_RANGE(WSREP_SYNC_WAIT_NONE, WSREP_SYNC_WAIT_MAX),
159+ DEFAULT(WSREP_SYNC_WAIT_NONE),
160+ BLOCK_SIZE(1),
161+ NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
162+ ON_UPDATE(wsrep_sync_wait_update));
163
164 static const char *wsrep_OSU_method_names[]= { "TOI", "RSU", NullS };
165 static Sys_var_enum Sys_wsrep_OSU_method(
166
167=== modified file 'sql/transaction.cc'
168--- sql/transaction.cc 2013-10-27 11:22:28 +0000
169+++ sql/transaction.cc 2014-08-12 03:33:55 +0000
170@@ -161,7 +161,7 @@
171
172 #ifdef WITH_WSREP
173 thd->wsrep_PA_safe= true;
174- if (WSREP_CLIENT(thd) && wsrep_causal_wait(thd))
175+ if (WSREP_CLIENT(thd) && wsrep_sync_wait(thd))
176 DBUG_RETURN(TRUE);
177 #endif /* WITH_WSREP */
178
179
180=== modified file 'sql/wsrep_mysqld.cc'
181--- sql/wsrep_mysqld.cc 2014-07-31 12:59:23 +0000
182+++ sql/wsrep_mysqld.cc 2014-08-12 03:33:55 +0000
183@@ -847,13 +847,15 @@
184 return true;
185 }
186
187-bool
188-wsrep_causal_wait (THD* thd)
189+bool wsrep_sync_wait (THD* thd, uint mask)
190 {
191- if (thd->variables.wsrep_causal_reads && thd->variables.wsrep_on &&
192+ if ((thd->variables.wsrep_sync_wait & mask) &&
193+ thd->variables.wsrep_on &&
194 !thd->in_active_multi_stmt_transaction() &&
195 thd->wsrep_conflict_state != REPLAYING)
196 {
197+ WSREP_DEBUG("wsrep_sync_wait: thd->variables.wsrep_sync_wait = %u, mask = %u",
198+ thd->variables.wsrep_sync_wait, mask);
199 // This allows autocommit SELECTs and a first SELECT after SET AUTOCOMMIT=0
200 // TODO: modify to check if thd has locked any rows.
201 wsrep_gtid_t gtid;
202@@ -877,7 +879,7 @@
203 err= ER_NOT_SUPPORTED_YET;
204 break;
205 default:
206- msg= "Causal wait failed.";
207+ msg= "Synchronous wait failed.";
208 err= ER_LOCK_WAIT_TIMEOUT; // NOTE: the above msg won't be displayed
209 // with ER_LOCK_WAIT_TIMEOUT
210 }
211
212=== modified file 'sql/wsrep_mysqld.h'
213--- sql/wsrep_mysqld.h 2014-06-19 09:19:53 +0000
214+++ sql/wsrep_mysqld.h 2014-08-12 03:33:55 +0000
215@@ -101,6 +101,14 @@
216 extern my_bool wsrep_slave_UK_checks;
217
218 enum enum_wsrep_OSU_method { WSREP_OSU_TOI, WSREP_OSU_RSU };
219+enum enum_wsrep_sync_wait {
220+ WSREP_SYNC_WAIT_NONE = 0x0,
221+ // show, select, begin
222+ WSREP_SYNC_WAIT_BEFORE_READ = 0x1,
223+ WSREP_SYNC_WAIT_BEFORE_UPDATE_DELETE = 0x2,
224+ WSREP_SYNC_WAIT_BEFORE_INSERT_REPLACE = 0x4,
225+ WSREP_SYNC_WAIT_MAX = 0x7
226+};
227
228 // MySQL status variables
229 extern my_bool wsrep_connected;
230@@ -171,9 +179,10 @@
231 /* new defines */
232 extern void wsrep_stop_replication(THD *thd);
233 extern bool wsrep_start_replication();
234-extern bool wsrep_causal_wait(THD* thd);
235+extern bool wsrep_sync_wait (THD* thd, uint mask = WSREP_SYNC_WAIT_BEFORE_READ);
236 extern int wsrep_check_opts (int argc, char* const* argv);
237 extern void wsrep_prepend_PATH (const char* path);
238+/* some inline functions are defined in wsrep_mysqld_inl.h */
239
240 /* Other global variables */
241 extern wsrep_seqno_t wsrep_locked_seqno;
242
243=== modified file 'sql/wsrep_var.cc'
244--- sql/wsrep_var.cc 2014-01-07 21:49:58 +0000
245+++ sql/wsrep_var.cc 2014-08-12 03:33:55 +0000
246@@ -63,11 +63,29 @@
247 return false;
248 }
249
250-void wsrep_causal_reads_update (sys_var *self, THD* thd, enum_var_type var_type)
251+bool wsrep_causal_reads_update (sys_var *self, THD* thd, enum_var_type var_type)
252 {
253- if (var_type == OPT_GLOBAL) {
254- thd->variables.wsrep_causal_reads = global_system_variables.wsrep_causal_reads;
255+ // global setting should not affect session setting.
256+ // if (var_type == OPT_GLOBAL) {
257+ // thd->variables.wsrep_causal_reads = global_system_variables.wsrep_causal_reads;
258+ // }
259+ if (thd->variables.wsrep_causal_reads) {
260+ thd->variables.wsrep_sync_wait |= WSREP_SYNC_WAIT_BEFORE_READ;
261+ } else {
262+ thd->variables.wsrep_sync_wait &= ~WSREP_SYNC_WAIT_BEFORE_READ;
263 }
264+ return false;
265+}
266+
267+bool wsrep_sync_wait_update (sys_var* self, THD* thd, enum_var_type var_type)
268+{
269+ // global setting should not affect session setting.
270+ // if (var_type == OPT_GLOBAL) {
271+ // thd->variables.wsrep_sync_wait = global_system_variables.wsrep_sync_wait;
272+ // }
273+ thd->variables.wsrep_causal_reads = thd->variables.wsrep_sync_wait &
274+ WSREP_SYNC_WAIT_BEFORE_READ;
275+ return false;
276 }
277
278 static int wsrep_start_position_verify (const char* start_str)
279
280=== modified file 'sql/wsrep_var.h'
281--- sql/wsrep_var.h 2013-10-11 16:03:06 +0000
282+++ sql/wsrep_var.h 2014-08-12 03:33:55 +0000
283@@ -33,7 +33,8 @@
284 #define INIT_ARGS (const char* opt)
285
286 extern bool wsrep_on_update UPDATE_ARGS;
287-extern void wsrep_causal_reads_update UPDATE_ARGS;
288+extern bool wsrep_causal_reads_update UPDATE_ARGS;
289+extern bool wsrep_sync_wait_update UPDATE_ARGS;
290 extern bool wsrep_start_position_check CHECK_ARGS;
291 extern bool wsrep_start_position_update UPDATE_ARGS;
292 extern void wsrep_start_position_init INIT_ARGS;

Subscribers

People subscribed via source and target branches

to all changes: