[MDEV-7526] TokuDB doesn't build on OS X Created: 2015-01-28  Updated: 2015-12-22  Resolved: 2015-12-22

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - TokuDB
Affects Version/s: 5.5, 10.0, 10.1
Fix Version/s: 5.5.48, 10.0.24, 10.1.10

Type: Bug Priority: Major
Reporter: Kolbe Kegel (Inactive) Assignee: Vicențiu Ciorbaru
Resolution: Fixed Votes: 0
Labels: None
Environment:

Mac OS X 10.10.1


Attachments: Text File toku_Werror_in_maint_mode_only.patch    
Issue Links:
Duplicate
duplicates MDEV-6869 Error when compiling for Mac OS X 10.9 Closed
Sprint: 10.1.10

 Description   

TokuDB apparently doesn't built on OS X:

[ 72%] Building CXX object storage/tokudb/ft-index/locktree/CMakeFiles/locktree_static.dir/locktree.cc.o
In file included from /Users/kolbe/Devel/bzr/maria/10.0.16/storage/tokudb/ft-index/locktree/locktree.cc:99:
In file included from /Users/kolbe/Devel/bzr/maria/10.0.16/storage/tokudb/ft-index/locktree/locktree.h:94:
/Users/kolbe/Devel/bzr/maria/10.0.16/storage/tokudb/ft-index/buildheader/db.h:323:1: error: empty struct has size 0 in C, size 1 in C++ [-Werror,-Wextern-c-compat]
struct __toku_db_lsn {
^
1 error generated.
make[2]: *** [storage/tokudb/ft-index/locktree/CMakeFiles/locktree_static.dir/locktree.cc.o] Error 1
make[1]: *** [storage/tokudb/ft-index/locktree/CMakeFiles/locktree_static.dir/all] Error 2
make: *** [all] Error 2

This should either be fixed, or TokuDB should be disabled on OS X for now.



 Comments   
Comment by Elena Stepanova [ 2015-01-28 ]

See also MDEV-6869

Comment by Charles Bailey [ 2015-05-05 ]

Aside questions about whether Toku is supported under OS X (cf MDEV-6869), the failure arises from addition of -Werror in TokuSetupCompiler.cmake; the clang version Apple releases warns on some constructs in the TokuDB source. Removing -Werror allows the build to complete, and the resulting binaries pass all of the toku tests in the regression suite for 10.1.4. So the attached patch reserves -Werror for maintainer/debug builds.

Comment by Thierry Coppey [ 2015-10-24 ]

I managed to build mariadb-10.1.8 on MacOS 10.9.5 with the following tweaks:

  perl -pi -e 's/ER_PARSE_ERROR/1064/g' sql/sql_trigger.h
  perl -pi -e 's/class Foreign_key/class Create_field;\nclass Foreign_key/g' sql/sql_class.h
  patch -p 0 <<PATCH
--- storage/mroonga/vendor/groonga/CMakeLists.txt
+++ storage/mroonga/vendor/groonga/CMakeLists.txt
@@ -167,6 +167,10 @@ if(CMAKE_COMPILER_IS_GNUCXX)
   MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-clobbered")
 endif()
 
+if(CMAKE_COMPILER_IS_CLANGCXX)
+  MY_CHECK_AND_SET_COMPILER_FLAG("-fexceptions")
+endif()
+
 if(NOT DEFINED CMAKE_C_COMPILE_OPTIONS_PIC)
   # For old CMake
   if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGCXX)
PATCH
 
  perl -pi -e 's/extern HASH/extern const char* const tokudb_hton_name;\nextern HASH/g' storage/tokudb/hatoku_hton.h
  perl -pi -e 's/const char \*tokudb_hton_name/const char *const tokudb_hton_name/g' storage/tokudb/hatoku_hton.cc
  perl -pi -e 's/ -fuse-linker-plugin//g' storage/tokudb/CMakeLists.txt
  perl -pi -e 's/ -fuse-linker-plugin//g' storage/tokudb/ft-index/cmake_modules/TokuSetupCompiler.cmake
  patch -p 0 <<PATCH
--- storage/tokudb/ft-index/cmake_modules/TokuSetupCompiler.cmake
+++ storage/tokudb/ft-index/cmake_modules/TokuSetupCompiler.cmake
@@ -157,10 +157,14 @@
   MY_CHECK_AND_SET_COMPILER_FLAG(-Wcast-align)
 endif ()
 
-## always want these
-set(CMAKE_C_FLAGS "-Wall -Werror \${CMAKE_C_FLAGS}")
-set(CMAKE_CXX_FLAGS "-Wall -Werror \${CMAKE_CXX_FLAGS}")
-
+if (MYSQL_MAINTAINER_MODE STREQUAL "ON")
+  set(CMAKE_C_FLAGS "-Wall -Werror \${CMAKE_C_FLAGS}")
+  set(CMAKE_CXX_FLAGS "-Wall -Werror \${CMAKE_CXX_FLAGS}")
+elseif (MYSQL_MAINTAINER_MODE STREQUAL "AUTO")
+  set(CMAKE_C_FLAGS_DEBUG "-Wall -Werror \${CMAKE_C_FLAGS_DEBUG}")
+  set(CMAKE_CXX_FLAGS_DEBUG "-Wall -Werror \${CMAKE_CXX_FLAGS_DEBUG}")
+endif ()
+
 ## need to set -stdlib=libc++ to get real c++11 support on darwin
 if (APPLE)
   if (CMAKE_GENERATOR STREQUAL Xcode)
PATCH

Dependencies: XCode, CMake, JEMalloc
Not sure it runs though.

Comment by Thierry Coppey [ 2015-10-25 ]

Compiles but crashes when trying to load the plugin, here is the error message:

Assertion failed: (r==0), function libtokuft_init, file .../mariadb-10.1.8/storage/tokudb/ft-index/src/ydb_lib.cc, line 103.
151025  0:05:38 [ERROR] mysqld got signal 6 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
 
To report this bug, see http://kb.askmonty.org/en/reporting-bugs
 
We will try our best to scrape up some info that will hopefully help
diagnose the problem, but since we have already crashed, 
something is definitely wrong and this may fail.
 
Server version: 10.1.8-MariaDB
key_buffer_size=67108864
read_buffer_size=524288
max_used_connections=1
max_threads=202
thread_count=1
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 379900 K  bytes of memory
Hope that's ok; if not, decrease some variables in the equation.
 
Thread pointer: 0x0x7fbd5c857808
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 0x124839e60 thread_stack 0x48000
.../mariadb-10.1.8/storage/tokudb/ft-index/portability/toku_pthread.h:199 toku_mutex_destroy: Assertion `r == 0' failed (errno=2) (r=22)
: No such file or directory
Backtrace: (Note: toku_do_assert=0x0x124d21ea0)
0   ha_tokudb.so                        0x0000000124d21ef4 _Z19db_env_do_backtraceP7__sFILE + 52
1   ha_tokudb.so                        0x0000000124d22093 _ZL23toku_do_backtrace_abortv + 19
2   ha_tokudb.so                        0x0000000124d2210c _Z24toku_do_assert_zero_failmPKcS0_S0_ii + 108
3   ha_tokudb.so                        0x0000000124cb8f36 _Z21toku_ft_layer_destroyv + 166
4   ???                                 0x00007fff6d75bef5 0x0 + 140735029821173
5   ???                                 0x00007fff6d74c279 0x0 + 140735029756537
6   libsystem_c.dylib                   0x00007fff8de687a1 __cxa_finalize + 177
7   libsystem_c.dylib                   0x00007fff8de68a4c exit + 22
8   mysqld                              0x000000010fd4c667 my_addr_resolve_init + 279
9   mysqld                              0x000000010fd3a13a my_print_stacktrace + 90
10  mysqld                              0x000000010f6c6797 handle_fatal_signal + 631
11  libsystem_platform.dylib            0x00007fff96ea65aa _sigtramp + 26
12  libsystem_c.dylib                   0x00007fff7b5b4278 __c_locale + 0
13  libsystem_c.dylib                   0x00007fff8de67b1a abort + 125
14  libsystem_c.dylib                   0x00007fff8de319bf basename + 0
15  ha_tokudb.so                        0x0000000124c6a3b7 _ZL14libtokuft_initv + 55
16  ???                                 0x00007fff6d75bc2e 0x0 + 140735029820462
17  ???                                 0x00007fff6d75bdba 0x0 + 140735029820858
18  ???                                 0x00007fff6d758a62 0x0 + 140735029807714
19  ???                                 0x00007fff6d7588f6 0x0 + 140735029807350
20  ???                                 0x00007fff6d74eb0e 0x0 + 140735029766926
21  ???                                 0x00007fff6d7557cf 0x0 + 140735029794767
22  libdyld.dylib                       0x00007fff960087ee dlopen + 59
23  mysqld                              0x000000010f8a7451 _ZL13plugin_dl_addPK19st_mysql_lex_stringi + 449
24  mysqld                              0x000000010f8a5fcc _ZL10plugin_addP11st_mem_rootPK19st_mysql_lex_stringPS1_i + 316
25  mysqld                              0x000000010f8a5be4 _Z20mysql_install_pluginP3THDPK19st_mysql_lex_stringS3_ + 516
26  mysqld                              0x000000010f88a559 _Z21mysql_execute_commandP3THD + 15977
27  mysqld                              0x000000010f885588 _Z11mysql_parseP3THDPcjP12Parser_state + 744
28  mysqld                              0x000000010f88367d _Z16dispatch_command19enum_server_commandP3THDPcj + 7789
29  mysqld                              0x000000010f88465f _Z10do_commandP3THD + 1007
30  mysqld                              0x000000010f975ba4 _Z24do_handle_one_connectionP3THD + 516
31  mysqld                              0x000000010f97598b handle_one_connection + 59
32  libsystem_pthread.dylib             0x00007fff977da899 _pthread_body + 138
33  libsystem_pthread.dylib             0x00007fff977da72a _pthread_struct_init + 0
34  libsystem_pthread.dylib             0x00007fff977defc9 thread_start + 13
Engine status function not available
Memory usage:
0   mysqld                              0x000000010fd3a11c my_print_stacktrace + 60
0   mysqld                              0x000000010f6c6797 handle_fatal_signal + 631
0   libsystem_platform.dylib            0x00007fff96ea65aa _sigtramp + 26
0   libsystem_c.dylib                   0x00007fff7b5b4278 __c_locale + 0
0   libsystem_c.dylib                   0x00007fff8de67b1a abort + 125
0   libsystem_c.dylib                   0x00007fff8de319bf basename + 0
0   ha_tokudb.so                        0x0000000124c6a3b7 _ZL14libtokuft_initv + 55
0   ???                                 0x00007fff6d75bc2e 0x0 + 140735029820462
0   ???                                 0x00007fff6d75bdba 0x0 + 140735029820858
0   ???                                 0x00007fff6d758a62 0x0 + 140735029807714
0   ???                                 0x00007fff6d7588f6 0x0 + 140735029807350
0   ???                                 0x00007fff6d74eb0e 0x0 + 140735029766926
0   ???                                 0x00007fff6d7557cf 0x0 + 140735029794767
0   libdyld.dylib                       0x00007fff960087ee dlopen + 59
0   mysqld                              0x000000010f8a7451 _ZL13plugin_dl_addPK19st_mysql_lex_stringi + 449
0   mysqld                              0x000000010f8a5fcc _ZL10plugin_addP11st_mem_rootPK19st_mysql_lex_stringPS1_i + 316
0   mysqld                              0x000000010f8a5be4 _Z20mysql_install_pluginP3THDPK19st_mysql_lex_stringS3_ + 516
0   mysqld                              0x000000010f88a559 _Z21mysql_execute_commandP3THD + 15977
0   mysqld                              0x000000010f885588 _Z11mysql_parseP3THDPcjP12Parser_state + 744
0   mysqld                              0x000000010f88367d _Z16dispatch_command19enum_server_commandP3THDPcj + 7789
0   mysqld                              0x000000010f88465f _Z10do_commandP3THD + 1007
0   mysqld                              0x000000010f975ba4 _Z24do_handle_one_connectionP3THD + 516
0   mysqld                              0x000000010f97598b handle_one_connection + 59
0   libsystem_pthread.dylib             0x00007fff977da899 _pthread_body + 138
0   libsystem_pthread.dylib             0x00007fff977da72a _pthread_struct_init + 0
0   libsystem_pthread.dylib             0x00007fff977defc9 thread_start + 13
 
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort.
Query (0x7fbd5c014620): is an invalid pointer
Connection ID (thread ID): 2
Status: NOT_KILLED

This seems to be related to the silenced warning that empty C structures have size 0 whereas this is not the case in C++.

Comment by Thierry Coppey [ 2015-10-26 ]

Finally I made it compile and was able to create a TokuDB table in a chrooted MySQL environment with MariaDB 10.1.8 on OSX 10.9.5, but the same trick would probably work for other versions. Here are the steps that I did:

0. Install XCode, and cmake (manually)
1. Install Jemalloc (from sources)

2. Patch MariaDB 10.1.8 (to execute from the root of the unzipped archive)

perl -pi -e 's/^class Item_trigger_field;/#include "mysqld_error.h"\nclass Item_trigger_field;/g' sql/sql_trigger.h
perl -pi -e 's/class Foreign_key/class Create_field;\nclass Foreign_key/g' sql/sql_class.h
perl -pi -e 's/extern HASH/extern const char* const tokudb_hton_name;\nextern HASH/g' storage/tokudb/hatoku_hton.h
perl -pi -e 's/const char \*tokudb_hton_name/const char *const tokudb_hton_name/g' storage/tokudb/hatoku_hton.cc
perl -pi -e 's/ -fuse-linker-plugin//g' storage/tokudb/CMakeLists.txt
perl -pi -e 's/ -fuse-linker-plugin//g' storage/tokudb/ft-index/cmake_modules/TokuSetupCompiler.cmake
perl -pi -e 's/CMAKE_CXX_FLAGS "-Wall -Werror/CMAKE_CXX_FLAGS "-Wall/g' storage/tokudb/ft-index/cmake_modules/TokuSetupCompiler.cmake
 
patch -p 0 <<PATCH
--- storage/mroonga/vendor/groonga/CMakeLists.txt
+++ storage/mroonga/vendor/groonga/CMakeLists.txt
@@ -167,6 +167,10 @@ if(CMAKE_COMPILER_IS_GNUCXX)
   MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-clobbered")
 endif()
 
+if(CMAKE_COMPILER_IS_CLANGCXX)
+  MY_CHECK_AND_SET_COMPILER_FLAG("-fexceptions")
+endif()
+
 if(NOT DEFINED CMAKE_C_COMPILE_OPTIONS_PIC)
   # For old CMake
   if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGCXX)
PATCH
 
patch -p 0 <<PATCH
--- storage/tokudb/ft-index/portability/portability.cc
+++ storage/tokudb/ft-index/portability/portability.cc
@@ -413,6 +413,13 @@
             r = toku_get_processor_frequency_sysctl("sysctl -n machdep.tsc_freq", hzret);
         if (r == 0)
             toku_cached_hz = *hzret;
+        if (r != 0) {
+            int mib[2] = { CTL_HW, HW_CPU_FREQ };
+            unsigned int freq;
+            size_t len = sizeof(freq);
+            r = sysctl(mib, 2, &freq, &len, NULL, 0);
+            toku_cached_hz = freq;
+        }
     }
     return r;
 }
PATCH
 
cat>>cmake/jemalloc.cmake<<EOF
SET(LIBJEMALLOC jemalloc)
SET(MALLOC_LIBRARY bundled jemalloc)
EOF

3. Configure, build and install

  • mkdir bld; cd bld; cmake .. -DBUILD_CONFIG=mysql_release
  • make -j 8; sudo make install

What struck me is that engineers do not remember there is a syscall API in C and do it the wrong way with 2-3 shell-based attempts to detect CPU speed in portability.cc – which is btw not compatible with chrooting.

Then (for completeness) I configure /etc/my.cnf (for chroot) with

[server]
socket = /socket/mysql.sock
basedir = /
datadir = /data
tmpdir = /tmp
plugin_dir=/lib/plugin
plugin-load=ha_tokudb
 

And run the server with
/usr/local/mysql/bin/mysqld --user=_mysql --chroot=/usr/local/mysql

Let me know if there is some missing bit

Comment by Sergey Vojtovich [ 2015-12-15 ]

Beware of 10.1 PR: https://github.com/MariaDB/server/pull/79

Comment by Vicențiu Ciorbaru [ 2015-12-19 ]

There are a number of errors that cause TokuDB to fail compiling on OS X. All these failures are still present in the 5.5 branch, so that is where we should address them.

The first error is related to the DB_LSN struct. Being declared empty, according to the C++ standard, it must be assigned a size of 1, while in C it does not. To fix this we add a dummy char field (of size 1). This fix has also been implemented upstream within the TokuDB repository and makes sense.

Comment by Vicențiu Ciorbaru [ 2015-12-19 ]

A second error is related to unused functions within the tokudb_dump.cc. I've removed the functions from the codebase.

A third error is related to a redundant if statement on the address of a member field in ft-index/ft/txn/rollback.cc. The address of a member field is always true.

A fourth error is caused by specifying attribute(nonnull) for the copyout function within ft-index/util/dmt.h.
By examining the code paths, we can see that only the output parameter should not be passed as null. All other parameters can be set to null. The code does actually call the function with null parameters so we can't just remove the null checks.

Comment by Vicențiu Ciorbaru [ 2015-12-19 ]

Hi Sergei!

Can you please review the series of patches on the commits mailing list related to this issue?

I've fixed all the errors within TokuDB on Mac OS X. The fixes are done on 5.5 as the problems are also present there.

All the changes that I've done, I've double checked with the upstream TokuDB repository.

One of the commits is actually from a pull request from the community.

Comment by Vicențiu Ciorbaru [ 2015-12-22 ]

Closed with:
591e74c7e8f682f2eada7496f50aa73f38bd168d
e386523a41245d8b03f1338934c1aa965530e4fc
f39b9e04db1e71e72bfc19174f257db5147df440
64149590c47d1cf6b1b227d8c90bdc23d20a8956
f89c9fc4b7b5d82c79775cb848225900b45a6b79

Generated at Thu Feb 08 07:20:16 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.