Debug Solr code – Remote Debug and Local

Solr is a very popular tool for enabling search.
It’s open-source, so you can easily download its source code.

Here is the git repository for Solr –
https://github.com/apache/lucene-solr

I wanted to use a specific version of Solr – (6.0.0)
Hence, I checked out the branch – branch_6_0
Well, now you have the code and the right branch. Let’s setup debug.

Prerequisites –

Ant should be installed on your machine.
I used IntelliJ IDE, so the instructions in this blog are specific to IntelliJ. The steps for Eclipse should not be very different.

Read the basic of contributing to Solr project –
http://wiki.apache.org/solr/HowToContribute

Let’s start setting up the debug environment now –
Assuming you checkout out the git code, you will now have a folder called lucene-solr.

Do the following –

cd lucene-solr
ant ivy-bootstrap
ant idea

cd solr (which is inside top level lucene-solr directory)
ant server
ant dist
ant package

Now open your project (lucene-solr) in IntelliJ

There are two ways to debug Solr.

1. Remote debug –

solr-remote-debug

In IntelliJ create a remote debug run configuration. Choose a port number (I think default is 6900).
Now IntelliJ will give you a “Commandline arguments for running remote JVM”.
Copy that line

Now start solr cloud with that line after “-a” option. Here is the command I used –
Assuming you are in the solr directory now –

./bin/solr start -a "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=6900" -e cloud

Solr will ask you for a number of options. I usually just start solr locally with one node. Collection name I chose was “mycollection”.

After solr is up go to IntelliJ and hit debug for the remote debug run configuration we just created.

Voila! You are now debugging Solr.

To do a quick check, that your remote debug environment is setup, you can set a breakpoint at –
org.apache.solr.parser.QueryParser (TopLevelQuery method or Query method).
Now, go to solr admin (http://localhost:8983/solr/#/mycollection/query) and query for documents.
This should hit your breakpoint!!

2. Local Debug –

start-jar-vm-options

solr-start-jar-debug

Follow the steps above to run solr. Now do a “ps -ef | grep solr” to see the details of the solr command.
The solr start script actually runs a jar file called start.jar located in solr/server directory.
We will basically be setting up a debug configuration to start debugging that jar file.
And we need to use the same JAVA options that were set by the solr start script (from the results of ps -ef command).

In IntelliJ create a jar debug configuration.
Use the following options –
debug the start.jar

Create a jar debug config on IntelliJ

Path to Jar
/lucene-solr/solr/server/start.jar

Program arguments –
-server –module=http

Working directory –
/lucene-solr/solr/server

Search sources using module’s classpath –

VM Options
-Xms512m
-Xmx512m
-XX:NewRatio=3
-XX:SurvivorRatio=4
-XX:TargetSurvivorRatio=90
-XX:MaxTenuringThreshold=8
-XX:+UseConcMarkSweepGC
-XX:+UseParNewGC
-XX:ConcGCThreads=4
-XX:ParallelGCThreads=4
-XX:+CMSScavengeBeforeRemark
-XX:PretenureSizeThreshold=64m
-XX:+UseCMSInitiatingOccupancyOnly
-XX:CMSInitiatingOccupancyFraction=50
-XX:CMSMaxAbortablePrecleanTime=6000
-XX:+CMSParallelRemarkEnabled
-XX:+ParallelRefProcEnabled
-verbose:gc
-XX:+PrintHeapAtGC
-XX:+PrintGCDetails
-XX:+PrintGCDateStamps
-XX:+PrintGCTimeStamps
-XX:+PrintTenuringDistribution
-XX:+PrintGCApplicationStoppedTime
-Xloggc:/lucene-solr/solr/server/logs/solr_gc.log
-DzkClientTimeout=15000
-DzkRun
-Djetty.port=8983
-DSTOP.PORT=7983
-DSTOP.KEY=solrrocks
-Duser.timezone=UTC
-Djetty.home=/lucene-solr/solr/server
-Dsolr.solr.home=/lucene-solr/solr/server/solr
-Dsolr.install.dir=/lucene-solr/solr
-Xss256k

Voila! You have started Solr in debug mode locally!!

To do a quick check, that your remote debug environment is setup, you can set a breakpoint at –
org.apache.solr.parser.QueryParser (TopLevelQuery method or Query method).
Now, go to solr admin (http://localhost:8983/solr/#/mycollection/query) and query for documents.
This should hit your breakpoint!!

1 thought on “Debug Solr code – Remote Debug and Local

Leave a Reply

Your email address will not be published. Required fields are marked *

Answer this * Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.