Bug #83613 compile error: size of array ‘compile_time_assert’ is negative added SQL command
Submitted: 30 Oct 2016 14:36 Modified: 16 Nov 2016 16:09
Reporter: Shahriyar Rzayev (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Replication Severity:S3 (Non-critical)
Version:5.6.32 OS:Any
Assigned to: CPU Architecture:Any

[30 Oct 2016 14:36] Shahriyar Rzayev
Description:
Trying to learn Replication, source code.
Reading book, "Expert MySQL" by Charles Bell.
Chapter 8, "Extending MySQL High Availability" -> page 310, "Extending Replication".
Where we should add new command -> "SQLCOM_STOP_SLAVES" executed on master and causing to STOP IO_THREAD on all slaves.

After adding necessary things into:
sql/lex.h
sql/sql_cmd.h
sql/sql_yacc.h
sql/sql_parse.cc

Resulted with:

Scanning dependencies of target sql
[ 54%] Building CXX object sql/CMakeFiles/sql.dir/sql_parse.cc.o
[ 54%] Building CXX object sql/CMakeFiles/sql.dir/mysqld.cc.o
In file included from /home/sh/MySQLPakcages/mysql-5.6.32/include/my_compiler.h:151:0,
                 from /home/sh/MySQLPakcages/mysql-5.6.32/include/my_global.h:473,
                 from /home/sh/MySQLPakcages/mysql-5.6.32/sql/mysqld.cc:17:
/home/sh/MySQLPakcages/mysql-5.6.32/sql/mysqld.cc: In function ‘int init_common_variables()’:
/home/sh/MySQLPakcages/mysql-5.6.32/include/my_attribute.h:38:42: error: size of array ‘compile_time_assert’ is negative
 #  define MY_ATTRIBUTE(A) __attribute__(A)
                                          ^
/home/sh/MySQLPakcages/mysql-5.6.32/include/my_global.h:377:52: note: in expansion of macro ‘MY_ATTRIBUTE’
     typedef char compile_time_assert[(X) ? 1 : -1] MY_ATTRIBUTE((unused)); \
                                                    ^
/home/sh/MySQLPakcages/mysql-5.6.32/sql/mysqld.cc:3871:3: note: in expansion of macro ‘compile_time_assert’
   compile_time_assert(sizeof(com_status_vars)/sizeof(com_status_vars[0]) - 1 ==
   ^
sql/CMakeFiles/sql.dir/build.make:3581: recipe for target 'sql/CMakeFiles/sql.dir/mysqld.cc.o' failed
make[2]: *** [sql/CMakeFiles/sql.dir/mysqld.cc.o] Error 1
CMakeFiles/Makefile2:5192: recipe for target 'sql/CMakeFiles/sql.dir/all' failed
make[1]: *** [sql/CMakeFiles/sql.dir/all] Error 2
Makefile:160: recipe for target 'all' failed
make: *** [all] Error 2

Inside sq/sql_cmd.h there is a comment:

/*
  When a command is added here, be sure it's also added in mysqld.cc
  in "struct show_var_st status_vars[]= {" ...
*/

It took me some time to figure out that instead of status_vars[] command should be added into  SHOW_VAR com_status_vars[]=

Also comment indicates struct show_var_st  status_vars[] inside sql/mysqld.cc which is in fact SHOW_VAR status_vars[] -> typedef struct st_mysql_show_var SHOW_VAR(sql/sql_show.h) -> struct st_mysql_show_var {
  const char *name;
  char *value;
  enum enum_mysql_show_type type;
};(include/mysql/plugin.h)

How to repeat:
The main reason for report is replacing comment with new one, to be clear for beginners.

Suggested fix:
Replace comment with:
/*
  When a command is added here, be sure it's also added in mysqld.cc
  in " struct st_mysql_show_var com_status_vars[]= {" ...
*/
[16 Nov 2016 16:09] Sinisa Milivojevic
Hi!

I have analyzed your idea and I am also inclined with you that comment should be changed. This is not a great job and it should be done fast.

I see what you are trying to accomplish, but  I would recommend you to look at our Group Replication. When it is announced (which should not happen in a long time), read about is and see if it suits you better then this variant of grouped commands.

Verified.