Bug 34027 - Add functionality to cleanup_database.pl to purge action logs in batches
Summary: Add functionality to cleanup_database.pl to purge action logs in batches
Status: Signed Off
Alias: None
Product: Koha
Classification: Unclassified
Component: Command-line Utilities (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: Aleisha Amohia
QA Contact: Kyle M Hall (khall)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-06-15 22:22 UTC by Aleisha Amohia
Modified: 2024-10-08 18:56 UTC (History)
4 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
Bug 34027: Add functionality to cleanup_database.pl to purge action logs in batches (4.79 KB, patch)
2023-06-16 02:12 UTC, Aleisha Amohia
Details | Diff | Splinter Review
Bug 34027: DO NOT PUSH!!!! Test data for KTD (1.04 KB, patch)
2023-06-16 02:12 UTC, Aleisha Amohia
Details | Diff | Splinter Review
Bug 34027: Add functionality to cleanup_database.pl to purge action logs in batches (4.88 KB, patch)
2024-06-04 16:32 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 34027: DO NOT PUSH!!!! Test data for KTD (1.04 KB, patch)
2024-06-04 16:32 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 34027: Add functionality to cleanup_database.pl to purge action logs in batches (4.94 KB, patch)
2024-06-04 18:23 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 34027: (QA follow-up) Slight logic improvement (1.95 KB, patch)
2024-06-04 18:23 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 34027: DO NOT PUSH!!!! Test data for KTD (1.04 KB, patch)
2024-06-04 18:23 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 34027: (follow-up) Make sleep seconds a command-line param (3.19 KB, patch)
2024-10-08 02:22 UTC, Aleisha Amohia
Details | Diff | Splinter Review
Bug 34027: Add functionality to cleanup_database.pl to purge action logs in batches (5.01 KB, patch)
2024-10-08 18:00 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 34027: (QA follow-up) Slight logic improvement (2.02 KB, patch)
2024-10-08 18:00 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 34027: DO NOT PUSH!!!! Test data for KTD (1.11 KB, patch)
2024-10-08 18:00 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 34027: (follow-up) Make sleep seconds a command-line param (3.26 KB, patch)
2024-10-08 18:00 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 34027: (QA follow-up) Tidy for qa script (975 bytes, patch)
2024-10-08 18:00 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Aleisha Amohia 2023-06-15 22:22:52 UTC
Some of our libraries did not have the --logs argument in place for cleanup_database.pl and their action logs tables have grown very large (millions of rows) and taking up lots of space on the disk.

We need to be able to clear these logs incrementally (in batches), as the sheer size of the delete query has overloaded the server.
Comment 1 Aleisha Amohia 2023-06-16 02:12:42 UTC
Created attachment 152394 [details] [review]
Bug 34027: Add functionality to cleanup_database.pl to purge action logs in batches

This enhancement gives libraries the option to purge action logs 'slowly', in batches. This is useful for when there are many, many rows to purge (i.e. millions).

To test, set up some sample logs (you'll need to change the timestamp in the database so they are picked up by the cronjob), run the cleanup_database.pl script with the --logs parameter and confirm it behaves as expected.

For example:

sudo koha-foreach --chdir --enabled /kohadevbox/koha/misc/cronjobs/cleanup_database.pl --confirm --logs 1 --logs-batch 500 --verbose

Test cases:

1. logs argument, no logs-batch argument. Cleanup should run as normal, in one query.

sudo koha-foreach --chdir --enabled /kohadevbox/koha/misc/cronjobs/cleanup_database.pl --confirm --logs 1 --verbose

2. logs argument, logs-batch argument with no ROWS specified. logs-batch should default to 1000, deletions done in batches of 1000 rows at a time.

sudo koha-foreach --chdir --enabled /kohadevbox/koha/misc/cronjobs/cleanup_database.pl --confirm --logs 1 --logs-batch --verbose

3. logs argument, logs-batch argument with ROWS specified. Deletions should be done in batches of the specified ROWS

sudo koha-foreach --chdir --enabled /kohadevbox/koha/misc/cronjobs/cleanup_database.pl --confirm --logs 1 --logs-batch 500 --verbose

Sponsored-by: Auckland University of Technology
Comment 2 Aleisha Amohia 2023-06-16 02:12:45 UTC
Created attachment 152395 [details] [review]
Bug 34027: DO NOT PUSH!!!! Test data for KTD

This is to add some test action logs to your database. DO NOT PUSH.
Comment 3 Liz Rea 2023-06-16 21:16:35 UTC
omg yes. I love this.
Comment 4 Martin Renvoize (ashimema) 2024-06-04 16:32:13 UTC
Created attachment 167407 [details] [review]
Bug 34027: Add functionality to cleanup_database.pl to purge action logs in batches

This enhancement gives libraries the option to purge action logs 'slowly', in batches. This is useful for when there are many, many rows to purge (i.e. millions).

To test, set up some sample logs (you'll need to change the timestamp in the database so they are picked up by the cronjob), run the cleanup_database.pl script with the --logs parameter and confirm it behaves as expected.

For example:

sudo koha-foreach --chdir --enabled /kohadevbox/koha/misc/cronjobs/cleanup_database.pl --confirm --logs 1 --logs-batch 500 --verbose

Test cases:

1. logs argument, no logs-batch argument. Cleanup should run as normal, in one query.

sudo koha-foreach --chdir --enabled /kohadevbox/koha/misc/cronjobs/cleanup_database.pl --confirm --logs 1 --verbose

2. logs argument, logs-batch argument with no ROWS specified. logs-batch should default to 1000, deletions done in batches of 1000 rows at a time.

sudo koha-foreach --chdir --enabled /kohadevbox/koha/misc/cronjobs/cleanup_database.pl --confirm --logs 1 --logs-batch --verbose

3. logs argument, logs-batch argument with ROWS specified. Deletions should be done in batches of the specified ROWS

sudo koha-foreach --chdir --enabled /kohadevbox/koha/misc/cronjobs/cleanup_database.pl --confirm --logs 1 --logs-batch 500 --verbose

Sponsored-by: Auckland University of Technology
Comment 5 Martin Renvoize (ashimema) 2024-06-04 16:32:15 UTC
Created attachment 167408 [details] [review]
Bug 34027: DO NOT PUSH!!!! Test data for KTD

This is to add some test action logs to your database. DO NOT PUSH.
Comment 6 Martin Renvoize (ashimema) 2024-06-04 16:32:28 UTC
Rebased
Comment 7 Martin Renvoize (ashimema) 2024-06-04 18:23:41 UTC
Created attachment 167412 [details] [review]
Bug 34027: Add functionality to cleanup_database.pl to purge action logs in batches

This enhancement gives libraries the option to purge action logs 'slowly', in batches. This is useful for when there are many, many rows to purge (i.e. millions).

To test, set up some sample logs (you'll need to change the timestamp in the database so they are picked up by the cronjob), run the cleanup_database.pl script with the --logs parameter and confirm it behaves as expected.

For example:

sudo koha-foreach --chdir --enabled /kohadevbox/koha/misc/cronjobs/cleanup_database.pl --confirm --logs 1 --logs-batch 500 --verbose

Test cases:

1. logs argument, no logs-batch argument. Cleanup should run as normal, in one query.

sudo koha-foreach --chdir --enabled /kohadevbox/koha/misc/cronjobs/cleanup_database.pl --confirm --logs 1 --verbose

2. logs argument, logs-batch argument with no ROWS specified. logs-batch should default to 1000, deletions done in batches of 1000 rows at a time.

sudo koha-foreach --chdir --enabled /kohadevbox/koha/misc/cronjobs/cleanup_database.pl --confirm --logs 1 --logs-batch --verbose

3. logs argument, logs-batch argument with ROWS specified. Deletions should be done in batches of the specified ROWS

sudo koha-foreach --chdir --enabled /kohadevbox/koha/misc/cronjobs/cleanup_database.pl --confirm --logs 1 --logs-batch 500 --verbose

Sponsored-by: Auckland University of Technology
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 8 Martin Renvoize (ashimema) 2024-06-04 18:23:43 UTC
Created attachment 167413 [details] [review]
Bug 34027: (QA follow-up) Slight logic improvement

This patch updates the loop to optimize the limit handling

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 9 Martin Renvoize (ashimema) 2024-06-04 18:23:46 UTC
Created attachment 167414 [details] [review]
Bug 34027: DO NOT PUSH!!!! Test data for KTD

This is to add some test action logs to your database. DO NOT PUSH.
Comment 10 Martin Renvoize (ashimema) 2024-06-04 18:24:48 UTC
Signing off as it all appears to work as expected.

I wonder slightly about the choice of sleep number.. do we really need to sleep for 3 seconds?
Comment 11 Aleisha Amohia 2024-06-04 20:58:06 UTC
(In reply to Martin Renvoize from comment #10)
> Signing off as it all appears to work as expected.
> 
> I wonder slightly about the choice of sleep number.. do we really need to
> sleep for 3 seconds?

I suppose not! It was a randomly chosen number as a precaution.
Comment 12 Kyle M Hall (khall) 2024-10-07 14:00:42 UTC
> > I wonder slightly about the choice of sleep number.. do we really need to
> > sleep for 3 seconds?
> 
> I suppose not! It was a randomly chosen number as a precaution.

If the number is arbitrary, can you please make it configurable via another command line option?

Thanks!
Comment 13 Aleisha Amohia 2024-10-08 02:22:07 UTC
Created attachment 172506 [details] [review]
Bug 34027: (follow-up) Make sleep seconds a command-line param

Use --logs-sleep SECONDS to specify how many seconds Koha should wait between batches when deleting action logs.

Defaults to 3

Sponsored-by: Auckland University of Technology
Sponsored-by: Catalyst IT
Comment 14 Kyle M Hall (khall) 2024-10-08 18:00:24 UTC
Created attachment 172543 [details] [review]
Bug 34027: Add functionality to cleanup_database.pl to purge action logs in batches

This enhancement gives libraries the option to purge action logs 'slowly', in batches. This is useful for when there are many, many rows to purge (i.e. millions).

To test, set up some sample logs (you'll need to change the timestamp in the database so they are picked up by the cronjob), run the cleanup_database.pl script with the --logs parameter and confirm it behaves as expected.

For example:

sudo koha-foreach --chdir --enabled /kohadevbox/koha/misc/cronjobs/cleanup_database.pl --confirm --logs 1 --logs-batch 500 --verbose

Test cases:

1. logs argument, no logs-batch argument. Cleanup should run as normal, in one query.

sudo koha-foreach --chdir --enabled /kohadevbox/koha/misc/cronjobs/cleanup_database.pl --confirm --logs 1 --verbose

2. logs argument, logs-batch argument with no ROWS specified. logs-batch should default to 1000, deletions done in batches of 1000 rows at a time.

sudo koha-foreach --chdir --enabled /kohadevbox/koha/misc/cronjobs/cleanup_database.pl --confirm --logs 1 --logs-batch --verbose

3. logs argument, logs-batch argument with ROWS specified. Deletions should be done in batches of the specified ROWS

sudo koha-foreach --chdir --enabled /kohadevbox/koha/misc/cronjobs/cleanup_database.pl --confirm --logs 1 --logs-batch 500 --verbose

Sponsored-by: Auckland University of Technology
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 15 Kyle M Hall (khall) 2024-10-08 18:00:46 UTC
Created attachment 172544 [details] [review]
Bug 34027: (QA follow-up) Slight logic improvement

This patch updates the loop to optimize the limit handling

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 16 Kyle M Hall (khall) 2024-10-08 18:00:48 UTC
Created attachment 172545 [details] [review]
Bug 34027: DO NOT PUSH!!!! Test data for KTD

This is to add some test action logs to your database. DO NOT PUSH.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 17 Kyle M Hall (khall) 2024-10-08 18:00:50 UTC
Created attachment 172546 [details] [review]
Bug 34027: (follow-up) Make sleep seconds a command-line param

Use --logs-sleep SECONDS to specify how many seconds Koha should wait between batches when deleting action logs.

Defaults to 3

Sponsored-by: Auckland University of Technology
Sponsored-by: Catalyst IT

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 18 Kyle M Hall (khall) 2024-10-08 18:00:52 UTC
Created attachment 172547 [details] [review]
Bug 34027: (QA follow-up) Tidy for qa script

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>