作者:郭奥门

爱可生 DBLE 研发成员,负责分布式数据库中间件的新性能开发,答复社区/客户/外部提出的一般性问题。

本文起源:原创投稿

*爱可生开源社区出品,原创内容未经受权不得随便应用,转载请分割小编并注明起源。


前言

observer调试有三种⽅法:⽇志,gdb调试,vscode调试(实质上是gdb或lldb)。这里咱们关注如何借助vscode进行调试

调试版本

OB代码基线:开源版本,社区版,3.1.5

github:https://github.com/oceanbase/...

commit id:99777b4bc94d2cfc6be8ae1dce624e46beefad08

调试形式采纳本地开发工具+近程gdb形式

本地指的是调试者的电脑(windows或mac)

近程指的是observer和gdb所在的linux服务器

所需工具:

本地:vscode(所需插件:C/C++、CMake、CMake Tools、Remote - SSH、Remote Development)

近程:gdb

近程环境

编译

具体可参考:https://github.com/oceanbase/...

yum install -y git wget rpm* cpio make glibc-devel glibc-headers binutils m4cd /opt && git clone https://github.com/oceanbase/oceanbase.gitcd oceanbase && git checkout 99777b4bc94d2cfc6be8ae1dce624e46beefad08curl http://mirrors.aliyun.com/oceanbase/OceanBase.repo## 批改编译选项## 正文掉 set(DEBUG_PREFIX "-fdebug-prefix-map=${CMAKE_SOURCE_DIR}=.")vi cmake/Env.cmake#工夫较长,能够先操作上面的步骤bash build.sh debug --init --make#实现后会在当前目录生成build_debug子目录,在build_debug/src/observer目录下会有一个observer二进制文件,此文件为observer的启动文件

装置

查看环境

这里我的环境只须要调整以下配置,倡议依照官网文档检查一下本人的服务器:环境和配置查看-OceanBase 数据库-OceanBase文档核心-分布式数据库应用文档(https://www.oceanbase.com/doc...)

vi /etc/security/limits.conf#追加root soft nofile 655350root hard nofile 655350* soft nofile 655350* hard nofile 655350* soft stack 20480* hard stack 20480* soft nproc 655360* hard nproc 655360* soft core unlimited* hard core unlimited#退出以后会话,从新登录。执行以下命令,查看配置是否失效:ulimit -a

部署

具体可参考:https://github.com/oceanbase/...

yum install -y yum-utilsyum-config-manager --add-repo https://mirrors.aliyun.com/oceanbase/OceanBase.repoyum install -y libtool libaio obclient/opt/oceanbase/deps/3rd && bash dep_create.sh allcd /opt/oceanbase/tools/deploy#该命令会将observer二进制文件(build_debug 或 build_release 都能够)和一些其余组件复制到当前目录,例如部署配置模板文件。./obd.sh prepare -p /opt/oceanbase/build_debug/src/observer./obd.sh deploy -c single.yaml

后续批改源码再调试时可间接运行:

./obd.sh prepare -p /opt/oceanbase/build_debug/src/observer./obd.sh deploy -c single.yaml

测试连贯:(single.yaml默认mysql端口为10000,RPC端口为10001)

[root@localhost deploy]# obclient -uroot -P10000 -h127.0.0.1Welcome to the OceanBase.  Commands end with ; or \g.Your OceanBase connection id is 3221487642Server version: OceanBase 3.1.5 (r1-99777b4bc94d2cfc6be8ae1dce624e46beefad08) (Built Nov 22 2022 06:09:41) Copyright (c) 2000, 2018, OB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. obclient [(none)]>

99777b4bc94d2cfc6be8ae1dce624e46beefad08对应咱们编译的observer版本

启动过程中产生谬误,可依据observer.log的相干报错进行排查

日志

所在目录:single.yaml中的home_path目录中

日志类型:OceanBase 数据库的过程⽇志次要分为 observer.log 、 rootservice.log 和 election.log ,以及对应的wf⽇志(只记录 WARN 和 ERROR),共2类6种⽇志。

装置gdb

cd /opt && wget http://ftp.gnu.org/gnu/gdb/gdb-7.12.tar.gztar zxvf gdb-7.12.tar.gz && cd gdb-7.12yum -y install gcc gcc-c++ texinfo./configuremake && make installgdb --versiongdbserver --version

本地环境

配置vscode

  • 本地自行装置插件:C/C++、CMake、CMake Tools、Remote - SSH、Remote Development

  • 装置胜利后,关上近程管理器,ssh连贯observer所在的服务器(不必ssh免密也能够,就是每次指定明码登录)

  • 关上oceanbase的源码目录

  • 持续在近程服务器上安装插件:C/C++、CMake、CMake Tools

  • 创立并配置launch.json,创立胜利后会保留在.vscode目录下

这里贴出我的配置:

launch.json
  • 启动

抉择 Run->Start Debugging,而后抉择 attach 的过程号,输⼊ observer 就能够搜寻到

抉择过程后期待半分钟,过程较多,gdb 加载须要工夫。

如下图所以,示意debug已启动胜利

  • 调试

关上ob_sql.cpp文件(快捷键ctrl+p 输出文件名),在1324行减少断点

注:因为oceanbase有很多后台任务,会定时的执行SQL,所以调试时设置的断点有可能会命中后台任务执行的SQL,调试起来不是很不便

  • 接下来开始欢快的调试吧=-=

参考:

文档概览-OceanBase 数据库-OceanBase文档核心-分布式数据库应用文档(https://www.oceanbase.com/doc...)

https://github.com/oceanbase/...