Elasticsearch6, Java Tutorial website s

elasticsearch6 elasticsearch java tutorial website

Download the source code

  1. The source download address is :https://github.com/elastic/elasticsearch/releases

  2. There are various versions of release, Find what we need Of 6.1.2 edition , Then download the compressed package , Here's the picture :

 Insert picture description here

  1. Download the source code to Ubuntu On the computer , perform tar -zxf elasticsearch-6.1.2.tar.gz After decompressing , Get a new folder elasticsearch-6.1.2;

Modify source code

To prove that the modified source code can be built and run normally , Let's modify a java file , Print some logs in it ;

  1. Enter the previously extracted folder elasticsearch-6.1.2;

  2. Open file core/src/main/java/org/elasticsearch/node/Node.java, Add a static method , The function is to print the current thread stack , The contents are as follows :

public static void printTrack(Logger logger, String prefix){

StackTraceElement[] st = Thread.currentThread().getStackTrace();

if(null==st){

logger.info(“invalid stack”);

return;

}

StringBuffer sbf =new StringBuffer();

for(StackTraceElement e:st){

if(sbf.length()>0){

sbf.append(" <- ");

sbf.append(System.getProperty(“line.separator”));

}

sbf.append(java.text.MessageFormat.format("{0}.{1}() {2}"

,e.getClassName()

,e.getMethodName()

,e.getLineNumber()));

}

logger.info(prefix

  • “\n************************************************************\n”

  • sbf.toString()

  • “\n************************************************************”);

}

  1. find Node.java Here's how :

protected Node(final Environment environment, Collection<Class<? extends Plugin>> classpathPlugins) {

final List resourcesToClose = new ArrayList<>(); // register everything we need to release in the case of an error

boolean success = false;

{

// use temp logger just to say we are starting. we can’t use it later on because the node name might not be set

Logger logger = Loggers.getLogger(Node.class, NODE_NAME_SETTING.get(environment.settings()));

logger.info(“initializing …”);

}

stay logger.info(“initializing …”); Add the following line below this line of code , Is used in elasticsearch Print at startup Node The call stack of a class instance :

printTrack(logger, “Here is stack of Node instance”);

Save it and exit , And then

《 A big factory Java Analysis of interview questions + Back end development learning notes + The latest architecture explanation video + Practical project source code handout 》

【docs.qq.com/doc/DSmxTbFJ1cmN1R2dB】 Full content open source sharing

To compile ;

Compiling and constructing

  1. Enter folder elasticsearch-6.1.2, Carry out orders ./gradlew assemble You can start compiling , Downloading dependencies takes a lot of time , So please wait patiently , During compilation CPU Slightly higher occupancy , Here's the picture :

 Insert picture description here

  1. about 10 In a few minutes , Compile and build successfully , The console is shown below :

Task :test:fixtures:old-elasticsearch:javadocJar

Building without git revision id.

Task :test:fixtures:old-elasticsearch:sourcesJar

Building without git revision id.

BUILD SUCCESSFUL in 11m 3s

473 actionable tasks: 473 executed

  1. After compilation , Entry directory elasticsearch-6.1.2/distribution/tar/build/distributions You can see the results of successful construction :elasticsearch-6.1.2-SNAPSHOT.tar.gz, This is what is available elasticsearch-6.1.2;

  2. Build the result file to SNAPSHOT As a filename suffix , If you don't want this suffix , Use the following command when compiling :

./gradlew assemble -Dbuild.snapshot=false

Verify the built elasticsearch Is it available

  1. decompression elasticsearch-6.1.2-SNAPSHOT.tar.gz To a directory ;

  2. Entry directory elasticsearch-6.1.2-SNAPSHOT/config, modify network.host The configuration is 0.0.0.0, Here's the picture :

 Insert picture description here

  1. Entry directory elasticsearch-6.1.2-SNAPSHOT/bin, perform ./elasticsearch Command startup service ;

  2. On the console, you can see the log of the newly added code , take Node The call stack of the class is printed out , We also take this opportunity to learn elasticsearch Key classes involved in startup :

[2019-04-20T04:02:55,785][INFO ][o.e.n.Node ] [] initializing …

[2019-04-20T04:02:55,789][INFO ][o.e.n.Node ] [] Here is stack of Node instance


java.lang.Thread.getStackTrace() 1,559 <-

org.elasticsearch.node.Node.printTrack() 953 <-

copyright:author[m0_ sixty-four million three hundred and eighty-three thousand ],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/01/202201261520159837.html