mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-10-19 08:56:34 +00:00
Fix SchemaIterator by replacing recursion with double nested while loops.
This commit is contained in:
@@ -334,13 +334,14 @@ sub _iterate_dbh {
|
||||
$self->{dbs} = \@dbs;
|
||||
}
|
||||
|
||||
DATABASE:
|
||||
while ( $self->{db} || defined(my $db = shift @{$self->{dbs}}) ) {
|
||||
if ( !$self->{db} ) {
|
||||
$self->{db} = shift @{$self->{dbs}};
|
||||
PTDEBUG && _d('Next database:', $self->{db});
|
||||
return unless $self->{db};
|
||||
PTDEBUG && _d('Next database:', $db);
|
||||
$self->{db} = $db;
|
||||
}
|
||||
|
||||
if ( !defined $self->{tbls} ) {
|
||||
if ( !$self->{tbls} ) {
|
||||
my $sql = 'SHOW /*!50002 FULL*/ TABLES FROM ' . $q->quote($self->{db});
|
||||
PTDEBUG && _d($sql);
|
||||
my @tbls = map {
|
||||
@@ -353,10 +354,11 @@ sub _iterate_dbh {
|
||||
&& $self->table_is_allowed($self->{db}, $tbl);
|
||||
}
|
||||
@{$dbh->selectall_arrayref($sql)};
|
||||
PTDEBUG && _d('Found', scalar @tbls, 'tables in database', $self->{db});
|
||||
PTDEBUG && _d('Found', scalar @tbls, 'tables in database',$self->{db});
|
||||
$self->{tbls} = \@tbls;
|
||||
}
|
||||
|
||||
TABLE:
|
||||
while ( my $tbl = shift @{$self->{tbls}} ) {
|
||||
my $ddl = eval { $tp->get_create_table($dbh, $self->{db}, $tbl) };
|
||||
if ( my $e = $EVAL_ERROR ) {
|
||||
@@ -366,13 +368,14 @@ sub _iterate_dbh {
|
||||
# do about it; If the table is missing, just PTDEBUG it, but
|
||||
# otherwise, warn with the error.
|
||||
if ( $e =~ /\QTable '$table_name' doesn't exist/ ) {
|
||||
PTDEBUG && _d("Skipping $table_name because it no longer exists");
|
||||
PTDEBUG && _d("$table_name no longer exists");
|
||||
}
|
||||
else {
|
||||
warn "Skipping $table_name because SHOW CREATE TABLE failed: $e";
|
||||
}
|
||||
next;
|
||||
next TABLE;
|
||||
}
|
||||
|
||||
my $tbl_struct = $tp->parse($ddl);
|
||||
if ( $self->engine_is_allowed($tbl_struct->{engine}) ) {
|
||||
return {
|
||||
@@ -388,10 +391,10 @@ sub _iterate_dbh {
|
||||
PTDEBUG && _d('No more tables in database', $self->{db});
|
||||
$self->{db} = undef;
|
||||
$self->{tbls} = undef;
|
||||
} # DATABASE
|
||||
|
||||
# Recurse to get the next database. If there's no next db, then the
|
||||
# call will return undef and we'll return undef, too.
|
||||
return $self->_iterate_dbh();
|
||||
PTDEBUG && _d('No more databases');
|
||||
return;
|
||||
}
|
||||
|
||||
sub database_is_allowed {
|
||||
|
Reference in New Issue
Block a user