Merge lp:~percona-toolkit-dev/percona-toolkit/pt-heartbeat-check-read-only-option-does-not-prevent-creates-or-inserts-1328686 into lp:~percona-toolkit-dev/percona-toolkit/release-2.2.12

Proposed by Frank Cizmich
Status: Merged
Merged at revision: 636
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/pt-heartbeat-check-read-only-option-does-not-prevent-creates-or-inserts-1328686
Merge into: lp:~percona-toolkit-dev/percona-toolkit/release-2.2.12
Diff against target: 36 lines (+26/-0)
1 file modified
bin/pt-heartbeat (+26/-0)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/pt-heartbeat-check-read-only-option-does-not-prevent-creates-or-inserts-1328686
Reviewer Review Type Date Requested Status
Daniel Nichter Needs Fixing
Review via email: mp+239767@code.launchpad.net

Description of the change

Problem:

Some users need to start pt-heartbeat on a server with read_only enabled, and enable writing at a later time.
The tool only checks for this after initializing tables and doing the first row insert, thus it fails if it begins to run on a read_only server.

Fix:
Before initializing, if --check-read-only and --update options are given, the tool waits for read_only to be disabled , checking at regular intervals.
--run-time is also honored, so if it is still waiting when run-time is reached, it exits.

To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Needs Fixing
630. By Frank Cizmich

Added check for sentinel file.

Revision history for this message
Frank Cizmich (frank-cizmich) wrote :

This duplicates some code, but trying to avoid that seems to complicate things too much.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/pt-heartbeat'
2--- bin/pt-heartbeat 2014-09-25 13:48:22 +0000
3+++ bin/pt-heartbeat 2014-11-06 17:05:49 +0000
4@@ -4892,6 +4892,32 @@
5 $dbh->do("USE `$db`");
6
7 # ########################################################################
8+ # If --check-read-only option was given and we are in --update mode
9+ # we wait until server is writable , or run-time is over, or sentinel file
10+ # We also do this check after daemon is up and running, but it is necessary
11+ # to check this before attempting to create the table and inserting rows
12+ # https://bugs.launchpad.net/percona-toolkit/+bug/1328686
13+ # #######################################################################
14+ if ( $o->get('check-read-only') && $o->get('update') ) {
15+ PTDEBUG && _d('Checking if server is read_only');
16+ if ( server_is_readonly($dbh) && PTDEBUG ) {
17+ _d('Server is read-only, waiting')
18+ }
19+ my $start_time = time;
20+ my $run_time = $o->get('run-time');
21+ my $interval = $o->get('interval') || 5;
22+ while (server_is_readonly($dbh)) {
23+ sleep($interval);
24+ if (
25+ ($run_time && $run_time < time - $start_time)
26+ || -f $sentinel
27+ ) {
28+ return 0;
29+ }
30+ }
31+ }
32+
33+ # ########################################################################
34 # Create the heartbeat table if --create-table was given.
35 # ########################################################################
36 my $utc = $o->get('utc');

Subscribers

People subscribed via source and target branches

to all changes: