pt-stalk omits trailing slash when deleting files in dest directory
Description
Environment
Smart Checklist
Activity
Lalit Choudhary January 11, 2022 at 3:06 PM
@Siml, Jan [ PLUSLINE.NET ]
Issue fixed as part of https://perconadev.atlassian.net/browse/PT-1336#icft=PT-1336
Now it shows the correct path for deletion and files were also deleted from the mentioned location.
Fixed version test:
$ ./pt-stalk --version
pt-stalk 3.3.2
$ sudo ./pt-stalk --no-stalk --retention-size=1536 --retention-count=2 --mysql-only --sleep=30 --user=msandbox --password=msandbox --socket=/tmp/mysql_sandbox8023.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
2022_01_11_20_26_00 Starting ./pt-stalk --function=status --variable=Threads_running --threshold=25 --match= --cycles=0 --interval=1 --iterations= --run-time=30 --sleep=30 --dest=/var/lib/pt-stalk --prefix= --notify-by-email= --log=/var/log/pt-stalk.log --pid=/var/run/pt-stalk.pid --plugin=
2022_01_11_20_26_00 Not stalking; collect triggered immediately
2022_01_11_20_26_00 Collect 1 triggered
2022_01_11_20_26_00 MYSQL_ONLY: yes
2022_01_11_20_26_00 Collect 1 PID 20641
deleting files /var/lib/pt-stalk/2022_01_11_20_24_37* according to the --retention-count param
deleting files /var/lib/pt-stalk/2022_01_11_20_24_07* according to the --retention-count param
2022_01_11_20_26_01 Collect 1 done
2022_01_11_20_26_01 Sleeping 30 seconds after collect
2022_01_11_20_26_31 Not stalking; collect triggered immediately
2022_01_11_20_26_31 Collect 2 triggered
2022_01_11_20_26_31 MYSQL_ONLY: yes
2022_01_11_20_26_31 Collect 2 PID 23316
deleting files /var/lib/pt-stalk/2022_01_11_20_25_07* according to the --retention-count param
2022_01_11_20_26_31 Collect 2 done
2022_01_11_20_26_31 Sleeping 30 seconds after collect
2022_01_11_20_27_01 Not stalking; collect triggered immediately
2022_01_11_20_27_01 Collect 3 triggered
2022_01_11_20_27_01 MYSQL_ONLY: yes
2022_01_11_20_27_01 Collect 3 PID 25882
deleting files /var/lib/pt-stalk/2022_01_11_20_26_00* according to the --retention-count param
2022_01_11_20_27_01 Collect 3 done
Sveta Smirnova January 10, 2022 at 9:20 PM
@Lalit Choudhary I believe the fix for https://perconadev.atlassian.net/browse/PT-1336#icft=PT-1336 should fix this one also. Could you please check?
Lalit Choudhary March 3, 2020 at 7:48 AM
Hi Jan,
Thank you for the report and the reproduciable test case.
Verified as described.
$ sudo pt-stalk --no-stalk --retention-size=1536 --retention-count=2 --mysql-only --sleep=30 --user=msandbox --password=msandbox --socket=/tmp/mysql_sandbox5729.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
2020_03_03_13_12_07 Starting /usr/local/bin/pt-stalk --function=status --variable=Threads_running --threshold=25 --match= --cycles=0 --interval=1 --iterations= --run-time=30 --sleep=30 --dest=/var/lib/pt-stalk --prefix= --notify-by-email= --log=/var/log/pt-stalk.log --pid=/var/run/pt-stalk.pid --plugin=
2020_03_03_13_12_07 Not stalking; collect triggered immediately
2020_03_03_13_12_07 Collect 1 triggered
2020_03_03_13_12_07 MYSQL_ONLY: yes
2020_03_03_13_12_07 Collect 1 PID 29610
deleting files /var/lib/pt-stalk2020_03_03_13_06_00* according to the --retention-count param
2020_03_03_13_12_07 Collect 1 done
2020_03_03_13_12_07 Sleeping 30 seconds after collect
In my case files are getting deleted, only output has a missing trailing slash
Working case:
$ sudo pt-stalk --no-stalk --retention-size=1536 --retention-count=2 --mysql-only --sleep=30 --user=msandbox --password=msandbox --socket=/tmp/mysql_sandbox5729.sock --dest /var/lib/pt-stalk/
mysql: [Warning] Using a password on the command line interface can be insecure.
2020_03_03_13_13_17 Starting /usr/local/bin/pt-stalk --function=status --variable=Threads_running --threshold=25 --match= --cycles=0 --interval=1 --iterations= --run-time=30 --sleep=30 --dest=/var/lib/pt-stalk/ --prefix= --notify-by-email= --log=/var/log/pt-stalk.log --pid=/var/run/pt-stalk.pid --plugin=
2020_03_03_13_13_17 Not stalking; collect triggered immediately
2020_03_03_13_13_17 Collect 1 triggered
2020_03_03_13_13_17 MYSQL_ONLY: yes
2020_03_03_13_13_17 Collect 1 PID 3657
deleting files /var/lib/pt-stalk/2020_03_03_13_12_07* according to the --retention-count param
deleting files /var/lib/pt-stalk/2020_03_03_13_10_41* according to the --retention-count param
deleting files /var/lib/pt-stalk/2020_03_03_13_06_00* according to the --retention-count param
2020_03_03_13_13_17 Collect 1 done
2020_03_03_13_13_17 Sleeping 30 seconds after collect
Siml, Jan [ PLUSLINE.NET ] February 28, 2020 at 2:00 PM
$ pt-stalk --version
pt-stalk 3.1.0
$ cat /etc/centos-release
CentOS Linux release 7.7.1908 (Core)
Siml, Jan [ PLUSLINE.NET ] February 28, 2020 at 1:56 PM
Unfortunately I wasn't able to filly submit the bug report and I don't have permission to edit the description now. Therefore I will make full comment here and someone with appropriate permissions might add missing text to description.
pt-stalk forgets the trailing slash in the directory and therefore does not delete any files when using retention-size or retention-count.
Using the following parameters, pt-stalk will attempt to delete the files in the wrong location:
# pt-stalk --no-stalk --retention-size=1536 --retention-count=144 --mysql-only
...
deleting files /var/lib/pt-stalk2020_02_28_05_47_28* according to the --retention-size param
Note the missing trailing slash!
The same happens with setting --dest to default value (/var/lib/pt-stalk):
# pt-stalk --no-stalk --retention-size=1536 --retention-count=144 --dest /var/lib/pt-stalk --mysql-only
...
deleting files /var/lib/pt-stalk2020_02_28_05_47_28* according to the --retention-size param
But if the trailing slash is set explicitly, pt-stalk will delete the files in the correct location.
# pt-stalk --no-stalk --retention-size=1536 --retention-count=144 --dest /var/lib/pt-stalk/ --mysql-only
...
deleting files /var/lib/pt-stalk/2020_02_28_05_47_28* according to the --retention-size param
pt-stalk forgets the trailing slash in the directory and therefore does not delete any files when using retention-size or retention-count.
Using the following parameters, pt-stalk will attempt to delete the files in the wrong location:
# pt-stalk --no-stalk --retention-size=1536 --retention-count=144 --mysql-only