Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 575360 - dev-db/mysql-init-scripts - please allow to start with empty data directory
Summary: dev-db/mysql-init-scripts - please allow to start with empty data directory
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Linux MySQL bugs team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-02-22 06:52 UTC by Tomáš Mózes
Modified: 2017-07-24 00:34 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
mysql.init.patch (mysql.init.patch,1.27 KB, patch)
2017-07-22 01:16 UTC, Brian Evans (RETIRED)
Details | Diff
Combined patch for this bug and #625918 (mysql-init-galera.patch,2.33 KB, patch)
2017-07-22 18:45 UTC, Phil Stracchino (Unix Ronin)
Details | Diff
mysql.init.patch (mysql.init.patch,3.69 KB, patch)
2017-07-22 21:59 UTC, Brian Evans (RETIRED)
Details | Diff
mysql.init.patch (mysql.init.patch,3.89 KB, patch)
2017-07-22 23:34 UTC, Brian Evans (RETIRED)
Details | Diff
mysql.init.patch (mysql.init.patch,4.77 KB, patch)
2017-07-23 00:31 UTC, Brian Evans (RETIRED)
Details | Diff
mysql.init.patch (mysql.init.patch,3.89 KB, patch)
2017-07-23 13:15 UTC, Brian Evans (RETIRED)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tomáš Mózes 2016-02-22 06:52:49 UTC
If you start a MariaDB galera cluster, the first server holds the data, but the rest can start with empty data set. Currently this is not possible:

if [ ! -d "${datadir}"/mysql ] ; then
...
  eerror "You don't appear to have the mysql database installed yet."
  eerror "Please run \`emerge --config =${DBPKG_P}\` to have this done..."
  return 1
fi
Comment 1 Phil Stracchino (Unix Ronin) 2017-07-22 00:47:58 UTC
I second this request and for exactly the same reason.

Also see https://bugs.gentoo.org/show_bug.cgi?id=625918 - dev-db/mysql-init-scripts does not support an action for Galera's cluster-bootstrap operation, forcing a lot of manual yak-shaving to bring up a cluster from all nodes down or configure a new cluster.
Comment 2 Brian Evans (RETIRED) gentoo-dev 2017-07-22 01:16:51 UTC
Created attachment 486414 [details, diff]
mysql.init.patch

Does the attached patch solve the new cluster issue?
Comment 3 Phil Stracchino (Unix Ronin) 2017-07-22 03:15:52 UTC
No, that won't solve it, because wsrep-new-cluster is used when bootstrapping the first node of a cluster and its data directory MUST contain data.  It is OK for the data directory to be empty only if the node is joining an existing already-bootstrapped cluster.  If I'm reading it right, this patch will skip the empty-datadir test if and only if a bootstrap is being performe, which is the one time in a Galera cluster that it must not be empty.
Comment 4 Phil Stracchino (Unix Ronin) 2017-07-22 03:18:26 UTC
Hmmm .....   I think I know an approach that would work.  IF /etc/mysql/my.cnf contains the string 'wsrep_on', on a line that is not commented out, AND my_args does NOT contain the string wsrep-new-cluster, THEN the empty-datadir check can be skipped.
Comment 5 Phil Stracchino (Unix Ronin) 2017-07-22 18:45:26 UTC
Created attachment 486476 [details, diff]
Combined patch for this bug and #625918

Functionality:

1. Galera is not in use:
No change in functionality, data directory validity is checked

2. Galera is in use:
2a.  rc-service mysql bootstrap
New cluster is bootstrapped
Data directory must not be empty
Service correctly marked as started
2b.  rc-service mysql start
Existing cluster is joined (existing cluster must be running)
Data directory is PERMITTED to be empty

Known shortcomings:
Galera is detected by the presence of the wsrep_on variable in $MY_CNF.  Properly, Galera should be considered active only if wsrep_on is present and not commented out or disabled.  However, for reasons I don't yet understand I was unable to get the 'present and not commented out' check to work, only the 'present' check.  I also do not check the value of the variable, only that it is present.
Also, this patch does not exhaustively check ALL files in the configdir.

Known bugs:  None discovered so far.
Comment 6 Brian Evans (RETIRED) gentoo-dev 2017-07-22 21:59:25 UTC
Created attachment 486478 [details, diff]
mysql.init.patch

Here is a second revision to compare.  boostrap_galera is added as a function so any user knows what it does.

