Bug #34905 Plugin variables of type enum don't receive their default value
Submitted: 27 Feb 2008 21:14 Modified: 5 Sep 2008 6:26
Reporter: Bill Mitchell Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.1.22 OS:Any
Assigned to: CPU Architecture:Any

[27 Feb 2008 21:14] Bill Mitchell
Description:
For handler plugin variables of type enum, there is a problem that the default value is not loaded into the variable upon startup.  Even though the variable is declared as having a nonzero default value, a show variables statement after startup shows the value is still zero.  

How to repeat:
In a plugin, declare a variable of type ENUM that has a non-zero default value, e.g.:

static const char *log_level_names[] =
{ "CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "USER", "TRACE",
  NullS};
static TYPELIB log_level_typelib= {array_elements(log_level_names)-1,"",
			       log_level_names, NULL};

static unsigned long test_level = 0;
static MYSQL_SYSVAR_ENUM(test_level, test_level, PLUGIN_VAR_OPCMDARG,
  "The value of the logging level: Critical, Error, Warning, etc... ",
  NULL, NULL, 3, &log_level_typelib);

After loading the handler, use SHOW VARIABLES LIKE ... to dump the value.  It will have a value of CRITICAL, not INFO matching the default.  

Suggested fix:
Near the end of the logic in construct_options(), there is a guard that skips code when the variable type is PLUGIN_VAR_ENUM or PLUGIN_VAR_SET.  It appears this logic calculates the memory address for the variable, without which no default is assigned.  After commenting out the guard for PLUGIN_VAR_ENUM, the global variable received its default value.

The block:
    if ((opt->flags & PLUGIN_VAR_TYPEMASK) != PLUGIN_VAR_ENUM &&
        (opt->flags & PLUGIN_VAR_TYPEMASK) != PLUGIN_VAR_SET)
    {
      if (opt->flags & PLUGIN_VAR_THDLOCAL)
        options->value= options->u_max_value= (uchar**)
          (global_system_variables.dynamic_variables_ptr + offset);
      else
        options->value= options->u_max_value= *(uchar***) (opt + 1);
    }
should read:

    if ((opt->flags & PLUGIN_VAR_TYPEMASK) != PLUGIN_VAR_ENUM &&
    if ((opt->flags & PLUGIN_VAR_TYPEMASK) != PLUGIN_VAR_SET)
    {
      if (opt->flags & PLUGIN_VAR_THDLOCAL)
        options->value= options->u_max_value= (uchar**)
          (global_system_variables.dynamic_variables_ptr + offset);
      else
        options->value= options->u_max_value= *(uchar***) (opt + 1);
    }

Of course, it may be that the guard should be removed entirely.  I did not define a variable of type SET so I did not investigate whether these have the same problem of not receiving a default value.  

By inspection, it appears this same problem is still in 5.1.23, and the above code fragment is from sql_plugin.cc in 5.1.23.  I did uncover a separate problem that a plugin that declared a variable of type MYSQL_THDVAR_ENUM was diagnosed as invalid in register_var(), but that bug appears fixed in the 5.1.23 source.
[6 Mar 2008 17:39] Bill Mitchell
Obviously there is a typo in the corrected fix, when I did the cut-and-paste.  The suggested fix should read:
 
    if ((opt->flags & PLUGIN_VAR_TYPEMASK) != PLUGIN_VAR_SET)
    {
      if (opt->flags & PLUGIN_VAR_THDLOCAL)
        options->value= options->u_max_value= (uchar**)
          (global_system_variables.dynamic_variables_ptr + offset);
      else
        options->value= options->u_max_value= *(uchar***) (opt + 1);
    }
[27 Mar 2008 14:34] Susanne Ebrecht
Please try with newer version: MySQL 5.1.23.
[14 Apr 2008 17:50] Olivier Chédru
On Windows, with 5.1.23, I cannot get my plugin enum variable set from my option file whereas other options are.
The default check_func_enum() is never called.
Could both problems be related?
[27 Apr 2008 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[4 Aug 2008 4:47] Valeriy Kravchuk
Please, try to repeat with a newer version, 5.1.26, and inform about the results.
[4 Aug 2008 8:57] Olivier Chédru
It's OK with 5.1.26-rc: the enum plugin variable gets its default value as set by the macro MYSQL_SYSVAR_ENUM, and is also properly set from an option file.
[7 Aug 2008 9:00] Susanne Ebrecht
So we can close this bug report?
[7 Aug 2008 9:08] Olivier Chédru
Yes, thanks.
[4 Sep 2008 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[5 Sep 2008 6:26] Valeriy Kravchuk
Closed as it seems fixed in 5.1.26.