wsrep_sst_xtrabackup-v2 not deleting all folders on cleanup

Description

wsrep_sst_xtrabackup-v2 uses mktemp to create temporary directories. It makes calls such as below:

itmpdir=$(mktemp -p "${tmpdirbase}" -dt donor_xb_XXXX)

It issues mktemp passing -t option. From src/mktemp.c file:

while ((c = getopt_long (argc, argv, "dp:qtuV", longopts, NULL)) != -1) { switch (c) { . . . case 't': use_dest_dir = true; deprecated_t_option = true; break; . . . } } . . . if (deprecated_t_option) { char *env = getenv ("TMPDIR"); if (env && *env) dest_dir = env; else if (dest_dir_arg && *dest_dir_arg) dest_dir = dest_dir_arg; else dest_dir = "/tmp"; if (last_component (template) != template) die (EXIT_FAILURE, 0, _("invalid template, %s, contains directory separator"), quote (template)); }

This means if TMPDIR is set, it will take precedence over directory passed by -p option. When wsrep_sst_xtrabackup-v2 calls cleanup it only removes tmpdirbase

cleanup_donor() { . . . if [[ -n "${tmpdirbase}" ]]; then [[ -d "${tmpdirbase}" ]] && rm -rf "${tmpdirbase}" || true fi . . . }

But as files have been created on whatever is set as TMPDIR they will never get removed.

See below example:

[root@localhost ~]# export TMPDIR=/tmp [root@localhost tmp]# mktemp -p /tmp -dt sst_XXXX /tmp/sst_2TXI [root@localhost tmp]# mktemp -p /tmp/sst_2TXI -dt joiner_XXXX /tmp/joiner_FVsH

joiner folder got created at /tmp/joiner_FVsH while the script expects it to be created at /tmp/sst_2TXI/joiner_FVsH

Environment

None

AFFECTED CS IDs

230198

Smart Checklist

Activity

Show:

KennT July 10, 2018 at 5:43 AM

commit 8cb7dfd37ba1d54fec93e8ad1862a75b7d549e76
Merge: 712da48 0ff7bfe
Author: Krunal Bauskar <krunal.bauskar@percona.com>
Date: Fri Jul 6 09:22:56 2018 +0530

Merge pull request #678 from kennt-percona/5.7-pxc-2155

https://perconadev.atlassian.net/browse/PXC-2155#icft=PXC-2155 : wsrep_sst_xtrabackup-v2 not deleting all folders on cleanup

commit 0ff7bfe9448e09be9ab0f5e516bb0c3a24df04e2
Author: Kenn Takara <kenn.takara@percona.com>
Date: Wed Jul 4 01:49:59 2018 -0700

https://perconadev.atlassian.net/browse/PXC-2155#icft=PXC-2155 : wsrep_sst_xtrabackup-v2 not deleting all folders on cleanup

Issue
If the TMPDIR environment variable is set, that location was being
used as the root folder (rather than the folder specified by
the "-p" option). When the sst script exits, it deletes the root
folder, therefore the folders that were created in the TMPDIR were
not getting deleted.

Solution
Use the "--tmpdir" option explicitly instead of "-p" which was
deprecated. This makes it clearer where the tmp directores are
being created.

 

KennT July 3, 2018 at 11:27 PM

Good catch!

We should remove the "-t" option from all calls to mktemp().  Given our usage, this shouldn't cause a problem.  This should give us what we want, creating the directories where we expect them to be created.

Done

Details

Assignee

Reporter

Time tracking

1d 1h logged

Affects versions

Priority

Smart Checklist

Created July 3, 2018 at 10:29 PM
Updated March 6, 2024 at 10:30 PM
Resolved July 10, 2018 at 5:43 AM

Flag notifications