Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mysql: improve warnings when data directory is present. #60190

Closed
wants to merge 16 commits into from

Conversation

peterb
Copy link
Contributor

@peterb peterb commented Aug 26, 2020

Users are already warned about config files, warn users about conflicting data directory too.

@BrewTestBot BrewTestBot added deprecated license Formula uses a deprecated SPDX license which should be updated legacy Relates to a versioned @ formula labels Aug 26, 2020
Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I think the [WARNING] is a bit out of place and a few questions/tweaks but otherwise: nice work!

Formula/mysql@5.7.rb Outdated Show resolved Hide resolved
Formula/mysql@5.7.rb Outdated Show resolved Hide resolved
Formula/mysql@5.7.rb Outdated Show resolved Hide resolved
@dtrodrigues
Copy link
Member

Can you prefix the commit message with mysql@5.7: please so it's clear that this is specific to mysql and not homebrew in general?

@SMillerDev SMillerDev changed the title Improve warnings when data directory is present. mysql: improve warnings when data directory is present. Aug 26, 2020
@peterb
Copy link
Contributor Author

peterb commented Aug 26, 2020

I've removed the warning, but this won't detect the presence of that data directory unless it can add something to the caveats from the post_install method, is this possible?

Update: I don't think that is possible, but at least users will get a note to remind them that this data directory could cause issues.

@MikeMcQuaid
Copy link
Member

I've removed the warning

Thanks!

but this won't detect the presence of that data directory unless it can add something to the caveats from the post_install method, is this possible?

I'm not sure I understand this, can you explain why this would be useful?

Update: I don't think that is possible, but at least users will get a note to remind them that this data directory could cause issues.

Yes, I was thinking this alone would be useful.

@peterb
Copy link
Contributor Author

peterb commented Aug 27, 2020

I'm not sure I understand this, can you explain why this would be useful?

We could detect the presence of the data directory before the post_install runs and alter the caveats depending on the result, so the user could be reminded that they had already installed mysql there. I believe that when the user invokes the formula the install method runs, then the post_install method, and then the caveats method. When the program enters the post_install method, there isn't any way of modifying the caveats, but it's at this point when we could check to see if that data directory already exists and add a warning about it for the user to see. Once the program is in the caveats method, it's already too late to check if there was a pre-existing data directory as brew has already run the mysql initialize on it via the post_install method.

@MikeMcQuaid
Copy link
Member

I see. In that case the change as-is seems rather pointless, unfortunately. Can you point to the specific issues that are being caused by this being already present and how failures occur?

@peterb
Copy link
Contributor Author

peterb commented Aug 27, 2020

Yes, I added some details to before I opened this issue on https://discourse.brew.sh/t/for-homebrew-mysql-installs-how-to-fix-mysql-sock-path/660/8

@MikeMcQuaid
Copy link
Member

I see, thanks.

Perhaps the install task should check if the data directory is present and abort if it is rather than silently failing?

I think in this case it needs to check specifically if the data directory exists and is for a newer version of MySQL than the one you're installing. I'm not sure how to do this but it feels like the right direction (and would need to be made to mysql.rb and all mysql@*.rb formulae).

@gromgit
Copy link
Member

gromgit commented Aug 27, 2020

@peterb You may want to look at how the postgresql formula deals with DB upgrades. In short, its caveat references an external Homebrew command postgresql-upgrade-database that users can run to Do The Right Thing. The source is in $(brew --repo homebrew/core)/cmd/postgresql-upgrade-database.rb.

@MikeMcQuaid
Copy link
Member

@gromgit This isn't necessary/comparable with MySQL because:

  • MySQL will automatically upgrade databases without intervention whereas PostgreSQL requires a manual command to be run
  • PostgreSQL uses separate data directories per-version and MySQL (how we have it setup, at least) does not.

We could consider using separate data directories for the older versions of MySQL we have (but we'd need to have it only take effect if the datadir doesn't exist so we don't break existing installs).

@peterb
Copy link
Contributor Author

peterb commented Aug 28, 2020

@MikeMcQuaid I'm happy to look at the mysql@*.rb formulae so that they create and use separate data directories unless there's already one present for the specific version the user is installing. I'm assuming there is a way to detect which version of MySQL a data directory corresponds to, and that the mysql formula won't require a check as it'll auto-upgrade if there was data from an older version present?

@MikeMcQuaid
Copy link
Member

I'm assuming there is a way to detect which version of MySQL a data directory corresponds to

Yeh, there should be. I have no idea what it is, though 😭

that the mysql formula won't require a check as it'll auto-upgrade if there was data from an older version present?

Yes, that's a safe assumption 👍🏻

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so my review is here (as @SMillerDev requested this): as-is this unfortunately won't do anything but we could consider moving the datadir for new installs.

@peterb
Copy link
Contributor Author

peterb commented Sep 2, 2020

@MikeMcQuaid I'm looking into this already, have just pushed some of the changes.

@MikeMcQuaid
Copy link
Member

Thanks @peterb, no rush!

Users are already warned about config files, warn users about conflicting data directory too.
Refine logic for detecting which version of MySQL the datadir corresponds to
by refactoring and adding heuristic for detection of MySQL 5.6.
Use special installation directory in MySQL 5.6 formula as well,
unless the default is already being used.
# type MYISAM, MySQL version 50647
#
def default_datadir_already_in_use_by_this_version?
(var/"mysql").exist? && var.glob("mysql/*.dblwr").empty? && (var/"mysql/test").exist?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think it's enough to just check for (var/"mysql").exist??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also output something in the caveats based on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I think that a simpler check and a caveat explaining the location of the datadir to the user would be preferable to trying to work it out automatically for them. I'll modify as you suggest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: It turns out this is harder to do than I expected, as putting a conditional in the datadir method means it gets evaluated differently during various stages in the formula.

Formula/mysql@5.7.rb Outdated Show resolved Hide resolved
@peterb
Copy link
Contributor Author

peterb commented Sep 11, 2020

@MikeMcQuaid I've updated this to something along the lines of what you were suggesting, I think that detecting if another version of MySQL is installed and using a different datadir is a nice idea in theory, but based on how the formula works it could make it more confusing for the user, and detecting the version of MySQL isn't going to be reliable because there are so many different heuristics but no definitive way of doing it.

With separate datadirs for each version (mysql57 and mysql56 are just suggestions), the possibilities of a conflict should be ameliorated quite a bit, as they can run brew install mysql; brew install mysql@5.7 and use any of these versions by running brew services stop mysql; brew services start msql@5.7 for people that have to deal with legacy databases, this should make using Homebrew to install them a lot friendlier.

Summary: assuming a fresh OSX install, this would get rid of the gotcha that 5.7 will break and requires manually fixing the datadir if MySQL 8 is already installed. If they already have a legacy MySQL installed and decide to run reinstall, then the caveats will tell them that the datadir location has moved.

@peterb
Copy link
Contributor Author

peterb commented Sep 22, 2020

Not sure what the consensus is on this one, so closing it for the moment.

@peterb peterb closed this Sep 22, 2020
@MikeMcQuaid MikeMcQuaid reopened this Sep 22, 2020
@MikeMcQuaid
Copy link
Member

Reopening because it's on my list, sorry for the delay here.

@MikeMcQuaid
Copy link
Member

@peterb #65102 demonstrates the sort of approach I think would make sense to follow for MySQL. Let me know if you have any thoughts/questions but hopefully this will unblock you.

@peterb
Copy link
Contributor Author

peterb commented Dec 7, 2020

@MikeMcQuaid thanks! At a first glance #65102 looks like a good example, I'll take a more detailed look at it.

@peterb
Copy link
Contributor Author

peterb commented Dec 11, 2020

@MikeMcQuaid MySQL 5.6 has reached end-of-life, so it's probably only worth updating the formula for MySQL 5.7. EDIT: 5.6 will reach EOL in three months time.

@BrewTestBot
Copy link
Member

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@BrewTestBot BrewTestBot added stale No recent activity and removed stale No recent activity labels Jan 2, 2021
@BrewTestBot
Copy link
Member

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@BrewTestBot BrewTestBot added the stale No recent activity label Jan 24, 2021
@peterb
Copy link
Contributor Author

peterb commented Jan 28, 2021

@MikeMcQuaid @SMillerDev @gromgit sorry for the delay in picking his up. I could look at MySQL 5.7? How valuable would be for Homebrew?

@BrewTestBot BrewTestBot removed the stale No recent activity label Jan 28, 2021
@SMillerDev
Copy link
Member

Go for it, every improvement is valuable

@BrewTestBot
Copy link
Member

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@BrewTestBot BrewTestBot added the stale No recent activity label Feb 19, 2021
@github-actions github-actions bot added the outdated PR was locked due to age label Apr 6, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
deprecated license Formula uses a deprecated SPDX license which should be updated legacy Relates to a versioned @ formula outdated PR was locked due to age stale No recent activity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants