Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test failures on MariaDB performance_schema: OFF #965

Closed
junaruga opened this issue Apr 27, 2018 · 21 comments · Fixed by #1193
Closed

Test failures on MariaDB performance_schema: OFF #965

junaruga opened this issue Apr 27, 2018 · 21 comments · Fixed by #1193

Comments

@junaruga
Copy link
Contributor

I would report as I got 2 test failures on my local environment.

I tried it on current master latest branch (4a20d58).
Do you know what's wrong on my environment?

Thanks!

OS: Fedora 27
MariaDB 10.2
Ruby: 2.5.1

$ cat /etc/fedora-release 
Fedora release 27 (Twenty Seven)

$ rpm -q mariadb-devel mariadb-server
mariadb-devel-10.2.12-5.fc27.x86_64
mariadb-server-10.2.12-5.fc27.x86_64

Start MariaDB daemon.

$ sudo systemctl start mariadb
$ which mysql
/usr/bin/mysql

$ rpm -qf /usr/bin/mysql
mariadb-10.2.12-5.fc27.x86_64

$ mysql -u root -e 'CREATE DATABASE /*M!50701 IF NOT EXISTS */ test'

$ which ruby
/usr/local/ruby-2.5.1/bin/ruby

$ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]

$ which bundle
/usr/local/ruby-2.5.1/bin/bundle

$ bundle -v
Bundler version 1.16.1

$ bundle install --path vendor/bundle --without benchmarks development

$ bundle list
Gems included by the bundle:
  * ast (2.4.0)
  * bundler (1.16.1)
  * diff-lcs (1.3)
  * eventmachine (1.2.5)
  * mysql2 (0.5.1)
  * parallel (1.12.1)
  * parser (2.5.1.0)
  * powerpack (0.1.1)
  * rainbow (2.2.2)
  * rake (10.4.2)
  * rake-compiler (1.0.4)
  * rspec (3.7.0)
  * rspec-core (3.7.1)
  * rspec-expectations (3.7.0)
  * rspec-mocks (3.7.0)
  * rspec-support (3.7.1)
  * rubocop (0.50.0)
  * ruby-progressbar (1.9.0)
  * unicode-display_width (1.3.2)

Run unit tests.

$ bundle exec rake spec
mkdir -p tmp/x86_64-linux/mysql2/2.5.1
cd tmp/x86_64-linux/mysql2/2.5.1
/usr/local/ruby-2.5.1/bin/ruby -I. ../../../../ext/mysql2/extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_wait_for_single_fd()... yes
-----
Using mysql_config at /usr/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for SSL_MODE_DISABLED in mysql.h... no
checking for MYSQL_OPT_SSL_ENFORCE in mysql.h... yes
checking for MYSQL.net.vio in mysql.h... no
checking for MYSQL.net.pvio in mysql.h... yes
checking for MYSQL_ENABLE_CLEARTEXT_PLUGIN in mysql.h... yes
checking for SERVER_QUERY_NO_GOOD_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_NO_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_WAS_SLOW in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_ON in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_OFF in mysql.h... yes
checking for my_bool in mysql.h... yes
-----
Setting libpath to /usr/lib64/
-----
creating Makefile
cd -
cd tmp/x86_64-linux/mysql2/2.5.1
/usr/bin/gmake
compiling ../../../../ext/mysql2/client.c
../../../../ext/mysql2/client.c: In function ‘rb_set_ssl_mode_option’:
../../../../ext/mysql2/client.c:140:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
../../../../ext/mysql2/client.c: At top level:
cc1: warning: unrecognized command line option ‘-Wno-used-but-marked-unused’
cc1: warning: unrecognized command line option ‘-Wno-static-in-inline’
cc1: warning: unrecognized command line option ‘-Wno-reserved-id-macro’
cc1: warning: unrecognized command line option ‘-Wno-missing-variable-declarations’
cc1: warning: unrecognized command line option ‘-Wno-documentation-unknown-command’
cc1: warning: unrecognized command line option ‘-Wno-disabled-macro-expansion’
cc1: warning: unrecognized command line option ‘-Wno-covered-switch-default’
cc1: warning: unrecognized command line option ‘-Wno-conditional-uninitialized’
cc1: warning: unrecognized command line option ‘-Wno-self-assign’
cc1: warning: unrecognized command line option ‘-Wno-constant-logical-operand’
cc1: warning: unrecognized command line option ‘-Wno-parentheses-equality’
compiling ../../../../ext/mysql2/infile.c
compiling ../../../../ext/mysql2/mysql2_ext.c
compiling ../../../../ext/mysql2/result.c
compiling ../../../../ext/mysql2/statement.c
linking shared-object mysql2/mysql2.so
cd -
mkdir -p tmp/x86_64-linux/stage/lib/mysql2
cp CHANGELOG.md tmp/x86_64-linux/stage/CHANGELOG.md
cp LICENSE tmp/x86_64-linux/stage/LICENSE
cp README.md tmp/x86_64-linux/stage/README.md
mkdir -p tmp/x86_64-linux/stage/examples
cp examples/eventmachine.rb tmp/x86_64-linux/stage/examples/eventmachine.rb
cp examples/threaded.rb tmp/x86_64-linux/stage/examples/threaded.rb
mkdir -p tmp/x86_64-linux/stage/ext/mysql2
cp ext/mysql2/client.c tmp/x86_64-linux/stage/ext/mysql2/client.c
cp ext/mysql2/client.h tmp/x86_64-linux/stage/ext/mysql2/client.h
cp ext/mysql2/extconf.rb tmp/x86_64-linux/stage/ext/mysql2/extconf.rb
cp ext/mysql2/infile.c tmp/x86_64-linux/stage/ext/mysql2/infile.c
cp ext/mysql2/infile.h tmp/x86_64-linux/stage/ext/mysql2/infile.h
cp ext/mysql2/mysql2_ext.c tmp/x86_64-linux/stage/ext/mysql2/mysql2_ext.c
cp ext/mysql2/mysql2_ext.h tmp/x86_64-linux/stage/ext/mysql2/mysql2_ext.h
cp ext/mysql2/mysql_enc_name_to_ruby.h tmp/x86_64-linux/stage/ext/mysql2/mysql_enc_name_to_ruby.h
cp ext/mysql2/mysql_enc_to_ruby.h tmp/x86_64-linux/stage/ext/mysql2/mysql_enc_to_ruby.h
cp ext/mysql2/result.c tmp/x86_64-linux/stage/ext/mysql2/result.c
cp ext/mysql2/result.h tmp/x86_64-linux/stage/ext/mysql2/result.h
cp ext/mysql2/statement.c tmp/x86_64-linux/stage/ext/mysql2/statement.c
cp ext/mysql2/statement.h tmp/x86_64-linux/stage/ext/mysql2/statement.h
cp ext/mysql2/wait_for_single_fd.h tmp/x86_64-linux/stage/ext/mysql2/wait_for_single_fd.h
cp lib/mysql2.rb tmp/x86_64-linux/stage/lib/mysql2.rb
cp lib/mysql2/client.rb tmp/x86_64-linux/stage/lib/mysql2/client.rb
cp lib/mysql2/console.rb tmp/x86_64-linux/stage/lib/mysql2/console.rb
cp lib/mysql2/em.rb tmp/x86_64-linux/stage/lib/mysql2/em.rb
cp lib/mysql2/error.rb tmp/x86_64-linux/stage/lib/mysql2/error.rb
cp lib/mysql2/field.rb tmp/x86_64-linux/stage/lib/mysql2/field.rb
cp lib/mysql2/result.rb tmp/x86_64-linux/stage/lib/mysql2/result.rb
cp lib/mysql2/statement.rb tmp/x86_64-linux/stage/lib/mysql2/statement.rb
cp lib/mysql2/version.rb tmp/x86_64-linux/stage/lib/mysql2/version.rb
mkdir -p tmp/x86_64-linux/stage/spec
cp spec/configuration.yml.example tmp/x86_64-linux/stage/spec/configuration.yml.example
mkdir -p tmp/x86_64-linux/stage/spec/em
cp spec/em/em_spec.rb tmp/x86_64-linux/stage/spec/em/em_spec.rb
cp spec/my.cnf.example tmp/x86_64-linux/stage/spec/my.cnf.example
mkdir -p tmp/x86_64-linux/stage/spec/mysql2
cp spec/mysql2/client_spec.rb tmp/x86_64-linux/stage/spec/mysql2/client_spec.rb
cp spec/mysql2/error_spec.rb tmp/x86_64-linux/stage/spec/mysql2/error_spec.rb
cp spec/mysql2/result_spec.rb tmp/x86_64-linux/stage/spec/mysql2/result_spec.rb
cp spec/mysql2/statement_spec.rb tmp/x86_64-linux/stage/spec/mysql2/statement_spec.rb
cp spec/rcov.opts tmp/x86_64-linux/stage/spec/rcov.opts
cp spec/spec_helper.rb tmp/x86_64-linux/stage/spec/spec_helper.rb
mkdir -p tmp/x86_64-linux/stage/spec/ssl
cp spec/ssl/ca-cert.pem tmp/x86_64-linux/stage/spec/ssl/ca-cert.pem
cp spec/ssl/ca-key.pem tmp/x86_64-linux/stage/spec/ssl/ca-key.pem
cp spec/ssl/ca.cnf tmp/x86_64-linux/stage/spec/ssl/ca.cnf
cp spec/ssl/cert.cnf tmp/x86_64-linux/stage/spec/ssl/cert.cnf
cp spec/ssl/client-cert.pem tmp/x86_64-linux/stage/spec/ssl/client-cert.pem
cp spec/ssl/client-key.pem tmp/x86_64-linux/stage/spec/ssl/client-key.pem
cp spec/ssl/client-req.pem tmp/x86_64-linux/stage/spec/ssl/client-req.pem
cp spec/ssl/gen_certs.sh tmp/x86_64-linux/stage/spec/ssl/gen_certs.sh
cp spec/ssl/pkcs8-client-key.pem tmp/x86_64-linux/stage/spec/ssl/pkcs8-client-key.pem
cp spec/ssl/pkcs8-server-key.pem tmp/x86_64-linux/stage/spec/ssl/pkcs8-server-key.pem
cp spec/ssl/server-cert.pem tmp/x86_64-linux/stage/spec/ssl/server-cert.pem
cp spec/ssl/server-key.pem tmp/x86_64-linux/stage/spec/ssl/server-key.pem
cp spec/ssl/server-req.pem tmp/x86_64-linux/stage/spec/ssl/server-req.pem
cp spec/test_data tmp/x86_64-linux/stage/spec/test_data
mkdir -p tmp/x86_64-linux/stage/support
cp support/5072E1F5.asc tmp/x86_64-linux/stage/support/5072E1F5.asc
cp support/libmysql.def tmp/x86_64-linux/stage/support/libmysql.def
cp support/mysql_enc_to_ruby.rb tmp/x86_64-linux/stage/support/mysql_enc_to_ruby.rb
cp support/ruby_enc_to_mysql.rb tmp/x86_64-linux/stage/support/ruby_enc_to_mysql.rb
install -c tmp/x86_64-linux/mysql2/2.5.1/mysql2.so lib/mysql2/mysql2.so
cp tmp/x86_64-linux/mysql2/2.5.1/mysql2.so tmp/x86_64-linux/stage/lib/mysql2/mysql2.so
/usr/local/ruby-2.5.1/bin/ruby -I/home/jaruga/git/mysql2/vendor/bundle/ruby/2.5.0/gems/rspec-core-3.7.1/lib:/home/jaruga/git/mysql2/vendor/bundle/ruby/2.5.0/gems/rspec-support-3.7.1/lib /home/jaruga/git/mysql2/vendor/bundle/ruby/2.5.0/gems/rspec-core-3.7.1/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb

