pt-online-schema-change 参数 critical-load 的使用

由于使用了 Tokudb 引擎的分区表,修改单表时,open数都会超1k。并发pt修改加上触发的analyze操作,会导致open file 超限。因此,希望通过设置 critical-load 参数,当 TOKUDB_DB_OPEN_CURRENT 状态超过4W时,就让pt任务直接结束。

尝试的执行:

pt-online-schema-change –host=xxx –port=3306 –user=xxx –password=xxx –alter=”add column test9 varchar(50) not null” D=bfune_db_zjww1a_ahd2017,t=tmp_test –print –execute –no-version-check –alter-foreign-keys-method=none –force –charset=utf8 –critical-load TOKUDB_DB_OPEN_CURRENT=40000

结果发现参数不起作用。

参看源码,发现,pt 先检查 max-load,如果 max-load 没有设置,直接就过了。
如果设置了 max-load,同时 critical-load也设置了相同 status name 的限制,那么,当 status 的值超过 critical-load 的值时,pt就可以主动结束。

sub wait {
   my ( $self, %args ) = @_;

   return unless $self->{max_val_for};

   my $pr = $args{Progress}; # optional

   my $oktorun    = $self->{oktorun};
   my $get_status = $self->{get_status};
   my $sleep      = $self->{sleep};

   my %vals_too_high = %{$self->{max_val_for}};
   my $pr_callback;
   if ( $pr ) {
      $pr_callback = sub {
         print STDERR "Pausing because "
            . join(', ',
                 map {
                    "$_="
                    . (defined $vals_too_high{$_} ? $vals_too_high{$_}
                                                  : 'unknown')
                 } sort keys %vals_too_high
              )
            . ".\n";
         return;
      };
      $pr->set_callback($pr_callback);
   }

   while ( $oktorun->() ) {
      PTDEBUG && _d('Checking status variables');
      foreach my $var ( sort keys %vals_too_high ) {
         my $val = $get_status->($var);
         PTDEBUG && _d($var, '=', $val);
         if ( $val
              && exists $self->{critical_val_for}->{$var}
              && $val >= $self->{critical_val_for}->{$var} ) {
            die "$var=$val exceeds its critical threshold "
               . "$self->{critical_val_for}->{$var}\n";
         }
         if ( $val >= $self->{max_val_for}->{$var} ) {
            $vals_too_high{$var} = $val;
         }
         else {
            delete $vals_too_high{$var};
         }
      }

因此,修改执行参数为:

pt-online-schema-change –host=xxx –port=3306 –user=xxx –password=xxx –alter=”add column test9 varchar(50) not null default ” comment ‘商品核对码’” D=bfune_db_zjww1a_ahd2017,t=tmp_test –print –execute –no-version-check –alter-foreign-keys-method=none –force –charset=utf8 –max-load TOKUDB_DB_OPEN_CURRENT=40000 –critical-load TOKUDB_DB_OPEN_CURRENT=40000

OK, have fun.

你可能感兴趣的:(MySQL)