ElasticSearch source code debugging, simple and practical, pro test available

The basic process is carried out in accordance with official documents . Especially the tool version, don't change it for beginners.

git clone https://github.com/elastic/elasticsearch.git
cd elasticsearch 
git checkout --track origin/6.6

./gradlew idea #可以理解为源码编译,一般问题均出在jdk版本

./gradlew run --debug-jvm #这一步可以理解为启动一个可以debug的elasticsearch服务

wget https://www.jetbrains.com/idea/download/download-thanks.html?platform=linux&code=IIC
tar zxvf ideaIC-2020.1.tar.gz
cd ideaIC-2020.1
./bin/idea.sh #启动ide工具,然后按照官方文档导入源码和环境

#文档中Run -> Attach to Process,执行成功后,如果想调试curl命令,则需要先断开执行下面的操作:
# Run -> Edit Configuratons -> + -> Remote,得到一个Run/Debug Configurations页面
# Name自己设置,HOST默认localhost,如果是真正的远程调试则设置服务器所在的ip,Port设置8000 (因为./gradlew run --debug-jvm 启动的默认Port是8000)
# 其它项均不要改动,点击ok。如果正常控制台会打印显示连接成功。
#在文件/server/src/main/java/org/elasticsearch/rest/RestController.java中的下述行(174)设置断点。
#这是elasticsearch处理web请求的入口类,收到curl请求时就会停在这里
tryAllHandlers(request, channel, threadContext); 

# 至此环境均准备好了,再开一个终端界面:
curl -i -XGET 'localhost:9200/' #随便执行一句curl指令,此时ide中程序就会停在断点处

In this way, we can debug happily.

Published 10 original articles · won praise 0 · Views 6258

Guess you like

Origin blog.csdn.net/u010379248/article/details/105644749
Recommended