Randomized with seed 54596
...
Failures:

  1) Mysql2::Client should set default program_name in connect_attrs
     Failure/Error: expect(result.first['attr_value']).to eq($PROGRAM_NAME)
     
     NoMethodError:
       undefined method `[]' for nil:NilClass
     # ./spec/mysql2/client_spec.rb:480:in `block (2 levels) in <top (required)>'

  2) Mysql2::Client should set custom connect_attrs
     Failure/Error: expect(results['program_name']).to eq('my_program_name')
     
       expected: "my_program_name"
            got: nil
     
       (compared using ==)
     # ./spec/mysql2/client_spec.rb:489:in `block (2 levels) in <top (required)>'

Finished in 10.35 seconds (files took 0.16545 seconds to load)
325 examples, 2 failures, 1 pending

Failed examples:

rspec ./spec/mysql2/client_spec.rb:474 # Mysql2::Client should set default program_name in connect_attrs
rspec ./spec/mysql2/client_spec.rb:483 # Mysql2::Client should set custom connect_attrs

Randomized with seed 54596
@junaruga
Copy link
Contributor Author

In the result of the case: Ruby 2.5.1 + MariaDB 10.2 for the PR: #966 , the 2 tests that are failed in my local environment are pending status on Travis CI.

Also the pending message Both client and server versions must be MySQL 5.6 or MariaDB 10.2 or later is not correct. Because the test is running on MariaDB 10.2.

