Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Solr Cookbook - Third Edition

You're reading from   Solr Cookbook - Third Edition Solve real-time problems related to Apache Solr 4.x and 5.0 effectively with the help of over 100 easy-to-follow recipes

Arrow left icon
Product type Paperback
Published in Jan 2015
Publisher
ISBN-13 9781783553150
Length 356 pages
Edition 3rd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Rafal Kuc Rafal Kuc
Author Profile Icon Rafal Kuc
Rafal Kuc
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Apache Solr Configuration FREE CHAPTER 2. Indexing Your Data 3. Analyzing Your Text Data 4. Querying Solr 5. Faceting 6. Improving Solr Performance 7. In the Cloud 8. Using Additional Functionalities 9. Dealing with Problems 10. Real-life Situations Index

Configuring the Solr heartbeat mechanism

Solr is designed to be scalable, fault tolerant, and have a high up time so that we can have our search service always ready. Many of the deployments, whether they are still master-slave setups or SolrCloud ones, still use some kind of load-balancing and health-checking mechanism. Solr comes with a request handler that is designed to handle health-checking requests, and this recipe will show you how to set it up.

How to do it...

Setting up the heartbeat mechanism in Solr is very easy. One just needs to add the following section to the solrconfig.xml file:

<requestHandler name="/admin/ping" class="solr.PingRequestHandler">
 <lst name="invariants">
  <str name="q">solrpingquery</str>
 </lst>
</requestHandler>

This is all. Of course, if we need all our cores and collections to respond to the health requests, we should include the previous section in the solrconfig.xml files for all of them. After this, run a query to the admin/ping handler of our Solr instance, for example:

curl 'localhost:8983/solr/heartbeat_core/admin/ping'

Solr will respond with a status response, for example:

<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">0</int><int name="QTime">6</int><lst name="params"/></lst><str name="status">OK</str>
</response>

How it works...

The configuration is really simple; we defined a new request handler that will be available under the /admin/ping address (of course, we have to prefix it with the host address and core name). The class implementing the handle is the one dedicated to handle the heartbeat mechanism request, solr.PingRequestHandler. We also defined that the q parameter for all the ping requests will be solrpingquery and the request won't be able to overwrite this parameter (because we included it in the invariants section). The ping query should be as simple as it can get so that it runs blazingly fast; what's more, it is usually good for it not to return any search results.

As you can see, the response contains the status section, which in our case has the value of OK. In the case of an error, the status section will contain the error code.

There's more...

The solr.PingRequestHandler handler allows us to enable and disable the heartbeat mechanism without shutting down the whole Solr instance.

Enabling and disabling the heartbeat mechanism

If we want to disable and enable the heartbeat mechanism without taking down the whole Solr instance, we need to introduce a property called healthcheckFile to our request handler configuration, for example:

<requestHandler name="/admin/ping" class="solr.PingRequestHandler">
 <lst name="invariants">
  <str name="q">solrpingquery</str>
 </lst>
 <str name="healthcheckFile">server-enabled.txt</str>
</requestHandler>

Now, to enable the heartbeat mechanism, one should run the following command:

curl 'localhost:8983/solr/heartbeat_core/admin/ping?action=enable'

By running this, Solr will create a file named server-enabled.txt in the directory the data directory is located at. This file will contain information about when the heartbeat mechanism is enabled.

To disable the heartbeat mechanism, one should run the following command:

curl 'localhost:8983/
solr/heartbeat_core/admin/ping?action=disable'

This command will delete the previously created file.

We can also check the heartbeat status by running the following command:

curl 'localhost:8983/solr/heartbeat_core/admin/ping?action=status'
You have been reading a chapter from
Solr Cookbook - Third Edition - Third Edition
Published in: Jan 2015
Publisher:
ISBN-13: 9781783553150
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image