Bug #25192 Using relay-log and relay-log-index without values produces unexpected results.
Submitted: 20 Dec 2006 1:14 Modified: 29 Jan 2011 23:17
Reporter: Morgan Tocker Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Options Severity:S3 (Non-critical)
Version:4.1+ OS:Linux (Linux)
Assigned to: Zhenxing He CPU Architecture:Any

[20 Dec 2006 1:14] Morgan Tocker
Description:
relay log files/index has a -- before it, and an unexpected name.

How to repeat:
Set up a server to be a slave of anything, but with an options file like this:

morgo@morgobook:~/bin/mysql/data$ more /etc/my.cnf 
[mysqld]
server-id=2

relay-log
relay-log-index

This creates files in the data directory like this:

morgo@morgobook:~/bin/mysql/data$ ls
ibdata1      master.info    morguntu.err  --relay-log-index.000001  test
ib_logfile0  morgobook.err  mysql         --relay-log-index.index
ib_logfile1  morgobook.pid  privtest      relay-log.info

Suggested fix:
Ignore the option if it has no value
[22 Dec 2006 8:54] Sveta Smirnova
Thank you for the report.

Verified as described.

All versions are affected.
[3 Jan 2007 11:07] Lars Thalmann
I think the server should generate a clear error message and *not*
ignore things an incorrect my.cnf file.

It is important that the user always gets what he expects from the
MySQL server and if he has configured something wrongly, he should be
clearly informed about that.
[23 Jan 2007 11:23] Sergei Golubchik
This is expected behaviour. MySQL processes options from my.cnf by inserting them into the command line, so

relay-log
relay-log-index

in the my.cnf is exactly equivalent to

mysqld --relay-log --relay-log-index

which means, _precisely_, that a relay log should be created with the file name "--relay-log-index"
[25 Jan 2007 8:32] Sergei Golubchik
ok, so this is a bug, because:
1. mysqld was started with --relay-log='--relay-log-index'
   which means "relay log file name should be --relay-log-index",
   relay log index file name should be default
2. created files were --relay-log-index.000001 and --relay-log-index.index
3. according to the manual, " The default name is host_name-relay-bin.index in the data directory, where host_name is the name of the slave server."
4. so relay log index file should've been morgobook-relay-bin.index and not 
--relay-log-index.index
[15 Dec 2007 11:54] Jon Stephens
This is neither intuitive nor sensible behaviour, and should *not* be documented as the norm.

Morgan's config should be either

a) interpreted as --relay-log=[default] --relay-index=[default]

(no argument = default)

or

b) rejected with an error

(no argument = invalid syntax)

(b) is preferable.

Please make it so.
[15 Dec 2007 12:19] Sergei Golubchik
The manual needs to explain that all option files are added to the command line before other (explicitly specified) options. Because this is how it is implemented.
[15 Dec 2007 18:57] Jon Stephens
The fact that options specified in an option file are parsed before those specified on the command line is not in dispute, and this is documented - I can't find where this is explicitly stated, but it is implied numerous times on (for example) http://dev.mysql.com/doc/refman/5.1/en/option-files.html (where it is noted, for instance, that only the first occurrence of --user is honoured so that it can't be overridden by being used again on the command line) and other places.

This also has absolutely nothing to do with the issue presented here, which is that

--option_a --option_b

is interpreted as

--option_a='--option_b'

