Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-27636

mariadb_upgrade --check-if-upgrade-is-needed cannot be run offline

Details

    Description

      The major cases for the --check-if-upgrade-is-needed are:

      • MDEV-27606 - debian upgrades, which for historical reasons ran mysql_upgrade to expose new functionality to the user.
      • MDEV-25670 Docker Library should run mariadb_upgrade - a very requested user feature that cannot be achieved in all the normal ways of container interaction.

      Because of the current implementation the current Debian implementation would look like:

      1. Start a temporary server in all the fancy ways to prevent user access, plugin initialization, excessive startup time etc (MDEV-27606 has a more complete list)
      2. Run mysql_upgrade --check-if-upgrade-is-needed
      3. If this returns true, probably not as already upgrade, run mysql_upgrade --upgrade-system-tables
      4. shutdown temporary server
      5. start real server with configured options

      The container implementation would be largely the same.

      The rather complicated idea of MDEV-27167 system variable deferred-networking to resolve early initialization, consistent with https://github.com/MariaDB/mariadb-docker/issues/350#issuecomment-786341072 seemed rather unpopular and I was awaiting the MDEV-27279 implementation to be able to resolve this is a scripted manner, preferably as below:

      A more ideal scenario is:

      1. (mariadb server is offline as starting point by default)
      2. Run mysql_upgrade --check-if-upgrade-is-needed
      3. if true; start temporary server; run mysql_upgrade; shutdown temporary server
      4. start real server with configured options

      The reasons for the mysql_upgrade to connect to the server are:

      • to SELECT VERSION
      • to obtain the datadir where mysql_upgrade_info can be examined

      To obtain these for the purposes of mysql_upgrade --check-if-upgrade-is-needed without connecting to the server:

      • mysql_upgrade has a hard baked server version
      • datadir can be a mysql_upgrade option

      While there is no 100% certainty that the mysql_upgrade version is the same as the mariadbd server version when connected, it always will be in the container (one version per container) and most likely in the Debian installation. Miss-use of mysql_upgrade from different server versions at the check stage can rely on the real upgrade version check to be more thorough.

      Even if the --check-if-upgrade-is-need from a 10.2 is run and returns a incorrect result because the server version is 10.1, the version of the server is still checked with the mysql_upgrade is properly run (unless --skip-force is specified).

      So lets re-implement mysql_upgrade --check-if-upgrade-is-needed to have a datadir option and run in an offline mode. This will prevent two mariadb server starts on every time systemd/sysv init/container entrypoint starts and account for the common of an upgrade already occurred, knowing there's a small chance of incorrect versions mismatch, and knowing the fall back version check is there.

      While this doesn't strictly block MDEV-27606 or MDEV-25670 as the first double start mechanism is implemented, many users will complain if the Debian packaging/container entry-point is implemented the current way.

      Attachments

        Issue Links

          Activity

            danblack Daniel Black added a comment -

            Note: 1 is necessary because mysql_upgrade needs to connect to the server and should no try to access the upgrade_info directly.

            The reasons are:

            mysql_upgrade needs to verify the following version information

            mysql_upgrade version (from compile time)

            Version in the mysql_upgrade_info file

            Version of the installed (running) server: All version info are needed to know if there is a need to do an upgrade and if the upgrade can be done.

            mysql_upgrade also need to know that the mysql_upgrade info it access/creates is for the running server.

            The safest way to do that (which will work for any use case) is to get the datadir from the server.

            Another option would be to add an option --datadir to mysql_upgrade, but this is less safe as there are several ways this can go wrong:

            The datadir could point to another directory than the running databases directory, in which case the upgrade will probably never be done (if this is done in a script).

            One could add the mysql_update --datadir option to a global config file. In this case any local users installation of MariaDB would be affected and if they run 'mysql_upgrade' it would use the global installation and probably not do anything even if a local upgrade is needed.

            I totally agree with the above, the actions of mysql_upgrade when its actually doing the upgrade need to do all the strict version/datadir checks. Just not with --check-if-upgrade-is-needed as a quick check which will almost never encounter these problems, and even if it did, it would be the responsibly of actually doing the upgrade to check it strictly.

            danblack Daniel Black added a comment - Note: 1 is necessary because mysql_upgrade needs to connect to the server and should no try to access the upgrade_info directly. The reasons are: mysql_upgrade needs to verify the following version information mysql_upgrade version (from compile time) Version in the mysql_upgrade_info file Version of the installed (running) server: All version info are needed to know if there is a need to do an upgrade and if the upgrade can be done. mysql_upgrade also need to know that the mysql_upgrade info it access/creates is for the running server. The safest way to do that (which will work for any use case) is to get the datadir from the server. Another option would be to add an option --datadir to mysql_upgrade, but this is less safe as there are several ways this can go wrong: The datadir could point to another directory than the running databases directory, in which case the upgrade will probably never be done (if this is done in a script). One could add the mysql_update --datadir option to a global config file. In this case any local users installation of MariaDB would be affected and if they run 'mysql_upgrade' it would use the global installation and probably not do anything even if a local upgrade is needed. I totally agree with the above, the actions of mysql_upgrade when its actually doing the upgrade need to do all the strict version/datadir checks. Just not with --check-if-upgrade-is-needed as a quick check which will almost never encounter these problems, and even if it did, it would be the responsibly of actually doing the upgrade to check it strictly.

            People

              danblack Daniel Black
              danblack Daniel Black
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.