You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

433 lines
12 KiB

Bug#53445: Build with -Wall and fix warnings that it generates Fix various mismatches between function's language linkage. Any particular function that is declared in C++ but should be callable from C must have C linkage. Note that function types with different linkages are also distinct. Thus, if a function type is declared in C code, it will have C linkage (same if declared in a extern "C" block). client/mysql.cc: Mismatch between prototype and declaration. client/mysqltest.cc: mysqltest used to be C code. Use C linkage where appropriate. cmd-line-utils/readline/input.c: Isolate unreachable code. include/my_alloc.h: Function type must have C linkage. include/my_base.h: Function type must have C linkage. include/my_global.h: Add helper macros to avoid spurious namespace indentation. include/mysql.h.pp: Update ABI file. mysys/my_gethwaddr.c: Remove stray carriage return and fix coding style. plugin/semisync/semisync_master_plugin.cc: Callback function types have C linkage. plugin/semisync/semisync_slave_plugin.cc: Callback function types have C linkage. sql/derror.cc: Expected function type has C linkage. sql/field.cc: Use helper macro and fix indentation. sql/handler.cc: Expected function type has C linkage. sql/item_sum.cc: Correct function linkages. Remove now unnecessary cast. sql/item_sum.h: Add prototypes with the appropriate linkage as otherwise they are distinct. sql/mysqld.cc: Wrap functions in C linkage mode. sql/opt_range.cc: C language linkage is ignored for class member functions. sql/partition_info.cc: Add wrapper functions with C linkage for class member functions. sql/rpl_utility.h: Use helper macro and fix indentation. sql/sql_class.cc: Change type of thd argument -- THD is a class. Use helper macro and fix indentation. sql/sql_class.h: Change type of thd argument -- THD is a class. sql/sql_select.cc: Expected function type has C linkage. sql/sql_select.h: Move prototype to sql_test.h sql/sql_show.cc: Expected function type has C linkage. sql/sql_test.cc: Fix required function prototype and fix coding style. sql/sql_test.h: Removed unnecessary export and add another. storage/myisammrg/ha_myisammrg.cc: Expected function type has C linkage. storage/perfschema/pfs.cc: PSI headers are declared with C language linkage, which also applies to function types.
16 years ago
Bug#53445: Build with -Wall and fix warnings that it generates Fix various mismatches between function's language linkage. Any particular function that is declared in C++ but should be callable from C must have C linkage. Note that function types with different linkages are also distinct. Thus, if a function type is declared in C code, it will have C linkage (same if declared in a extern "C" block). client/mysql.cc: Mismatch between prototype and declaration. client/mysqltest.cc: mysqltest used to be C code. Use C linkage where appropriate. cmd-line-utils/readline/input.c: Isolate unreachable code. include/my_alloc.h: Function type must have C linkage. include/my_base.h: Function type must have C linkage. include/my_global.h: Add helper macros to avoid spurious namespace indentation. include/mysql.h.pp: Update ABI file. mysys/my_gethwaddr.c: Remove stray carriage return and fix coding style. plugin/semisync/semisync_master_plugin.cc: Callback function types have C linkage. plugin/semisync/semisync_slave_plugin.cc: Callback function types have C linkage. sql/derror.cc: Expected function type has C linkage. sql/field.cc: Use helper macro and fix indentation. sql/handler.cc: Expected function type has C linkage. sql/item_sum.cc: Correct function linkages. Remove now unnecessary cast. sql/item_sum.h: Add prototypes with the appropriate linkage as otherwise they are distinct. sql/mysqld.cc: Wrap functions in C linkage mode. sql/opt_range.cc: C language linkage is ignored for class member functions. sql/partition_info.cc: Add wrapper functions with C linkage for class member functions. sql/rpl_utility.h: Use helper macro and fix indentation. sql/sql_class.cc: Change type of thd argument -- THD is a class. Use helper macro and fix indentation. sql/sql_class.h: Change type of thd argument -- THD is a class. sql/sql_select.cc: Expected function type has C linkage. sql/sql_select.h: Move prototype to sql_test.h sql/sql_show.cc: Expected function type has C linkage. sql/sql_test.cc: Fix required function prototype and fix coding style. sql/sql_test.h: Removed unnecessary export and add another. storage/myisammrg/ha_myisammrg.cc: Expected function type has C linkage. storage/perfschema/pfs.cc: PSI headers are declared with C language linkage, which also applies to function types.
16 years ago
  1. /* Copyright (C) 2007 Google Inc.
  2. Copyright (C) 2008 MySQL AB, 2008-2009 Sun Microsystems, Inc
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; version 2 of the License.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  13. #include "semisync_master.h"
  14. #include "sql_class.h" // THD
  15. ReplSemiSyncMaster repl_semisync;
  16. C_MODE_START
  17. int repl_semi_report_binlog_update(Binlog_storage_param *param,
  18. const char *log_file,
  19. my_off_t log_pos, uint32 flags)
  20. {
  21. int error= 0;
  22. if (repl_semisync.getMasterEnabled())
  23. {
  24. /*
  25. Let us store the binlog file name and the position, so that
  26. we know how long to wait for the binlog to the replicated to
  27. the slave in synchronous replication.
  28. */
  29. error= repl_semisync.writeTranxInBinlog(log_file,
  30. log_pos);
  31. }
  32. return error;
  33. }
  34. int repl_semi_request_commit(Trans_param *param)
  35. {
  36. return 0;
  37. }
  38. int repl_semi_report_commit(Trans_param *param)
  39. {
  40. bool is_real_trans= param->flags & TRANS_IS_REAL_TRANS;
  41. if (is_real_trans && param->log_pos)
  42. {
  43. const char *binlog_name= param->log_file;
  44. return repl_semisync.commitTrx(binlog_name, param->log_pos);
  45. }
  46. return 0;
  47. }
  48. int repl_semi_report_rollback(Trans_param *param)
  49. {
  50. return repl_semi_report_commit(param);
  51. }
  52. int repl_semi_binlog_dump_start(Binlog_transmit_param *param,
  53. const char *log_file,
  54. my_off_t log_pos)
  55. {
  56. bool semi_sync_slave= repl_semisync.is_semi_sync_slave();
  57. if (semi_sync_slave)
  58. {
  59. /* One more semi-sync slave */
  60. repl_semisync.add_slave();
  61. /*
  62. Let's assume this semi-sync slave has already received all
  63. binlog events before the filename and position it requests.
  64. */
  65. repl_semisync.reportReplyBinlog(param->server_id, log_file, log_pos);
  66. }
  67. sql_print_information("Start %s binlog_dump to slave (server_id: %d), pos(%s, %lu)",
  68. semi_sync_slave ? "semi-sync" : "asynchronous",
  69. param->server_id, log_file, (unsigned long)log_pos);
  70. return 0;
  71. }
  72. int repl_semi_binlog_dump_end(Binlog_transmit_param *param)
  73. {
  74. bool semi_sync_slave= repl_semisync.is_semi_sync_slave();
  75. sql_print_information("Stop %s binlog_dump to slave (server_id: %d)",
  76. semi_sync_slave ? "semi-sync" : "asynchronous",
  77. param->server_id);
  78. if (semi_sync_slave)
  79. {
  80. /* One less semi-sync slave */
  81. repl_semisync.remove_slave();
  82. }
  83. return 0;
  84. }
  85. int repl_semi_reserve_header(Binlog_transmit_param *param,
  86. unsigned char *header,
  87. unsigned long size, unsigned long *len)
  88. {
  89. *len += repl_semisync.reserveSyncHeader(header, size);
  90. return 0;
  91. }
  92. int repl_semi_before_send_event(Binlog_transmit_param *param,
  93. unsigned char *packet, unsigned long len,
  94. const char *log_file, my_off_t log_pos)
  95. {
  96. return repl_semisync.updateSyncHeader(packet,
  97. log_file,
  98. log_pos,
  99. param->server_id);
  100. }
  101. int repl_semi_after_send_event(Binlog_transmit_param *param,
  102. const char *event_buf, unsigned long len)
  103. {
  104. if (repl_semisync.is_semi_sync_slave())
  105. {
  106. THD *thd= current_thd;
  107. /*
  108. Possible errors in reading slave reply are ignored deliberately
  109. because we do not want dump thread to quit on this. Error
  110. messages are already reported.
  111. */
  112. (void) repl_semisync.readSlaveReply(&thd->net,
  113. param->server_id, event_buf);
  114. thd->clear_error();
  115. }
  116. return 0;
  117. }
  118. int repl_semi_reset_master(Binlog_transmit_param *param)
  119. {
  120. if (repl_semisync.resetMaster())
  121. return 1;
  122. return 0;
  123. }
  124. C_MODE_END
  125. /*
  126. semisync system variables
  127. */
  128. static void fix_rpl_semi_sync_master_timeout(MYSQL_THD thd,
  129. SYS_VAR *var,
  130. void *ptr,
  131. const void *val);
  132. static void fix_rpl_semi_sync_master_trace_level(MYSQL_THD thd,
  133. SYS_VAR *var,
  134. void *ptr,
  135. const void *val);
  136. static void fix_rpl_semi_sync_master_enabled(MYSQL_THD thd,
  137. SYS_VAR *var,
  138. void *ptr,
  139. const void *val);
  140. static MYSQL_SYSVAR_BOOL(enabled, rpl_semi_sync_master_enabled,
  141. PLUGIN_VAR_OPCMDARG,
  142. "Enable semi-synchronous replication master (disabled by default). ",
  143. NULL, // check
  144. &fix_rpl_semi_sync_master_enabled, // update
  145. 0);
  146. static MYSQL_SYSVAR_ULONG(timeout, rpl_semi_sync_master_timeout,
  147. PLUGIN_VAR_OPCMDARG,
  148. "The timeout value (in ms) for semi-synchronous replication in the master",
  149. NULL, // check
  150. fix_rpl_semi_sync_master_timeout, // update
  151. 10000, 0, ~0L, 1);
  152. static MYSQL_SYSVAR_BOOL(wait_no_slave, rpl_semi_sync_master_wait_no_slave,
  153. PLUGIN_VAR_OPCMDARG,
  154. "Wait until timeout when no semi-synchronous replication slave available (enabled by default). ",
  155. NULL, // check
  156. NULL, // update
  157. 1);
  158. static MYSQL_SYSVAR_ULONG(trace_level, rpl_semi_sync_master_trace_level,
  159. PLUGIN_VAR_OPCMDARG,
  160. "The tracing level for semi-sync replication.",
  161. NULL, // check
  162. &fix_rpl_semi_sync_master_trace_level, // update
  163. 32, 0, ~0L, 1);
  164. static SYS_VAR* semi_sync_master_system_vars[]= {
  165. MYSQL_SYSVAR(enabled),
  166. MYSQL_SYSVAR(timeout),
  167. MYSQL_SYSVAR(wait_no_slave),
  168. MYSQL_SYSVAR(trace_level),
  169. NULL,
  170. };
  171. static void fix_rpl_semi_sync_master_timeout(MYSQL_THD thd,
  172. SYS_VAR *var,
  173. void *ptr,
  174. const void *val)
  175. {
  176. *(unsigned long *)ptr= *(unsigned long *)val;
  177. repl_semisync.setWaitTimeout(rpl_semi_sync_master_timeout);
  178. return;
  179. }
  180. static void fix_rpl_semi_sync_master_trace_level(MYSQL_THD thd,
  181. SYS_VAR *var,
  182. void *ptr,
  183. const void *val)
  184. {
  185. *(unsigned long *)ptr= *(unsigned long *)val;
  186. repl_semisync.setTraceLevel(rpl_semi_sync_master_trace_level);
  187. return;
  188. }
  189. static void fix_rpl_semi_sync_master_enabled(MYSQL_THD thd,
  190. SYS_VAR *var,
  191. void *ptr,
  192. const void *val)
  193. {
  194. *(char *)ptr= *(char *)val;
  195. if (rpl_semi_sync_master_enabled)
  196. {
  197. if (repl_semisync.enableMaster() != 0)
  198. rpl_semi_sync_master_enabled = false;
  199. }
  200. else
  201. {
  202. if (repl_semisync.disableMaster() != 0)
  203. rpl_semi_sync_master_enabled = true;
  204. }
  205. return;
  206. }
  207. Trans_observer trans_observer = {
  208. sizeof(Trans_observer), // len
  209. repl_semi_report_commit, // after_commit
  210. repl_semi_report_rollback, // after_rollback
  211. };
  212. Binlog_storage_observer storage_observer = {
  213. sizeof(Binlog_storage_observer), // len
  214. repl_semi_report_binlog_update, // report_update
  215. };
  216. Binlog_transmit_observer transmit_observer = {
  217. sizeof(Binlog_transmit_observer), // len
  218. repl_semi_binlog_dump_start, // start
  219. repl_semi_binlog_dump_end, // stop
  220. repl_semi_reserve_header, // reserve_header
  221. repl_semi_before_send_event, // before_send_event
  222. repl_semi_after_send_event, // after_send_event
  223. repl_semi_reset_master, // reset
  224. };
  225. #define SHOW_FNAME(name) \
  226. rpl_semi_sync_master_show_##name
  227. #define DEF_SHOW_FUNC(name, show_type) \
  228. static int SHOW_FNAME(name)(MYSQL_THD thd, SHOW_VAR *var, char *buff) \
  229. { \
  230. repl_semisync.setExportStats(); \
  231. var->type= show_type; \
  232. var->value= (char *)&rpl_semi_sync_master_##name; \
  233. return 0; \
  234. }
  235. DEF_SHOW_FUNC(status, SHOW_BOOL)
  236. DEF_SHOW_FUNC(clients, SHOW_LONG)
  237. DEF_SHOW_FUNC(wait_sessions, SHOW_LONG)
  238. DEF_SHOW_FUNC(trx_wait_time, SHOW_LONGLONG)
  239. DEF_SHOW_FUNC(trx_wait_num, SHOW_LONGLONG)
  240. DEF_SHOW_FUNC(net_wait_time, SHOW_LONGLONG)
  241. DEF_SHOW_FUNC(net_wait_num, SHOW_LONGLONG)
  242. DEF_SHOW_FUNC(avg_net_wait_time, SHOW_LONG)
  243. DEF_SHOW_FUNC(avg_trx_wait_time, SHOW_LONG)
  244. /* plugin status variables */
  245. static SHOW_VAR semi_sync_master_status_vars[]= {
  246. {"Rpl_semi_sync_master_status",
  247. (char*) &SHOW_FNAME(status),
  248. SHOW_FUNC},
  249. {"Rpl_semi_sync_master_clients",
  250. (char*) &SHOW_FNAME(clients),
  251. SHOW_FUNC},
  252. {"Rpl_semi_sync_master_yes_tx",
  253. (char*) &rpl_semi_sync_master_yes_transactions,
  254. SHOW_LONG},
  255. {"Rpl_semi_sync_master_no_tx",
  256. (char*) &rpl_semi_sync_master_no_transactions,
  257. SHOW_LONG},
  258. {"Rpl_semi_sync_master_wait_sessions",
  259. (char*) &SHOW_FNAME(wait_sessions),
  260. SHOW_FUNC},
  261. {"Rpl_semi_sync_master_no_times",
  262. (char*) &rpl_semi_sync_master_off_times,
  263. SHOW_LONG},
  264. {"Rpl_semi_sync_master_timefunc_failures",
  265. (char*) &rpl_semi_sync_master_timefunc_fails,
  266. SHOW_LONG},
  267. {"Rpl_semi_sync_master_wait_pos_backtraverse",
  268. (char*) &rpl_semi_sync_master_wait_pos_backtraverse,
  269. SHOW_LONG},
  270. {"Rpl_semi_sync_master_tx_wait_time",
  271. (char*) &SHOW_FNAME(trx_wait_time),
  272. SHOW_FUNC},
  273. {"Rpl_semi_sync_master_tx_waits",
  274. (char*) &SHOW_FNAME(trx_wait_num),
  275. SHOW_FUNC},
  276. {"Rpl_semi_sync_master_tx_avg_wait_time",
  277. (char*) &SHOW_FNAME(avg_trx_wait_time),
  278. SHOW_FUNC},
  279. {"Rpl_semi_sync_master_net_wait_time",
  280. (char*) &SHOW_FNAME(net_wait_time),
  281. SHOW_FUNC},
  282. {"Rpl_semi_sync_master_net_waits",
  283. (char*) &SHOW_FNAME(net_wait_num),
  284. SHOW_FUNC},
  285. {"Rpl_semi_sync_master_net_avg_wait_time",
  286. (char*) &SHOW_FNAME(avg_net_wait_time),
  287. SHOW_FUNC},
  288. {NULL, NULL, SHOW_LONG},
  289. };
  290. #ifdef HAVE_PSI_INTERFACE
  291. PSI_mutex_key key_ss_mutex_LOCK_binlog_;
  292. static PSI_mutex_info all_semisync_mutexes[]=
  293. {
  294. { &key_ss_mutex_LOCK_binlog_, "LOCK_binlog_", 0}
  295. };
  296. PSI_cond_key key_ss_cond_COND_binlog_send_;
  297. static PSI_cond_info all_semisync_conds[]=
  298. {
  299. { &key_ss_cond_COND_binlog_send_, "COND_binlog_send_", 0}
  300. };
  301. static void init_semisync_psi_keys(void)
  302. {
  303. const char* category= "semisync";
  304. int count;
  305. if (PSI_server == NULL)
  306. return;
  307. count= array_elements(all_semisync_mutexes);
  308. PSI_server->register_mutex(category, all_semisync_mutexes, count);
  309. count= array_elements(all_semisync_conds);
  310. PSI_server->register_cond(category, all_semisync_conds, count);
  311. }
  312. #endif /* HAVE_PSI_INTERFACE */
  313. static int semi_sync_master_plugin_init(void *p)
  314. {
  315. #ifdef HAVE_PSI_INTERFACE
  316. init_semisync_psi_keys();
  317. #endif
  318. if (repl_semisync.initObject())
  319. return 1;
  320. if (register_trans_observer(&trans_observer, p))
  321. return 1;
  322. if (register_binlog_storage_observer(&storage_observer, p))
  323. return 1;
  324. if (register_binlog_transmit_observer(&transmit_observer, p))
  325. return 1;
  326. return 0;
  327. }
  328. static int semi_sync_master_plugin_deinit(void *p)
  329. {
  330. if (unregister_trans_observer(&trans_observer, p))
  331. {
  332. sql_print_error("unregister_trans_observer failed");
  333. return 1;
  334. }
  335. if (unregister_binlog_storage_observer(&storage_observer, p))
  336. {
  337. sql_print_error("unregister_binlog_storage_observer failed");
  338. return 1;
  339. }
  340. if (unregister_binlog_transmit_observer(&transmit_observer, p))
  341. {
  342. sql_print_error("unregister_binlog_transmit_observer failed");
  343. return 1;
  344. }
  345. sql_print_information("unregister_replicator OK");
  346. return 0;
  347. }
  348. struct Mysql_replication semi_sync_master_plugin= {
  349. MYSQL_REPLICATION_INTERFACE_VERSION
  350. };
  351. /*
  352. Plugin library descriptor
  353. */
  354. mysql_declare_plugin(semi_sync_master)
  355. {
  356. MYSQL_REPLICATION_PLUGIN,
  357. &semi_sync_master_plugin,
  358. "rpl_semi_sync_master",
  359. "He Zhenxing",
  360. "Semi-synchronous replication master",
  361. PLUGIN_LICENSE_GPL,
  362. semi_sync_master_plugin_init, /* Plugin Init */
  363. semi_sync_master_plugin_deinit, /* Plugin Deinit */
  364. 0x0100 /* 1.0 */,
  365. semi_sync_master_status_vars, /* status variables */
  366. semi_sync_master_system_vars, /* system variables */
  367. NULL /* config options */
  368. }
  369. mysql_declare_plugin_end;