我花了三天时间启动ES源码这件事

2022-04-12 14:54:51 浏览数 (1)

起因是当我尝试调用完ES的Java api后,想尝试进行ES源码的启动调试,想看到哪里结合netty的使用,以及如何进行调试,当我翻遍文章解决我的问题,却发现并不起作用(为啥我在打这段话的时候一种中式英语的风格油然而生

难读的ElasticSearch源码

并不是代码的难读性,而是我为了准备阅读的环境,陆陆续续准备了3天,当下我的idea仍然在下载gradle的必要组件,其实提起兴趣的还是因为它引用了netty。

环境准备

代码语言:javascript复制
Elasticsearch version (bin/elasticsearch --version): elasticsearch-8.1.0
JVM version (java -version): openjdk version jdk-17.0.2
Windows environment : Windows 11
idea:2021.3

启动elasticsearch

解压Elasticsearch-8.1.0到本地后启动elasticsearch.bat成功

下载源码到本地,由于是gradle编译,通过更改国内镜像的前提下,我5G的WIFI网速,12代i7的环境仍然下载了10分钟。

为了解决低版本在jdk13.14中的bug我在本地安装了jdk17,其他特别的设置,在项目的根路径下添加了init.gradle,其他无任何更改。

代码语言:javascript复制
启动org.elasticsearch.bootstrap.Elasticsearch
/**
     * Main entry point for starting elasticsearch
     */
    public static void main(final String[] args) throws Exception {
        overrideDnsCachePolicyProperties();
        org.elasticsearch.bootstrap.Security.prepopulateSecurityCaller();

        /*
         * We want the JVM to think there is a security manager installed so that if internal policy decisions that would be based on the
         * presence of a security manager or lack thereof act as if there is a security manager present (e.g., DNS cache policy). This
         * forces such policies to take effect immediately.
         */
        org.elasticsearch.bootstrap.Security.setSecurityManager(new SecurityManager() {

            @Override
            public void checkPermission(Permission perm) {
                // grant all permissions so that we can later set the security manager to the one that we want
            }

        });
        LogConfigurator.registerErrorListener();
        final Elasticsearch elasticsearch = new Elasticsearch();
        int status = main(args, elasticsearch, Terminal.DEFAULT);
        if (status != ExitCodes.OK) {
            printLogsSuggestion();
            exit(status);
        }
    }

报错如下

代码语言:javascript复制
ERROR: the system property [es.path.conf] must be set

到这里其实已经可以进行初步的debug,但是想知道问题怎么解决,在搜遍全网发现大多是抄自github的解决方案时,我自己也提了个issue到elasticsearch

0 人点赞