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

Debian postinstall chown or the datadir takes too long on servers with many files on the datadir

Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Fixed
    • 5.5.46, 10.0.22, 10.1.8
    • 10.2.3
    • Platform Debian
    • None
    • Debian

    Description

      I recently experienced a slow MariaDB upgrade/migration from MySQL 5.5 to MariaDB 5.5, after the server has been stopped it took maybe one or two minutes before starting the new one.

      A process doing a "chown mysql -R /var/lib/mysql" was runing for quite a long time.
      This particular server has about 350000 files on its datadir, while its far from being the best practice its not easy to change that (its a shared hosting server).

      Replacing the line on "mariadb-server-*.postinst" :

      chown -R mysql $mysql_datadir

      With something like (there is probably a better alternative) :

      find /var/lib/mysql/ ! -uid $(id -u mysql) -print0 |xargs -0 -r chown mysql

      It seems to be marginally slower (less than 1/100th of a second on my tests) on small directories but faster on directories with many files on it (about 20-40% faster on a directory with only 25k files on a software raid1 with 2* 7200k HDDs).

      Attachments

        Activity

          jb-boin Jean Weisbuch added a comment - - edited

          I did some better testings on the same system with 850,000 unique files on a directory (3.3G of space) located on an ext4 partition and all files are already owned by "mysql" (or the target user).

          It takes between 1min30s and 1min40s to run the classic "chown -R" while the "find" variant only takes around 1.8 seconds, which is significantly faster.
          I did repeat the test multiple times and got a similar result every times.

          Having only one file owned by a different owner (for example "debian-10.0.flag" owned by root) on the folder wont make an significant difference.

          The main drawback of the "find" alternative, is that it will be slower if an important number of files in the folder are owned by a different user than "mysql" (or the target one).
          This case should not be a common one as by default files are created by "mysqld" using the "mysql" user.

          Using "find" and "xargs" would require to add a dependency to the "findutils" package (both files are in it) but its possible to stick to the old behavior in case the package is not present on the system.

          jb-boin Jean Weisbuch added a comment - - edited I did some better testings on the same system with 850,000 unique files on a directory (3.3G of space) located on an ext4 partition and all files are already owned by "mysql" (or the target user). It takes between 1min30s and 1min40s to run the classic " chown -R " while the " find " variant only takes around 1.8 seconds , which is significantly faster. I did repeat the test multiple times and got a similar result every times. Having only one file owned by a different owner (for example " debian-10.0.flag " owned by root ) on the folder wont make an significant difference. The main drawback of the " find " alternative, is that it will be slower if an important number of files in the folder are owned by a different user than " mysql " (or the target one). This case should not be a common one as by default files are created by " mysqld " using the " mysql " user. Using " find " and " xargs " would require to add a dependency to the " findutils " package (both files are in it) but its possible to stick to the old behavior in case the package is not present on the system.

          jb-boin Is find /var/lib/mysql/ ! -uid $(id -u mysql) -print0 |xargs -0 -r chown mysql now your final suggestion or do you have improved versions of it?

          otto Otto Kekäläinen added a comment - jb-boin Is find /var/lib/mysql/ ! -uid $(id -u mysql) -print0 |xargs -0 -r chown mysql now your final suggestion or do you have improved versions of it?

          How about find $mysql_datadir ! -uid $(id -u mysql) -exec chown mysql:mysql {} \; ?

          otto Otto Kekäläinen added a comment - How about find $mysql_datadir ! -uid $(id -u mysql) -exec chown mysql:mysql {} \; ?
          otto Otto Kekäläinen added a comment - Fixed in https://github.com/MariaDB/server/commit/3a6e781ea39b67fabf1a528e6a071215a65f50b0 for 10.2
          jb-boin Jean Weisbuch added a comment -

          Sorry for the delay but just to answer to you last question, the use of "find ... -exec" would call chown on each file wile piping to xargs would call chown with multiple arguments and thus doing less forking and being faster.

          jb-boin Jean Weisbuch added a comment - Sorry for the delay but just to answer to you last question, the use of "find ... -exec" would call chown on each file wile piping to xargs would call chown with multiple arguments and thus doing less forking and being faster.
          otto Otto Kekäläinen added a comment - Fixed for 10.1 in Debian in https://github.com/ottok/mariadb-10.1/commit/7d52f516e41f4af9cb5ec2eb97f6f35240914302
          danblack Daniel Black added a comment -

          For find, -uid $(id -u mysql) is equivalent to -user mysql.

          xargs has a --max-procs=max-procs which could be useful for parallelism of the changes.

          danblack Daniel Black added a comment - For find, -uid $(id -u mysql) is equivalent to -user mysql . xargs has a --max-procs=max-procs which could be useful for parallelism of the changes.

          People

            otto Otto Kekäläinen
            jb-boin Jean Weisbuch
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

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