关于oceanbase:技术分享-新手如何调试-OceanBase

10次阅读

共计 3188 个字符,预计需要花费 8 分钟才能阅读完成。

作者:郭奥门

爱可生 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/…

正文完
 0