https://travis-ci.org/brianmario/mysql2/jobs/372082279

Pending: (Failures listed here are expected and do not affect your suite's status)
  1) Mysql2::Client should set custom connect_attrs
     # Both client and server versions must be MySQL 5.6 or MariaDB 10.2 or later.
     Failure/Error: expect(results['program_name']).to eq('my_program_name')
     
       expected: "my_program_name"
            got: nil
     
       (compared using ==)
     # ./spec/mysql2/client_spec.rb:489:in `block (2 levels) in <top (required)>'
  2) Mysql2::Client should set default program_name in connect_attrs
     # Both client and server versions must be MySQL 5.6 or MariaDB 10.2 or later.
     Failure/Error: expect(result.first['attr_value']).to eq($PROGRAM_NAME)
     
     NoMethodError:
       undefined method `[]' for nil:NilClass
     # ./spec/mysql2/client_spec.rb:480:in `block (2 levels) in <top (required)>'
Finished in 7.66 seconds (files took 0.18018 seconds to load)
325 examples, 0 failures, 2 pending

@junaruga
Copy link
Contributor Author

junaruga commented Apr 27, 2018

I added blow debug log to check the criteria to be pending.

diff --git a/ext/mysql2/client.c b/ext/mysql2/client.c
index d12f2c1..9f0a2e7 100644
--- a/ext/mysql2/client.c
+++ b/ext/mysql2/client.c
@@ -1587,9 +1587,11 @@ void init_mysql2_client() {
 #endif
 
 #ifdef CLIENT_CONNECT_ATTRS
+  printf("[DEBUG] CLIENT_CONNECT_ATTRS defined: CLIENT_CONNECT_ATTRS: [%ld]\n", CLIENT_CONNECT_ATTRS);
   rb_const_set(cMysql2Client, rb_intern("CONNECT_ATTRS"),
       LONG2NUM(CLIENT_CONNECT_ATTRS));
 #else
+  printf("[DEBUG] CLIENT_CONNECT_ATTRS undefined.\n");
   /* HACK because MySQL 5.5 and earlier don't define this constant,
    * but we're using it in our default connection flags. */
   rb_const_set(cMysql2Client, rb_intern("CONNECT_ATTRS"),
diff --git a/spec/mysql2/client_spec.rb b/spec/mysql2/client_spec.rb
index 00d9c17..8ad4f7c 100644
--- a/spec/mysql2/client_spec.rb
+++ b/spec/mysql2/client_spec.rb
@@ -473,6 +473,8 @@ RSpec.describe Mysql2::Client do
 
   it "should set default program_name in connect_attrs" do
     client = new_client
+    puts("Mysql2::Client::CONNECT_ATTRS.zero?: #{Mysql2::Client::CONNECT_ATTRS.zero?}")
+    puts("client.server_info[:version]: #{client.server_info[:version]}")
     if Mysql2::Client::CONNECT_ATTRS.zero? || client.server_info[:version].match(/10.[01].\d+-MariaDB/)
       pending('Both client and server versions must be MySQL 5.6 or MariaDB 10.2 or later.')
     end

The result is
The value of Mysql2::Client::CONNECT_ATTRS.zero? is different.
That's why the tests are failed on my local environment.

MariaDB 10.2 on Ubuntu

[DEBUG] CLIENT_CONNECT_ATTRS undefined.
Mysql2::Client::CONNECT_ATTRS.zero?: true
client.server_info[:version]: 5.5.5-10.2.14-MariaDB-10.2.14+maria~trusty

MariaDB 10.2 on Fedora 27.

[DEBUG] CLIENT_CONNECT_ATTRS defined: CLIENT_CONNECT_ATTRS: [1048576]
Mysql2::Client::CONNECT_ATTRS.zero?: false
client.server_info[:version]: 10.2.12-MariaDB-log

@junaruga
Copy link
Contributor Author

Additional info.

$ wget https://downloads.mariadb.org/interstitial/mariadb-10.2.12/source/mariadb-10.2.12.tar.gz

$ tar xzvf mariadb-10.2.12.tar.gz 

$ grep -r CLIENT_CONNECT_ATTRS *
...
mariadb-10.2.12/libmariadb/include/mariadb_com.h:#define CLIENT_CONNECT_ATTRS     (1UL << 20)
...

Above value is

irb(main):002:0> 1048576.to_s(2)
=> "100000000000000000000"

As an another concern, CLIENT_CONNECT_ATTRS is defined as unsigned long.
But LONG2NUM(CLIENT_CONNECT_ATTRS)); is used. ULONG2NUM might be better.

@sodabrew
Copy link
Collaborator

1<<20 is still well within 31-bits for a singed integer though, so I don't think that's urgent to switch to ULONG2NUM or even ULL2NUM.

@sodabrew
Copy link
Collaborator

My best guess is that you're linking against a "real" MySQL client library version 5.5. But you shouldn't see a test failure, you should see the test skipped because the value of the constant is zero.

@junaruga
Copy link
Contributor Author

1<<20 is still well within 31-bits for a singed integer though, so I don't think that's urgent to switch to ULONG2NUM or even ULL2NUM.

You are right. It's not urgent in this case.

@junaruga
Copy link
Contributor Author

junaruga commented Apr 27, 2018

I used strace command to see system call. libmariadb.so.3 (mariadb-libs-10.2.12) looks called.

$ strace bundle exec rspec ./spec/mysql2/client_spec.rb:492 >& strace.log

$ vi strace.log
...
openat(AT_FDCWD, "/usr/lib64/libmariadb.so.3", O_RDONLY|O_CLOEXEC) = 7
read(7, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0i\1\0\0\0\0\0"..., 832) = 832 
fstat(7, {st_mode=S_IFREG|0755, st_size=351160, ...}) = 0
...
$ rpm -qf /usr/lib64/libmariadb.so.3
mariadb-libs-10.2.12-5.fc27.x86_64

@junaruga
Copy link
Contributor Author

junaruga commented Apr 27, 2018

Below is about my client version.

   it "should set default program_name in connect_attrs" do
     client = new_client
+    puts("Mysql2::Client.info[:version]: #{Mysql2::Client.info[:version]}")
+    puts("Mysql2::Client::CONNECT_ATTRS: #{Mysql2::Client::CONNECT_ATTRS}")
+    puts("Mysql2::Client::CONNECT_ATTRS.zero?: #{Mysql2::Client::CONNECT_ATTRS.zero?}")
+    puts("client.server_info[:version]: #{client.server_info[:version]}")
     if Mysql2::Client::CONNECT_ATTRS.zero? || client.server_info[:version].match(/10.[01].\d+-MariaDB/)
       pending('Both client and server versions must be MySQL 5.6 or MariaDB 10.2 or later.')
     end

Fedora and MariaDB 10.2

Mysql2::Client.info[:version]: 10.2.12
Mysql2::Client::CONNECT_ATTRS: 1048576
Mysql2::Client::CONNECT_ATTRS.zero?: false
client.server_info[:version]: 10.2.12-MariaDB-log

Ubuntu and MariaDB 10.2 (On Travis CI)

Mysql2::Client.info[:version]: 5.5.58
Mysql2::Client::CONNECT_ATTRS: 0
Mysql2::Client::CONNECT_ATTRS.zero?: true
client.server_info[:version]: 5.5.5-10.2.14-MariaDB-10.2.14+maria~trusty

@junaruga
Copy link
Contributor Author

junaruga commented Apr 30, 2018

I found a test related to CLIENT_CONNECT_ATTRS in mariadb-connector-c, and checked the value of mysql->server_capabilities & CLIENT_CONNECT_ATTRS. The value is true (okay) on my local.

I would check mariadb-connector-c running the unit tests by myself.
So, I wish this issue still opened.
Thank you.

https://github.com/MariaDB/mariadb-connector-c/blob/master/unittest/libmariadb/misc.c#L936

  if (!(mysql->server_capabilities & CLIENT_CONNECT_ATTRS))
  {
    diag("Server doesn't support connection attributes");
    return SKIP;
  }

@sodabrew
Copy link
Collaborator

sodabrew commented Jul 4, 2018

Hi! Checking in to ask if there's a specific change you would like to see? Maybe to adjust the tests to key off of the value of the flag rather than the version of the library?

@junaruga
Copy link
Contributor Author

junaruga commented Jul 5, 2018

Hi @sodabrew ! I am still in progressing. I will try it again after next week.

@junaruga
Copy link
Contributor Author

junaruga commented Jul 10, 2018

@sodabrew Right now there is no the specific change for that, I was doing debug [1] for used mariadb-connector-c [2].

Below SQL's result raw count is zero row on the case "should set default program_name in connect_attrs".

SELECT attr_value FROM performance_schema.session_account_connect_attrs

I need some helps for that.
I prepared the Fedora environment to reproduce.
The Travis result is here [3].
When you have a time, could you check it?

$ git remote add junaruga [email protected]:junaruga/mysql2.git
$ git fetch junaruga
$ git checkout feature/travis-centos-fedora

Start docker.
Build docker container.

$ docker build --rm -t mysql2_fedora -f .travis_Dockerfile_fedora .

To run test.

$ docker run --rm --add-host=mysql2gem.example.com:127.0.0.1 -t mysql2_fedora

To debug interactively.

$ docker run --rm --add-host=mysql2gem.example.com:127.0.0.1 -it mysql2_fedora bash
# sh .travis_fedora.sh

[1] https://gist.github.com/junaruga/70bc7aa7aeb60d94745553ef4c52a3b7
[2] https://github.com/MariaDB/mariadb-connector-c
[3] https://travis-ci.org/junaruga/mysql2/builds/402268795 DOCKER=fedora

@sodabrew
Copy link
Collaborator

sodabrew commented Feb 6, 2019

Checking in to see if you have any news on this issue @junaruga ?

@junaruga
Copy link
Contributor Author

@sodabrew sorry, I do not have news for the issue. It still happens.

@voxik
Copy link

voxik commented Feb 11, 2021

Isn't the difference here MySql vs MariaDB? It seems that MariaDB introduced "Performance Schema" in 10.5.2:

https://mariadb.com/kb/en/mariadb-1052-release-notes/

@junaruga
Copy link
Contributor Author

@voxik I think it seems the "Performance Schema" is initially introduced at MariaDB 10.0.11.
https://mariadb.com/kb/en/performance-schema-overview/

Isn't the difference here MySql vs MariaDB?

Yes, I think so. it comes from the difference between MySQL vs MariaDB. This issue does not happen on MySQL.

@junaruga
Copy link
Contributor Author

I captured the client and server info on the CI cases failing on the failures.

$ ruby -I lib -r mysql2 -e 'p Mysql2::Client.info'
{:id=>100505, :version=>"10.5.5", :header_version=>"10.5.5"}

fedora fedola:latest

[DEBUG] spec/mysql2/client_spec.rb Mysql2::Client::CONNECT_ATTRS.zero?: false
[DEBUG] spec/mysql2/client_spec.rb client.server_info[:version]: 10.4.18-MariaDB
client_info: {:id=>100505, :version=>"10.5.5", :header_version=>"10.5.5"}

fedora fedola:rawhide

[DEBUG] spec/mysql2/client_spec.rb Mysql2::Client::CONNECT_ATTRS.zero?: false
[DEBUG] spec/mysql2/client_spec.rb client.server_info[:version]: 10.5.9-MariaDB
client_info: {:id=>100505, :version=>"10.5.5", :header_version=>"10.5.5"}

macos-latest ruby 2.4 mariadb

[DEBUG] spec/mysql2/client_spec.rb Mysql2::Client::CONNECT_ATTRS.zero?: false
[DEBUG] spec/mysql2/client_spec.rb client.server_info[:version]: 10.5.9-MariaDB
client_info: {:id=>100509, :version=>"10.5.9", :header_version=>"10.5.9"}

@junaruga
Copy link
Contributor Author

junaruga commented Apr 12, 2021

What I observed these failures is when I upgraded the version of ruby mysql2 RPM package from 0.4.10 to 0.5.2.
So, I checked what was changed between the versions. 0.4.10...0.5.2

  • The option the :connect_attrs = {:program_name => $PROGRAM_NAME, ...} is newly added to the Mysql2::Client class's argument opiton ( https://github.com/brianmario/mysql2/compare/0.4.10...0.5.2#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R214 ).
  • #ifdef CLIENT_CONNECT_ATTRS is newly added in ext/mysql2/client.c ( https://github.com/brianmario/mysql2/compare/0.4.10...0.5.2#diff-8cc85b931218589827ff4097193b14289b4d0fd58f28e95a15c6bd63cdaf5ed8R403 ).

I suppose the CLIENT_CONNECT_ATTRS macro might be wrongly judged in MariaDB case.

Sorry I forget things on this issue. the CLIENT_CONNECT_ATTRS macro looks okay.

ext/mysql2/extconf.rb

+$CFLAGS.gsub!(/-O[123]/, '-O0')
+$CFLAGS << ' -O0 -gdwarf-2 -ggdb3 -g3'
+$CXXFLAGS.gsub!(/-O[123]/, '-O0')
+$CXXFLAGS << ' -O0 -gdwarf-2 -ggdb3 -g3'

client.c:1653

  rb_const_set(cMysql2Client, rb_intern("CONNECT_ATTRS"),
      LONG2NUM(CLIENT_CONNECT_ATTRS));
$ gdb -q --args ruby-mri -I lib -e 'require "mysql2"; p Mysql2::Client::CONNECT_ATTRS.zero?'
(gdb) set breakpoint pending on
(gdb) b init_mysql2_client
(gdb) b ext/mysql2/client.c:1653
(gdb) b ext/mysql2/client.c:1658
(gdb) r

(gdb) info macro CLIENT_CONNECT_ATTRS
Defined at /usr/include/mysql/mariadb_com.h:160
  included at /usr/include/mysql/mysql.h:59
  included at /mnt/mysql2/tmp/x86_64-linux/mysql2/3.0.0/../../../../ext/mysql2/mysql2_ext.h:13
  included at /mnt/mysql2/tmp/x86_64-linux/mysql2/3.0.0/../../../../ext/mysql2/client.c:1
#define CLIENT_CONNECT_ATTRS (1UL << 20)
(gdb) p LONG2NUM(CLIENT_CONNECT_ATTRS)
$1 = 2097153
(gdb) p CLIENT_CONNECT_ATTRS
$2 = 1048576

@junaruga
Copy link
Contributor Author

@sodabrew Finally I got the answer for this issue by checking the logic of mariadb-connector-c and MariaDB upstream's issue ticket.

The performance-schema is disabled by by default.

We are adding the MYSQL_OPT_CONNECT_ATTR_ADD's value for the following logic.

mysql_options4(wrapper->client, MYSQL_OPT_CONNECT_ATTR_ADD, StringValueCStr(key), StringValueCStr(value));

The mysql_options4 calling mysql_optionsv calling hash_insert.

https://github.com/mariadb-corporation/mariadb-connector-c/blob/7d304d26c787a3f0430624db977b615aba56e4bb/libmariadb/mariadb_lib.c#L3202

Here is the input key and value that we wanted to store.

(gdb) p (char *) StringValueCStr(key)
$23 = 0x5555559f0430 "program_name"
(gdb) p (char *) StringValueCStr(value)
$24 = 0x5555559f1128 "my_program_name

But I might find only key was stored and the value was not stored to the record. at my_bool hash_insert(HASH *info,const uchar *record).

(gdb) p (uchar *)record
$34 = (uchar *) 0x5555562e6340 "program_name"

So, I searched if there is a issue related to MYSQL_OPT_CONNECT_ATTR_ADD. And I found the following reported issue.

CONNECTION_ATTRS not stored in performance schema
https://jira.mariadb.org/browse/MDEV-6726

Are you running the server with --performance-schema?
Keep in mind that it's disabled by default in 10.0 (unlike 5.6 where it's enabled by default).

According to the documentation (http://dev.mysql.com/doc/internals/en/capability-flags.html), the flag only means that the server allows connection attributes in Protocol::HandshakeResponse41. It still does, whether performance schema is enabled or not, so why should this check fail?

@junaruga
Copy link
Contributor Author

I got the performance_schema is disabled on my Fedora rawhide's MariaDB server.

https://mariadb.com/kb/en/performance-schema-overview/#activating-the-performance-schema

MariaDB [test]> SHOW VARIABLES LIKE 'performance_schema';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| performance_schema | OFF   |
+--------------------+-------+
1 row in set (0.002 sec)

So, the solution for this issue is

  • When the performance_schema is off, skip the tests on the spec files.
  • Enable performance_schema on one or some of the MariaDB cases in the CI.

@junaruga junaruga changed the title 2 Failures on Ruby 2.5.1, Mariadb 10.2 and Fedora 27 Test failures on Mariadb on performance_schema: OFF Apr 14, 2021
@junaruga junaruga changed the title Test failures on Mariadb on performance_schema: OFF Test failures on MariaDB on performance_schema: OFF Apr 14, 2021
@junaruga junaruga changed the title Test failures on MariaDB on performance_schema: OFF Test failures on MariaDB performance_schema: OFF Apr 14, 2021
@junaruga
Copy link
Contributor Author

A good news! I confirmed these test failures do not happen when the performance_schema is enabled (ON) on my Fedora 35's MariaDB 10.5.

Here is the reproducer.

Seeing https://mariadb.com/kb/en/performance-schema-overview/ , add the setting to enable performance schema to the cnf file.

# vi /etc/my.cnf.d/mariadb-server.cnf

[mysqld]
...

# https://mariadb.com/kb/en/performance-schema-overview/
performance_schema=ON
performance-schema-instrument='stage/%=ON'
performance-schema-consumer-events-stages-current=ON
performance-schema-consumer-events-stages-history=ON
performance-schema-consumer-events-stages-history-long=ON

Run the MariaDB server

Confirm the settings performance_schema: ON, performance_schema_users_size: -1 The -1 is default value. and it is auto sizing. Seeing the document.

$ mysql -u "mockbuild" -S test_db/mysql.sock -e "SHOW VARIABLES WHERE Variable_name IN ('have_ssl', 'local_infile', 'performance_schema', 'performance_schema_users_size');"
+-------------------------------+-------+
| Variable_name                 | Value |
+-------------------------------+-------+
| have_ssl                      | YES   |
| local_infile                  | ON    |
| performance_schema            | ON    |
| performance_schema_users_size | -1    |
+-------------------------------+-------+

Then on the current latest master 346b4a43a146aa2239b82a6bb1020c66f6e456a0 (+ some debugging patches).

$ bundle exec rake spec

Failures: 

  1) Mysql2::Error encoding returns error messages as UTF-8 by default
     Failure/Error: expect(bad_err.message).to include("??}\u001F")
       expected "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '??}\\001F' at line 1" to include "??}\u001F"
     # ./spec/mysql2/error_spec.rb:67:in `block (4 levels) in <top (required)>'
     # ./spec/spec_helper.rb:23:in `with_internal_encoding'
     # ./spec/mysql2/error_spec.rb:60:in `block (3 levels) in <top (required)>'

Finished in 13.71 seconds (files took 0.19643 seconds to load)
333 examples, 1 failure, 1 pending

The #1152 's 1) is only shown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants