技术分享 | 新手如何调试 OceanBase

作者:郭奥门

爱可生 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 m4
cd /opt && git clone https://github.com/oceanbase/oceanbase.git
cd oceanbase && git checkout 99777b4bc94d2cfc6be8ae1dce624e46beefad08
curl 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 655350
root 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-utils
yum-config-manager --add-repo https://mirrors.aliyun.com/oceanbase/OceanBase.repo
yum install -y libtool libaio obclient
/opt/oceanbase/deps/3rd && bash dep_create.sh all
cd /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.1
Welcome to the OceanBase.  Commands end with ; or \g.
Your OceanBase connection id is 3221487642
Server 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.gz
tar zxvf gdb-7.12.tar.gz && cd gdb-7.12
yum -y install gcc gcc-c++ texinfo
./configure
make && make install
gdb --version
gdbserver --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/...

你可能感兴趣的:(oceanbase调试)