diff options
author | Sergei Golubchik <sergii@pisem.net> | 2010-11-25 18:17:28 +0100 |
---|---|---|
committer | Sergei Golubchik <sergii@pisem.net> | 2010-11-25 18:17:28 +0100 |
commit | 65ca700def99289cc31a7040537f5aa6e12bf485 (patch) | |
tree | 97b3a07299b626c519da0e80c122b5b79b933914 /mysql-test/suite/sphinx/suite.pm | |
parent | 2ab57de38d13d927ddff2d51aed4af34e13998f5 (diff) | |
parent | 6e5bcca7935d3c62f84bb640e5357664a210ee12 (diff) | |
download | mariadb-git-65ca700def99289cc31a7040537f5aa6e12bf485.tar.gz |
merge.
checkpoint.
does not compile.
Diffstat (limited to 'mysql-test/suite/sphinx/suite.pm')
-rw-r--r-- | mysql-test/suite/sphinx/suite.pm | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/mysql-test/suite/sphinx/suite.pm b/mysql-test/suite/sphinx/suite.pm new file mode 100644 index 00000000000..199e59e26d7 --- /dev/null +++ b/mysql-test/suite/sphinx/suite.pm @@ -0,0 +1,120 @@ +package My::Suite::Sphinx; + +use My::SafeProcess; +use My::File::Path; +use mtr_report; + +@ISA = qw(My::Suite); + +use Carp; +$Carp::Verbose=1; + +############# initialization ###################### +sub locate_sphinx_binary { + my ($name)= @_; + my $res; + my @list= map "$_/$name", split /:/, $ENV{PATH}; + my $env_override= $ENV{"SPHINXSEARCH_\U$name"}; + @list= ($env_override) if $env_override; + for (@list) { return $_ if -x $_; } +} + +# Look for Sphinx binaries. +my $exe_sphinx_indexer = &locate_sphinx_binary('indexer'); +my $exe_sphinx_searchd = &locate_sphinx_binary('searchd'); + +return "No Sphinx" unless $exe_sphinx_indexer and $exe_sphinx_searchd; +return "No SphinxSE" unless $ENV{HA_SPHINX_SO} or + $::mysqld_variables{'sphinx'} eq "ON"; + +{ + local $_ = `"$exe_sphinx_searchd" --help`; + my $ver = sprintf "%04d.%04d.%04d", (/([0-9]+)\.([0-9]+)\.([0-9]+)/); + return "Sphinx 0.9.9 or later is needed" unless $ver ge '0000.0009.0009'; +} + +############# action methods ###################### + +sub write_sphinx_conf { + my ($config) = @_; # My::Config + my $res; + + foreach my $group ($config->groups()) { + my $name= $group->{name}; + # Only the ones relevant to Sphinx search. + next unless ($name eq 'indexer' or $name eq 'searchd' or + $name =~ /^(source|index) \w+$/); + $res .= "$name\n{\n"; + foreach my $option ($group->options()) { + $res .= $option->name(); + my $value= $option->value(); + if (defined $value) { + $res .= "=$value"; + } + $res .= "\n"; + } + $res .= "}\n\n"; + } + $res; +} + +sub searchd_start { + my ($sphinx, $test) = @_; # My::Config::Group, My::Test + + return unless $exe_sphinx_indexer and $exe_sphinx_searchd; + + # First we must run the indexer to create the data. + my $sphinx_data_dir= "$::opt_vardir/" . $sphinx->name(); + mkpath($sphinx_data_dir); + my $sphinx_log= $sphinx->value('#log-error'); + my $sphinx_config= "$::opt_vardir/my_sphinx.conf"; + my $cmd= "\"$exe_sphinx_indexer\" --config \"$sphinx_config\" test1 > \"$sphinx_log\" 2>&1"; + &::mtr_verbose("cmd: $cmd"); + system $cmd; + + # Then start the searchd daemon. + my $args; + &::mtr_init_args(\$args); + &::mtr_add_arg($args, "--config"); + &::mtr_add_arg($args, $sphinx_config); + &::mtr_add_arg($args, "--console"); + &::mtr_add_arg($args, "--pidfile"); + + $sphinx->{'proc'}= My::SafeProcess->new + ( + name => 'sphinx-' . $sphinx->name(), + path => $exe_sphinx_searchd, + args => \$args, + output => $sphinx_log, + error => $sphinx_log, + append => 1, + nocore => 1, + ); + &::mtr_verbose("Started $sphinx->{proc}"); +} + +sub searchd_wait { + my ($sphinx) = @_; # My::Config::Group + + return not &::sleep_until_file_created($sphinx->value('pid_file'), 20, + $sphinx->{'proc'}) +} + +############# declaration methods ###################### + +sub config_files() { + ( 'my_sphinx.conf' => \&write_sphinx_conf ) +} + +sub servers { + ( qr/^searchd$/ => { + SORT => 400, + START => \&searchd_start, + WAIT => \&searchd_wait, + } + ) +} + +############# return an object ###################### +bless { }; + |