0

Having a cluster with a single node :

Node node = NodeBuilder.nodeBuilder().loadConfigSettings(true).node();

What is the difference betwwen

node.close();

and

node.client().admin().cluster().prepareNodesShutdown().execute().actionGet();

?

What's the recommended method to gracefully shutdown the node/cluster from java ?

2 Answers 2

1

Both mentioned operations have the same effect. The difference is, potentially, the nodes they affect.

With node.close() you close your own node, that you started from your application, which can either be the only node you have if you embed the elasticsearch cluster in your application, or just a client node that connects to an external cluster through java api (transport port).

Using the nodes shutdown api you can effectively shutdown remote nodes, potentially multiple nodes and the whole cluster as well in a single operation. As a result, each node in the context of the command will be closed, again calling the close method.

Also, both commands gracefully close nodes.

Sign up to request clarification or add additional context in comments.

Comments

0

If you deign to use shutdown() on unconnected datagram sockets, it will simply make the socket unavailable for further send() and recv() calls (remember that you can use these if you connect() your datagram socket.)

It's important to note that shutdown() doesn't actually close the file descriptor—it just changes its usability. To free a socket descriptor, you need to use close().

However, as far as Elasticserach goes, there API does not mention any difference in particular (just a Client example and a Nodes Shutdown example). These are the common defined differences. It may be best to contact their development (there is an option at the bottom of the website) to get a more detailed explanation on the implementation of their library.

I'd recommend using the node to access the cluster, then loop the cluster and individually close all nodes. However, this depends on what you really want.

2 Comments

I mentioned what I really want in the question : 'gracefully shutdown the node'
I've usually seen close() used with a grace time period. I'm not sure if Elasticsearch's Node class allows for giving a grace period (usually in milliseconds), but if so, you should give a grace period to allow a graceful close/shutdown.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.