Also, you cannot read a file to know if wsrep_on is enabled, you won't know where the file is.  You must use my_print_defaults.

Please test and confirm.
Comment 7 Brian Evans (RETIRED) gentoo-dev 2017-07-22 23:34:19 UTC
Created attachment 486482 [details, diff]
mysql.init.patch

Revision 3 with further logic to bootstrap_galera
Comment 8 Phil Stracchino (Unix Ronin) 2017-07-23 00:09:45 UTC
(In reply to Brian Evans from comment #7)
> Created attachment 486482 [details, diff] [details, diff]
> mysql.init.patch
> 
> Revision 3 with further logic to bootstrap_galera

Sorry, this fails to start mysqld.


narn:root:/etc/init.d:14 # rc-service mysql start
 * Checking mysqld configuration for mysql ...
/etc/init.d/mysql: line 182: /sbin/mysqld: No such file or directory
 * mysql config check failed                                                                                              [ !! ]
 * ERROR: mysql failed to start
Comment 9 Phil Stracchino (Unix Ronin) 2017-07-23 00:18:42 UTC
You know, you said the init script can't read from my.cnf because the init script doesn't know where it is.  But the existing init script does this:

	MY_CNF="${MY_CNF:-/etc/${SVCNAME}/my.cnf}"

	if [ ! -r "${MY_CNF}" ] ; then
		eerror "Cannot read the configuration file \`${MY_CNF}'"
		return 1
	fi

And I've tested and verified that my fileContainsString function passed that same ${MY_CNF} works.  So I confess I don't quite see the problem with doing it this way.  Am I missing something non-obvious?
Comment 10 Brian Evans (RETIRED) gentoo-dev 2017-07-23 00:21:48 UTC
(In reply to Phil Stracchino (Unix Ronin) from comment #9)
> You know, you said the init script can't read from my.cnf because the init
> script doesn't know where it is.  But the existing init script does this:
> 
> 	MY_CNF="${MY_CNF:-/etc/${SVCNAME}/my.cnf}"
> 
> 	if [ ! -r "${MY_CNF}" ] ; then
> 		eerror "Cannot read the configuration file \`${MY_CNF}'"
> 		return 1
> 	fi
> 
> And I've tested and verified that my fileContainsString function passed that
> same ${MY_CNF} works.  So I confess I don't quite see the problem with doing
> it this way.  Am I missing something non-obvious?

Because this won't work with the configs included with MariaDB 10.2
Comment 11 Brian Evans (RETIRED) gentoo-dev 2017-07-23 00:31:58 UTC
Created attachment 486486 [details, diff]
mysql.init.patch

Revision 4 to account for empty basedir
Comment 12 Brian Evans (RETIRED) gentoo-dev 2017-07-23 00:40:12 UTC
(In reply to Brian Evans from comment #10)
> (In reply to Phil Stracchino (Unix Ronin) from comment #9)
> > You know, you said the init script can't read from my.cnf because the init
> > script doesn't know where it is.  But the existing init script does this:
> > 
> > 	MY_CNF="${MY_CNF:-/etc/${SVCNAME}/my.cnf}"
> > 
> > 	if [ ! -r "${MY_CNF}" ] ; then
> > 		eerror "Cannot read the configuration file \`${MY_CNF}'"
> > 		return 1
> > 	fi
> > 
> > And I've tested and verified that my fileContainsString function passed that
> > same ${MY_CNF} works.  So I confess I don't quite see the problem with doing
> > it this way.  Am I missing something non-obvious?
> 
> Because this won't work with the configs included with MariaDB 10.2

To expand, i made the 10.2 config based on !includedir which may have several files.  Never assume that a user doesn't have !include or !includedir and read the file.  Using my_print_defaults is consistent.
Comment 13 Phil Stracchino (Unix Ronin) 2017-07-23 01:33:44 UTC
(In reply to Brian Evans from comment #12)

> To expand, i made the 10.2 config based on !includedir which may have
> several files.  Never assume that a user doesn't have !include or
> !includedir and read the file.  Using my_print_defaults is consistent.

A good point.  I did note that as a limitation of my patch.

Trying version 4.
Comment 14 Phil Stracchino (Unix Ronin) 2017-07-23 04:34:58 UTC
Sorry, still no go.  First problem was a bad variable declaration:

narn:root:/etc/init.d:40 # service mysql start
 * Checking mysqld configuration for mysql ...                                                                            [ ok ]
 * Starting mysql ...
/etc/init.d/mysql: line 79: local: `wsrep-new=': not a valid identifier
 * MySQL datadir `' is empty or invalid
 * Please check your config file `/etc/mysql/my.cnf'
 * ERROR: mysql failed to start


I changed that wsrep-new variable to wsrep_new, and got a little further:

narn:root:/etc/init.d:42 # service mysql start
 * Caching service dependencies ...                                                                                       [ ok ]
 * Checking mysqld configuration for mysql ...                                                                            [ ok ]
 * Starting mysql ...
 * MySQL datadir `' is empty or invalid
 * Please check your config file `/etc/mysql/my.cnf'
 * ERROR: mysql failed to start


It looks like get_config() is not working correctly.
Comment 15 Brian Evans (RETIRED) gentoo-dev 2017-07-23 13:15:45 UTC
Created attachment 486570 [details, diff]
mysql.init.patch

(In reply to Phil Stracchino (Unix Ronin) from comment #14)
> narn:root:/etc/init.d:42 # service mysql start
>  * Caching service dependencies ...                                         
> [ ok ]
>  * Checking mysqld configuration for mysql ...                              
> [ ok ]
>  * Starting mysql ...
>  * MySQL datadir `' is empty or invalid
>  * Please check your config file `/etc/mysql/my.cnf'
>  * ERROR: mysql failed to start
> 
> 
> It looks like get_config() is not working correctly.

Yes, I tried to play with it, so this is a bit reverted.
Comment 16 Phil Stracchino (Unix Ronin) 2017-07-23 17:10:56 UTC
Galera active, stop and restart:  successful
Standaline start with Galera disabled:  successful
Galera active, bootstrap:  successful
Bootstrap with empty data:  correctly alerts that database is empty
Standalone start with empty data and Galera disabled:  correctly alerts
Galera active, start with empty data:  Successfully starts, receives SST and rejoins


The one state I have found that does not work correctly and requires manual intervention:  When attempting to bootstrap from a potentially-unclean data directory (grastate.dat contains 'safe_to_bootstrap: 0'), the script does not detect that bootstrap has failed.  It hangs and leaves the mysql service marked in 'crashed' state when killed.  Marking the service 'crashed' is probably correct in this case, but the script should exit instead of hanging.
Comment 17 Phil Stracchino (Unix Ronin) 2017-07-23 17:13:02 UTC
er, meant 'should exit and report failure instead of hanging'
Comment 18 Phil Stracchino (Unix Ronin) 2017-07-23 18:13:43 UTC
Thinking about it, the safe option in this case would be for bootstrep_galera( ) to check ${datadir}/grastate.dat for safe_to_bootstrap and abort bootstrap with a warning if it is 0.  But it does still need to exit with a failed/crashed state if bootstrap or join fails, instead of hanging.  (This is probably not entirely straightforward in the case of an empty-or-unclean cluster join that requires an SST.)
Comment 19 Brian Evans (RETIRED) gentoo-dev 2017-07-23 23:37:03 UTC
(In reply to Phil Stracchino (Unix Ronin) from comment #18)
> Thinking about it, the safe option in this case would be for
> bootstrep_galera( ) to check ${datadir}/grastate.dat for safe_to_bootstrap
> and abort bootstrap with a warning if it is 0.  But it does still need to
> exit with a failed/crashed state if bootstrap or join fails, instead of
> hanging.  (This is probably not entirely straightforward in the case of an
> empty-or-unclean cluster join that requires an SST.)

Added with mysql-init-scripts-2.2

Thanks for the testing.  An init system will not be able to account for all possible reasons the service fails to start.  That's the administrator's job.
We do provide some fail-safe, but a user should know what they are doing to solve issues.
Comment 20 Phil Stracchino (Unix Ronin) 2017-07-24 00:34:30 UTC
(In reply to Brian Evans from comment #19)
> Added with mysql-init-scripts-2.2
> 
> Thanks for the testing.  An init system will not be able to account for all
> possible reasons the service fails to start.  That's the administrator's job.
> We do provide some fail-safe, but a user should know what they are doing to
> solve issues.

Totally agree.  The one failure mode I was able to find is an edge case that requires detailed knowledge of Galera to resolve anyway.