mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-10 13:11:32 +00:00
Add lock_in_share_mode option to NibbleIterator. Silence query_table.pl diag messages.
This commit is contained in:
@@ -5021,6 +5021,7 @@ sub new {
|
|||||||
: join(', ', map { $q->quote($_) } @cols))
|
: join(', ', map { $q->quote($_) } @cols))
|
||||||
. " FROM $tbl->{name}"
|
. " FROM $tbl->{name}"
|
||||||
. ($where ? " WHERE $where" : '')
|
. ($where ? " WHERE $where" : '')
|
||||||
|
. ($args{lock_in_share_mode} ? " LOCK IN SHARE MODE" : "")
|
||||||
. " /*$comments{bite}*/";
|
. " /*$comments{bite}*/";
|
||||||
PTDEBUG && _d('One nibble statement:', $nibble_sql);
|
PTDEBUG && _d('One nibble statement:', $nibble_sql);
|
||||||
|
|
||||||
@@ -5030,6 +5031,7 @@ sub new {
|
|||||||
: join(', ', map { $q->quote($_) } @cols))
|
: join(', ', map { $q->quote($_) } @cols))
|
||||||
. " FROM $tbl->{name}"
|
. " FROM $tbl->{name}"
|
||||||
. ($where ? " WHERE $where" : '')
|
. ($where ? " WHERE $where" : '')
|
||||||
|
. ($args{lock_in_share_mode} ? " LOCK IN SHARE MODE" : "")
|
||||||
. " /*explain $comments{bite}*/";
|
. " /*explain $comments{bite}*/";
|
||||||
PTDEBUG && _d('Explain one nibble statement:', $explain_nibble_sql);
|
PTDEBUG && _d('Explain one nibble statement:', $explain_nibble_sql);
|
||||||
|
|
||||||
@@ -5113,6 +5115,7 @@ sub new {
|
|||||||
. " AND " . $asc->{boundaries}->{'<='} # upper boundary
|
. " AND " . $asc->{boundaries}->{'<='} # upper boundary
|
||||||
. ($where ? " AND ($where)" : '')
|
. ($where ? " AND ($where)" : '')
|
||||||
. ($args{order_by} ? " ORDER BY $order_by" : "")
|
. ($args{order_by} ? " ORDER BY $order_by" : "")
|
||||||
|
. ($args{lock_in_share_mode} ? " LOCK IN SHARE MODE" : "")
|
||||||
. " /*$comments{nibble}*/";
|
. " /*$comments{nibble}*/";
|
||||||
PTDEBUG && _d('Nibble statement:', $nibble_sql);
|
PTDEBUG && _d('Nibble statement:', $nibble_sql);
|
||||||
|
|
||||||
@@ -5125,6 +5128,7 @@ sub new {
|
|||||||
. " AND " . $asc->{boundaries}->{'<='} # upper boundary
|
. " AND " . $asc->{boundaries}->{'<='} # upper boundary
|
||||||
. ($where ? " AND ($where)" : '')
|
. ($where ? " AND ($where)" : '')
|
||||||
. ($args{order_by} ? " ORDER BY $order_by" : "")
|
. ($args{order_by} ? " ORDER BY $order_by" : "")
|
||||||
|
. ($args{lock_in_share_mode} ? " LOCK IN SHARE MODE" : "")
|
||||||
. " /*explain $comments{nibble}*/";
|
. " /*explain $comments{nibble}*/";
|
||||||
PTDEBUG && _d('Explain nibble statement:', $explain_nibble_sql);
|
PTDEBUG && _d('Explain nibble statement:', $explain_nibble_sql);
|
||||||
|
|
||||||
@@ -8581,6 +8585,7 @@ sub main {
|
|||||||
dml => $dml,
|
dml => $dml,
|
||||||
select => $select,
|
select => $select,
|
||||||
callbacks => $callbacks,
|
callbacks => $callbacks,
|
||||||
|
lock_in_share_mode => 1,
|
||||||
OptionParser => $o,
|
OptionParser => $o,
|
||||||
Quoter => $q,
|
Quoter => $q,
|
||||||
TableParser => $tp,
|
TableParser => $tp,
|
||||||
|
@@ -97,6 +97,7 @@ sub new {
|
|||||||
: join(', ', map { $q->quote($_) } @cols))
|
: join(', ', map { $q->quote($_) } @cols))
|
||||||
. " FROM $tbl->{name}"
|
. " FROM $tbl->{name}"
|
||||||
. ($where ? " WHERE $where" : '')
|
. ($where ? " WHERE $where" : '')
|
||||||
|
. ($args{lock_in_share_mode} ? " LOCK IN SHARE MODE" : "")
|
||||||
. " /*$comments{bite}*/";
|
. " /*$comments{bite}*/";
|
||||||
PTDEBUG && _d('One nibble statement:', $nibble_sql);
|
PTDEBUG && _d('One nibble statement:', $nibble_sql);
|
||||||
|
|
||||||
@@ -106,6 +107,7 @@ sub new {
|
|||||||
: join(', ', map { $q->quote($_) } @cols))
|
: join(', ', map { $q->quote($_) } @cols))
|
||||||
. " FROM $tbl->{name}"
|
. " FROM $tbl->{name}"
|
||||||
. ($where ? " WHERE $where" : '')
|
. ($where ? " WHERE $where" : '')
|
||||||
|
. ($args{lock_in_share_mode} ? " LOCK IN SHARE MODE" : "")
|
||||||
. " /*explain $comments{bite}*/";
|
. " /*explain $comments{bite}*/";
|
||||||
PTDEBUG && _d('Explain one nibble statement:', $explain_nibble_sql);
|
PTDEBUG && _d('Explain one nibble statement:', $explain_nibble_sql);
|
||||||
|
|
||||||
@@ -210,6 +212,7 @@ sub new {
|
|||||||
. " AND " . $asc->{boundaries}->{'<='} # upper boundary
|
. " AND " . $asc->{boundaries}->{'<='} # upper boundary
|
||||||
. ($where ? " AND ($where)" : '')
|
. ($where ? " AND ($where)" : '')
|
||||||
. ($args{order_by} ? " ORDER BY $order_by" : "")
|
. ($args{order_by} ? " ORDER BY $order_by" : "")
|
||||||
|
. ($args{lock_in_share_mode} ? " LOCK IN SHARE MODE" : "")
|
||||||
. " /*$comments{nibble}*/";
|
. " /*$comments{nibble}*/";
|
||||||
PTDEBUG && _d('Nibble statement:', $nibble_sql);
|
PTDEBUG && _d('Nibble statement:', $nibble_sql);
|
||||||
|
|
||||||
@@ -222,6 +225,7 @@ sub new {
|
|||||||
. " AND " . $asc->{boundaries}->{'<='} # upper boundary
|
. " AND " . $asc->{boundaries}->{'<='} # upper boundary
|
||||||
. ($where ? " AND ($where)" : '')
|
. ($where ? " AND ($where)" : '')
|
||||||
. ($args{order_by} ? " ORDER BY $order_by" : "")
|
. ($args{order_by} ? " ORDER BY $order_by" : "")
|
||||||
|
. ($args{lock_in_share_mode} ? " LOCK IN SHARE MODE" : "")
|
||||||
. " /*explain $comments{nibble}*/";
|
. " /*explain $comments{nibble}*/";
|
||||||
PTDEBUG && _d('Explain nibble statement:', $explain_nibble_sql);
|
PTDEBUG && _d('Explain nibble statement:', $explain_nibble_sql);
|
||||||
|
|
||||||
|
@@ -22,23 +22,31 @@ my $dbh = DBI->connect(
|
|||||||
{RaiseError => 1, AutoCommit => 0, ShowErrorStatement => 1, PrintError => 0},
|
{RaiseError => 1, AutoCommit => 0, ShowErrorStatement => 1, PrintError => 0},
|
||||||
);
|
);
|
||||||
|
|
||||||
$sleep ||= 0.01;
|
my $del_sql = "DELETE FROM $db.$tbl WHERE $pkcol=?";
|
||||||
|
my $ins_sql = "INSERT INTO $db.$tbl ($pkcol, c) VALUES (?, ?)";
|
||||||
|
my $upd_sql = "UPDATE $db.$tbl SET c=? WHERE $pkcol=?";
|
||||||
|
|
||||||
my $cnt = 0;
|
my $del_sth = $dbh->prepare($del_sql);
|
||||||
my (@del, %del);
|
my $ins_sth = $dbh->prepare($ins_sql);
|
||||||
my (@upd, %upd);
|
my $upd_sth = $dbh->prepare($upd_sql);
|
||||||
my (@ins, %ins);
|
|
||||||
|
$sleep ||= 0.01;
|
||||||
|
|
||||||
use constant TYPE_DELETE => 1;
|
use constant TYPE_DELETE => 1;
|
||||||
use constant TYPE_UPDATE => 2;
|
use constant TYPE_UPDATE => 2;
|
||||||
|
|
||||||
sub new_transaction {
|
my (@del, %del);
|
||||||
|
my (@upd, %upd);
|
||||||
|
my (@ins, %ins);
|
||||||
|
my $cnt = 0;
|
||||||
|
my $id = 0;
|
||||||
|
my $type = 0;
|
||||||
|
|
||||||
|
sub reset_counters {
|
||||||
@del = ();
|
@del = ();
|
||||||
@ins = ();
|
@ins = ();
|
||||||
@upd = ();
|
@upd = ();
|
||||||
$cnt = 0;
|
$cnt = 0;
|
||||||
|
|
||||||
$dbh->do("START TRANSACTION /*!40108 WITH CONSISTENT SNAPSHOT */");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub commit {
|
sub commit {
|
||||||
@@ -46,61 +54,65 @@ sub commit {
|
|||||||
$dbh->commit;
|
$dbh->commit;
|
||||||
};
|
};
|
||||||
if ( $EVAL_ERROR ) {
|
if ( $EVAL_ERROR ) {
|
||||||
Test::More::diag($EVAL_ERROR);
|
#Test::More::diag($EVAL_ERROR);
|
||||||
|
#Test::More::diag("lost deleted: @del");
|
||||||
|
#Test::More::diag("lost updated: @upd");
|
||||||
|
#Test::More::diag("lost inserted: @ins");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
map { $del{$_}++ } @del;
|
map { $del{$_}++ } @del;
|
||||||
map { $ins{$_}++ } @ins;
|
map { $ins{$_}++ } @ins;
|
||||||
map { $upd{$_}++ } @upd;
|
map { $upd{$_}++ } @upd;
|
||||||
}
|
}
|
||||||
new_transaction();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
new_transaction(); # first transaction
|
$dbh->do("START TRANSACTION");
|
||||||
|
|
||||||
for my $i ( 1..5_000 ) {
|
for my $i ( 1..5_000 ) {
|
||||||
last if -f $stop_file;
|
last if -f $stop_file;
|
||||||
my $id = 0;
|
|
||||||
my $type = '';
|
|
||||||
eval {
|
eval {
|
||||||
# We do roughly 25% DELETE, 25% UPDATE and 50% INSERT.
|
my $type = int(rand(5)); # roughly 25% DELETE, 25% UPDATE, 50% INSERT
|
||||||
my $type = int(rand(5));
|
|
||||||
if ($type == TYPE_DELETE) {
|
if ( $type == TYPE_DELETE ) {
|
||||||
$id = int(rand(500)) || 1;
|
$id = int(rand(500)) || 1;
|
||||||
$dbh->do("delete from $db.$tbl where $pkcol=$id");
|
$del_sth->execute($id);
|
||||||
# To challenge the tool, we *do* (or can) delete the same id twice.
|
push @del, $id if $del_sth->rows;
|
||||||
# But to keep the numbers straight, we only record each deleted
|
|
||||||
# id once.
|
|
||||||
push @del, $id;
|
|
||||||
}
|
}
|
||||||
elsif ($type == TYPE_UPDATE) {
|
elsif ( $type == TYPE_UPDATE ) {
|
||||||
$id = int(rand(500)) || 1;
|
$id = int(rand(500)) || 1;
|
||||||
# Update a row if we haven't already deleted it.
|
if ( !$del{$id} && ($id <= 500 || $ins{$id}) ) {
|
||||||
if ( !$del{$id} ) {
|
my $t = time;
|
||||||
my $t=time;
|
$upd_sth->execute("updated row $t", $id);
|
||||||
$dbh->do("update $db.$tbl set c='updated row $t' where $pkcol=$id");
|
|
||||||
push @upd, $id;
|
push @upd, $id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else { # INSERT
|
||||||
$id = 500 + $i;
|
$id = 500 + $i;
|
||||||
my $t = time;
|
my $t = time;
|
||||||
$dbh->do("insert ignore into $db.$tbl ($pkcol, c) values ($id, 'new row $t')");
|
$ins_sth->execute($id, "new row $t");
|
||||||
push @ins, $id;
|
push @ins, $id;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if ( $EVAL_ERROR ) {
|
if ( $EVAL_ERROR ) {
|
||||||
Test::More::diag($EVAL_ERROR);
|
#Test::More::diag($EVAL_ERROR);
|
||||||
new_transaction();
|
#Test::More::diag("lost deleted: @del");
|
||||||
|
#Test::More::diag("lost updated: @upd");
|
||||||
|
#Test::More::diag("lost inserted: @ins");
|
||||||
|
reset_counters();
|
||||||
|
sleep $sleep;
|
||||||
|
$dbh->do("START TRANSACTION");
|
||||||
}
|
}
|
||||||
|
|
||||||
# COMMIT every N statements. With PXC this can fail.
|
# COMMIT every N statements. With PXC this can fail.
|
||||||
if ( $cnt++ > 5 ) {
|
if ( ++$cnt >= 5 ) {
|
||||||
commit();
|
commit();
|
||||||
new_transaction();
|
reset_counters();
|
||||||
|
sleep $sleep;
|
||||||
|
$dbh->do("START TRANSACTION");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sleep 0.001;
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep($sleep);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
commit();
|
commit();
|
||||||
|
Reference in New Issue
Block a user