obproxy-4.2.1适配KunPeng+openEuler操作系统

工作背景

信创软硬件投产需要,obproxy-4.2.1版本需要适配openEuler操作系统

环境信息

[root@localhost] # cat /etc/os-release 
NAME="openEuler"
VERSION="22.03 LTS"
ID="openEuler"
VERSION_ID="22.03"
PRETTY_NAME="openEuler 22.03 LTS"
ANSI_COLOR="0;31"

适配过程

问题1 dep_create.sh 不支持openEuler 分支

第一次执行编译脚本的时候,发现在执行 dep_create.sh 脚本时报错。检索发现在社区官网发现有一篇博客遇到过同样的问题
OceanBase 二次开发 之 Kunpeng + openEuler 适配优化(一)

参考博文中的解决方案:修改dep_create.sh脚本,增加 openEuler 的分支,同时,依赖包列表会在同级目录下找到 oceanbase.el8.aarch64.deps

--- a/deps/3rd/dep_create.sh
+++ b/deps/3rd/dep_create.sh
@@ -75,6 +75,8 @@ function get_os_release() {
       uos)
         version_ge "20" && compat_centos7 && return
         ;;
+      openEuler)
+       version_ge "22.03" && OS_RELEASE=8 && return
     esac
   elif [[ "${OS_ARCH}x" == "aarch64x" ]]; then
     case "$ID" in

问题2 使用了弃用的接口

make[3]: Entering directory '/root/obproxy/src'
  CXX      obproxy/main.o
  CXX      lib/ob_errno.lo
  CXX      lib/allocator/ob_malloc.lo
  CXX      lib/allocator/ob_mod_define.lo
lib/allocator/ob_mod_define.cpp: In member function ‘void oceanbase::common::ObModSet::print_mod_memory_usage(bool) const’:
lib/allocator/ob_mod_define.cpp:107:37: error: ‘mallinfo mallinfo()’ is deprecated [-Werror=deprecated-declarations]
  107 |     struct mallinfo info = mallinfo();
      |                                     ^
In file included from lib/allocator/ob_mod_define.cpp:15:
/usr/include/malloc.h:113:24: note: declared here
  113 | extern struct mallinfo mallinfo (void) __THROW __MALLOC_DEPRECATED;
      |                        ^~~~~~~~
lib/allocator/ob_mod_define.cpp:107:37: error: ‘mallinfo mallinfo()’ is deprecated [-Werror=deprecated-declarations]
  107 |     struct mallinfo info = mallinfo();
      |                                     ^
In file included from lib/allocator/ob_mod_define.cpp:15:
/usr/include/malloc.h:113:24: note: declared here
  113 | extern struct mallinfo mallinfo (void) __THROW __MALLOC_DEPRECATED;
      |                        ^~~~~~~~
cc1plus: all warnings being treated as errors
make[3]: *** [Makefile:6269: lib/allocator/ob_mod_define.lo] Error 1
make[3]: Leaving directory '/root/obproxy/src'
make[2]: *** [Makefile:2953: all] Error 2
make[2]: Leaving directory '/root/obproxy/src'
make[1]: *** [Makefile:462: all-recursive] Error 1
make[1]: Leaving directory '/root/obproxy'
make: *** [Makefile:373: all] Error 2

-Werror=deprecated-declarations 这个编译选项 应该是不允许程序使用弃用的接口

直接在obproxy的代码目录下grep -Ri 'deprecated-declarations' *,冒险一点直接把-Werror=deprecated-declarations 注释掉

--- a/src/lib/allocator/ob_mod_define.cpp
+++ b/src/lib/allocator/ob_mod_define.cpp
@@ -17,6 +17,7 @@
 #include "lib/objectpool/ob_concurrency_objpool.h"
 #include "lib/utility/ob_print_utils.h"
 #include "lib/thread_local/ob_tsi_factory.h"
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

问题3 sys/sysctl.h: No such file or directory

make[3]: Entering directory '/root/obproxy/src'
  CXX      obproxy/main.o
In file included from ../src/obproxy/iocore/net/ob_inet.h:38,
                 from ./lib/net/ob_addr.h:22,
                 from ./lib/profile/ob_trace_id.h:15,
                 from obproxy/ob_proxy_main.h:18,
                 from obproxy/main.cpp:17:
../src/obproxy/utils/ob_proxy_lib.h:96:10: fatal error: sys/sysctl.h: No such file or directory
   96 | #include <sys/sysctl.h>
      |          ^~~~~~~~~~~~~~
compilation terminated.
make[3]: *** [Makefile:6253: obproxy/main.o] Error 1
make[3]: Leaving directory '/root/obproxy/src'
make[2]: *** [Makefile:2953: all] Error 2
make[2]: Leaving directory '/root/obproxy/src'
make[1]: *** [Makefile:462: all-recursive] Error 1
make[1]: Leaving directory '/root/obproxy'
make: *** [Makefile:373: all] Error
./src/obproxy/utils/ob_proxy_lib.h:96:10: fatal error: sys/sysctl.h: No such file or directory
   96 | #include <sys/sysctl.h>

glibc2.32 开始废弃了sys/sysctl.h ,查看当前操作系统下glibc版本

[root@localhost obproxy]# rpm -qa | grep glibc
glibc-2.34-144.oe2203.x86_64
glibc-common-2.34-144.oe2203.x86_64
glibc-devel-2.34-144.oe2203.x86_64
[root@localhost obproxy]# rpm -ql glibc | grep "sysctl.h"
[root@localhost obproxy]#

发现这个<sys/sysctl.h>并没有代码中使用,仅仅添加到头文件中

--- a/src/obproxy/utils/ob_proxy_lib.h
+++ b/src/obproxy/utils/ob_proxy_lib.h
@@ -93,7 +93,7 @@ typedef unsigned int in_addr_t;
 #include <sys/sysinfo.h>
 #ifdef EL9_PLATFORM
 #else 
-#include <sys/sysctl.h>
+//#include <sys/sysctl.h>
 #endif
 #include <dlfcn.h>
 #include <math.h>

抱着试一试的心态,注释掉头文件之后继续编译,竟然成功了,测试功能目前也是正常的。

参考文章:

OceanBase 二次开发 之 Kunpeng + openEuler 适配优化(一)

本帖记录一下相关流程,供社区的其他开发者参考。解决方法不一定正确,如有关键失误请各位专家指正。

再次也特别感谢夏克老师在社区发的博客给了很多参考与启发。

首先,非常赞你的经验分享!
另外,我这边有一个小的问题,理论上centos的obproxy应该是可以在OpenEular+KunPeng上跑的,目前是有遇到什么困难所以希望做重新编译吗?