If this were true of *all* server options, then we would merely be arguing the merits (or lack thereof) of the implementation (which IMHO is not good because its very counterintuitive and so makes it entirely too easy for users to shoot themselves in the foot, but that's beside the point). But it isn't true of all options that expect to be paired with values, and so we're not arguing the merits of this behaviour at all:

jon@tonfisk:~/bin/mysql-6.0/bin> ./mysqld_safe --log-error --binlog_format --ndbcluster --ndb-connectstring=127.0.0.1 &
[1] 16350
jon@tonfisk:~/bin/mysql-6.0/bin> 071215 19:26:49 mysqld_safe Logging to '/home/jon/bin/mysql-6.0/var/tonfisk.err'.
071215 19:26:49 mysqld_safe Starting mysqld daemon with databases from /home/jon/bin/mysql-6.0/var
071215 19:26:50 mysqld_safe mysqld from pid file /home/jon/bin/mysql-6.0/var/tonfisk.pid ended

[1]+  Done                    ./mysqld_safe --log-error --binlog_format --ndbcluster --ndb-connectstring=127.0.0.1
jon@tonfisk:~/bin/mysql-6.0/bin> tail ../var/tonfisk.err

071215 19:26:49 mysqld_safe Starting mysqld daemon with databases from /home/jon/bin/mysql-6.0/var
Unknown option to binlog_format: --ndbcluster
Alternatives are: 'MIXED','STATEMENT','ROW'
071215 19:26:50 mysqld_safe mysqld from pid file /home/jon/bin/mysql-6.0/var/tonfisk.pid ended

In this case, --log-err does *not* write to an error file named '--binlog_format'; in other words, it doesn't mistake the following switch as an option value (although --binlog_format does); instead, it writes to the default, hostname.err.

So we have some options that act one way, and some that act another way, and there appear to be no rules covering this. Which is a misfeature. Misfeatures don't need to be enshrined in the documentation; they need to be fixed.
[15 Dec 2007 19:11] Paul DuBois
Option precedence is:

"MySQL programs determine which options are given first by examining environment variables, then by reading option files, and then by checking the command line. This means that environment variables have the lowest precedence and command-line options the highest."

as stated here: http://dev.mysql.com/doc/refman/5.0/en/program-options.html
[15 Dec 2007 20:12] Sergei Golubchik
I didn't mean the precedence. But the fact that they are added to the command line. That is,

[client]
new

is not somehow parsed, but, exactly, changed to --new and added to the command line. The behavior is *absolutely* identical to having --new on the command line.
The manual doesn't say anything beyond "parsed before" which is not enough.
[15 Dec 2007 20:28] Sergei Golubchik
As for the rest...

First. see http://dev.mysql.com/doc/refman/5.1/en/server-options.html and 
http://dev.mysql.com/doc/refman/5.1/en/replication-options.html

   --log-error[=file_name]
   --binlog-format={row|statement|mixed}
   --relay-log=file_name

that is, for --log-error the argument is optional, for --binlog-format and --relay-log it is mandatory.

Second. It's the standard behavior to support --option value as well as --option=value:

% grep --after-context=1 more /etc/protocols
# See protocols(5) for more info
#
% grep --after-context 1 more /etc/protocols 
# See protocols(5) for more info
#
% 

also when a value starts from '--':

% ls -l
total 0K
-rw------- 1 serg users 0 Dec 15 21:31 file1
-rw------- 1 serg users 0 Dec 15 21:31 file2
-rw------- 1 serg users 0 Dec 15 21:31 file3
% ls -l --inode
total 0K
28606547 -rw------- 1 serg users 0 Dec 15 21:31 file1
28606548 -rw------- 1 serg users 0 Dec 15 21:31 file2
28606549 -rw------- 1 serg users 0 Dec 15 21:31 file3
% ls -l --ignore --inode
total 0K
-rw------- 1 serg users 0 Dec 15 21:31 file1
-rw------- 1 serg users 0 Dec 15 21:31 file2
-rw------- 1 serg users 0 Dec 15 21:31 file3
%
[8 Jan 2008 20:04] Paul DuBois
Serg, you say:

"[15 Dec 2007 21:12] Sergei Golubchik
I didn't mean the precedence. But the fact that they are added to the command line."

No, they're not added to the command line. They are added to the argument array created from the command line. Perhaps that is a quibble.

But the fact that the arguments are added to the argument array produces the same effect as precedence: The option file options appear earlier in the array, the command line arguments appear later, and because later options override earlier ones, the command-line arguments take precedence over the option file arguments.
[12 Jan 2008 20:43] Jon Stephens
This is still a server bug.

[mysqld]
--relay-log
--relay-log-index

should, by Sergei's account, be the same as starting the server with 

--relay-log=--relay-log-index 

on the command line. This should have the following result:

1. A relay log is created with the name '--relay-log-index.0001'. This is in fact what happens, and is (whether I happen to like it or not) correct behaviour.

2. A relay log index file is created with the name '--relay-log-index.index'. But --relay-log-index option *was not used*,  because this string was treated as the value of the --relay-log option, no? Therefore, as Sergei has already stated, "relay log index file should've been morgobook-relay-bin.index and not --relay-log-index.index".

The string '--relay-log-index' should be parsed *either* as an option, or as an option value. It should not be treated as both, which appears to be what's happened here. And (according to the Manual) the value of --relay-log should not have any effect on the naming of the relay log index file.
[12 Jan 2008 23:09] Jon Stephens
Lest anyone think I am merely trying to avoid doing any work on this, I offer the following commit to the docs in an effort to explain options behaviour a bit better: 

http://lists.mysql.com/commits/40965

This will appear shortly in the online Manual as: 

http://dev.mysql.com/doc/refman/5.1/en/option-defaults-equals.html

Feedback is invited on same.

Thanks.
[14 Jan 2008 9:36] Sergei Golubchik
Cool! Thanks, Jon
[23 Jan 2008 23:05] Sveta Smirnova
Bug #33881 was marked as duplicate of this one.
[6 Mar 2009 6:37] Zhenxing He
The documentation about 'relay-log' and 'relay-log-index' is not correct, when only one of these options are set, the other will get the same value. So if we set --relay-log='--relay-log-index' and leave out --relay-log-index, then --relay-log-index will be '--relay-log-index' too, and this is designed behavior. 

Although I think it's correct to interpret options --relay-log --relay-log-index given on command line as --relay-log='--relay-log-index', I don't think it is correct to interpret the corresponding configure in file this way:

[mysqld]
relay-log
relay-log-index

I think in this case, it's obvious that the user does not specify a value for both relay-log and relay-log-index, there is not ambiguity here as in command line. So I think mysqld should report an error about wrong usage of options.
[6 Mar 2009 9:17] Jon Stephens
Per latest comments and IRC discussion with Jason, reassigning to myself (at least for now/docs portion of this issue)
[17 Mar 2009 14:05] Jon Stephens
Thank you for your bug report. This issue has been addressed in the documentation. The updated documentation will appear on our website shortly, and will be included in the next release of the relevant products.
[17 Mar 2009 14:06] Jon Stephens
After closing Docs portion of this issue, setting back to Verified/Server:Options and reassigning to JasonH per our previous discussion.
[18 Mar 2009 9:50] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/69551

2827 He Zhenxing	2009-03-18
      BUG#25192 Using relay-log and relay-log-index without values produces unexpected results.
      
      If an option requires a value, it will take the next argument as
      the value even if it is an option name, this behavior can confuse
      the users when they specify multiple options and expecting to use
      the default value.
      
      Fixed the problem by not allowing arguments started with '-' to
      be treated as values for an option, if such a value is used for
      an option, it must be given after '='.
[25 Mar 2009 4:25] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/70290

2828 He Zhenxing	2009-03-25
      BUG#25192 Using relay-log and relay-log-index without values produces unexpected results.
      
      Options loaded from config files were added before command line
      arguments, and they were parsed together, which could interprete
      the following:
      option-a
      option-b
      as --option-a=--option-b if 'option-a' requires a value, and 
      caused confusing.
      
      Because all options that requires a value are always given in
      the form '--option=value', so it's an error if there is no 
      '=value' part for such an option read from config file.
      
      This patch added a separator to separate the arguments from 
      config files and that from command line, so that they can be
      handled differently. And report an error for options loaded
      from config files that requires a value and is not given in the
      form '--option=value'.
[31 Mar 2009 5:45] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/70855

2827 He Zhenxing	2009-03-31
      BUG#25192 Using relay-log and relay-log-index without values produces unexpected results.
      
      Options loaded from config files were added before command line
      arguments, and they were parsed together, which could interprete
      the following:
      option-a
      option-b
      as --option-a=--option-b if 'option-a' requires a value, and 
      caused confusing.
      
      Because all options that requires a value are always given in
      the form '--option=value', so it's an error if there is no 
      '=value' part for such an option read from config file.
      
      This patch added a separator to separate the arguments from 
      config files and that from command line, so that they can be
      handled differently. And report an error for options loaded
      from config files that requires a value and is not given in the
      form '--option=value'.
[1 Apr 2009 6:56] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/71003

2827 He Zhenxing	2009-04-01
      BUG#25192 Using relay-log and relay-log-index without values produces unexpected results.
      
      Options loaded from config files were added before command line
      arguments, and they were parsed together, which could interprete
      the following:
      option-a
      option-b
      as --option-a=--option-b if 'option-a' requires a value, and 
      caused confusing.
      
      Because all options that requires a value are always given in
      the form '--option=value', so it's an error if there is no 
      '=value' part for such an option read from config file.
      
      This patch added a separator to separate the arguments from 
      config files and that from command line, so that they can be
      handled differently. And report an error for options loaded
      from config files that requires a value and is not given in the
      form '--option=value'.
[21 Apr 2009 9:28] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/72552

2845 He Zhenxing	2009-04-21
      BUG#25192 Using relay-log and relay-log-index without values produces unexpected results.
      
      Options loaded from config files were added before command line
      arguments, and they were parsed together, which could interprete
      the following:
      option-a
      option-b
      as --option-a=--option-b if 'option-a' requires a value, and 
      caused confusing.
      
      Because all options that requires a value are always given in
      the form '--option=value', so it's an error if there is no 
      '=value' part for such an option read from config file.
      
      This patch added a separator to separate the arguments from 
      config files and that from command line, so that they can be
      handled differently. And report an error for options loaded
      from config files that requires a value and is not given in the
      form '--option=value'.
[24 Apr 2009 4:05] Zhenxing He
pushed to 6.0-rpl
[13 May 2009 3:30] Bugs System
Pushed into 6.0.12-alpha (revid:alik@sun.com-20090513032549-rxa73jbxd1qv09xc) (version source revid:aelkin@mysql.com-20090429125820-vu261kl1z4z5f0iv) (merge vers: 6.0.12-alpha) (pib:6)
[13 May 2009 19:32] Jon Stephens
The 17 March commit for the documentation (2nd fix to docs arising from this bug) can be found here: http://lists.mysql.com/commits/69423.
[14 May 2009 8:30] Jon Stephens
Documented bugfix in the 6.0.12 changelog as follows:

        An option that requires a value, when specified in an option
        file without a value, was assigned the text of the next line in
        the file as the value. Now, if you fail to specify a required
        value in an option file, the server aborts with an error.

        This change does not effect how options are handled by the
        server when they are used on the command line. For example,
        starting the server using *mysqld_safe --relay-log 
        --relay-log-index &* causes the server to create relay log files 
        named --relay-log-index.000001, --relay-log-index.000002,
        and so on.

Also updated option-defaults-equals section of 6.0 Manual with info and examples of the behavior change.
[2 Oct 2009 8:26] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/85478

3119 He Zhenxing	2009-10-02
      Backport BUG#25192 Using relay-log and relay-log-index without values produces unexpected results.
      
      Options loaded from config files were added before command line
      arguments, and they were parsed together, which could interprete
      the following:
      option-a
      option-b
      as --option-a=--option-b if 'option-a' requires a value, and 
      caused confusing.
      
      Because all options that requires a value are always given in
      the form '--option=value', so it's an error if there is no 
      '=value' part for such an option read from config file.
      
      This patch added a separator to separate the arguments from 
      config files and that from command line, so that they can be
      handled differently. And report an error for options loaded
      from config files that requires a value and is not given in the
      form '--option=value'.
[2 Oct 2009 8:40] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/85482

3121 He Zhenxing	2009-10-02
      Backport post fix compiler warnings and test failures for BUG#25192 BUG#12190
[27 Oct 2009 9:48] Bugs System
Pushed into 6.0.14-alpha (revid:alik@sun.com-20091027094604-9p7kplu1vd2cvcju) (version source revid:zhenxing.he@sun.com-20091026140226-uhnqejkyqx1aeilc) (merge vers: 6.0.14-alpha) (pib:13)
[12 Nov 2009 8:18] Bugs System
Pushed into 5.5.0-beta (revid:alik@sun.com-20091110093229-0bh5hix780cyeicl) (version source revid:alik@sun.com-20091027095744-rf45u3x3q5d1f5y0) (merge vers: 5.5.0-beta) (pib:13)
[15 Nov 2009 22:20] Paul DuBois
Noted in 5.5.0 changelog.
[17 Jan 2011 9:59] Bugs System
Pushed into mysql-trunk 5.6.2 (revid:hezx@greatopensource.com-20110117095259-jbpwy1vhb0ggkq9k) (version source revid:hezx@greatopensource.com-20110117095259-jbpwy1vhb0ggkq9k) (merge vers: 5.6.2) (pib:24)
[17 Jan 2011 10:01] Bugs System
Pushed into mysql-5.5 5.5.10 (revid:hezx@greatopensource.com-20110117095918-ibh2zq8x63eqcq4q) (version source revid:hezx@greatopensource.com-20110117074437-v3icyuwsocqj0j6c) (merge vers: 5.5.10) (pib:24)