Environment: ES-5.4.0 version, deployment method: 3master+2client+3datanode
Description: Datanode and client are configured with Http.enabled:false, program in writing data times wrong: No data nodes with http-enabled available
SOURCE Analysis:
public static void filternondatanodesifneeded (Settings Settings, log log) { if (!settings.getnodesdataonly ()) { return; } Restclient bootstrap = new restclient (settings); Try { String message = "No data nodes with http-enabled available"; list<nodeinfo> datanodes = Bootstrap.gethttpdatanodes ();
Datanodes will be error if (Datanodes.isempty ()) { throw new eshadoopillegalargumentexception (message); } . .. } finally { bootstrap.close (); }}
Next, take a look at the value logic of the Restclient.gethttpdatanodes () method
Public list<nodeinfo> Gethttpdatanodes () {list<nodeinfo> nodes = Gethttpnodes (false);
Traverse the node acquired above iterator<nodeinfo> it = Nodes.iterator (); while (It.hasnext ()) {nodeinfo node = It.next ();
If it is not a data node, remove if (!node.isdata ()) {it.remove (); }} return nodes;}
Gets the HTTP node _nodes/httppublic list<nodeinfo> gethttpnodes (Boolean clientnodeonly) {
Get nodes information through the ES interface "_nodes/http" map<string, map<string, object>> nodesdata = Get ("_nodes/http", "nodes") ; list<nodeinfo> nodes = new arraylist<nodeinfo> (); For (entry<string, map<string, object>> Entry:nodesData.entrySet ()) {nodeinfo node = new NodeInfo (en Try.getkey (), Entry.getvalue ());
If you are not looking for a client node, you can add if the node is running network access, and if you are looking for a client node, you will also pass Isclient authentication to add if (Node.hashttp () && (!clientnodeon ly | | Node.isclient ())) {Nodes.Add (node); }} return nodes;}
Finally, take a look at the method of Node.hashttp (), Isclient (), Isdata ( )
Private final String ID; Private final String name; Private final String host; Private final String IP; Private final String publishaddress; Private Final Boolean hashttp; Private Final Boolean isclient; Private Final Boolean isdata; Private Final Boolean isingest; Public NodeInfo (String ID, map<string, object> Map) {this.id = ID; Esmajorversion Version = Esmajorversion.parse ((String) map.get ("version"); THIS.name = (String) map.get ("name"); This.host = (String) map.get ("host"); This.ip = (String) map.get ("IP");
5.0 the following version of the branch if (Version.before (esmajorversion.v_5_x)) {map<string, object> attributes = (map< ; String, object>) map.get ("attributes"); if (attributes = = null) {this.isclient = false; This.isdata = true; } else {String data = (string) attributes.get ("Data"); this.isclient = data = = null? true:! Boolean.parseboolean (data); This.isdata = data = = null? True:Boolean.parseBoolean (data); } this.isingest = false;
Branches with more than 5.0 versions} else {list<string> roles = (list<string>) map.get ("roles");
If the roles list does not contain "data", then this node is client this.isclient = roles.contains ("data") = = false;
If the roles list contains "data", then this node is data This.isdata = roles.contains ("Data");
If the roles list contains "ingest", then this node is ingest this.isingest = Roles.contains ("ingest"); } map<string, object> httpmap = (map<string, object>) map.get ("http");
If the node data contains key:http if (httpmap! = null) {String addr = (string) httpmap.get ("publish_address");
If the HTTP data contains key:publish_address if (addr! = null) {Stringutils.ipandport Ipandport = Stringut Ils.parseipaddress (addr); this.publishaddress = Ipandport.ip + ":" + ipandport.port;
This node can provide HTTP services, namely:http.enabled:trueThis.hashttp = true; } else {this.publishaddress = null; This.hashttp = false; }} else {this.publishaddress = null; This.hashttp = false; } }
From the above source analysis can be concluded: If a data node does not configure http.enabled:true, then this node will not be searched by the Gethttpdatanodes () method, then the exception will be thrown directly: no data nodes with Http-enabled available
There are two ways to solve this problem:
First: Data node configuration http.enabled:true
Second: Bypass filternondatanodesifneeded () check, need Settings.getnodesdataonly () return false; see the source below, The default es.nodes.data.only is true, which is set to false in the client.
/** clients only */string es_nodes_client_only = "Es.nodes.client.only"; String Es_nodes_client_only_default = "false";/** Data only */string es_nodes_data_only = "Es.nodes.data.only"; String Es_nodes_data_only_default = "true";/** Ingest only */string es_nodes_ingest_only = "Es.nodes.ingest.only"; String Es_nodes_ingest_only_default = "false";/** WAN only */string es_nodes_wan_only = "Es.nodes.wan.only"; String Es_nodes_wan_only_default = "false"; public boolean getnodesdataonly () {//by DEFAULT, if not set, return a V Alue compatible with the other settings
The default es.nodes.data.only is true, which is set to false in the client to return Booleans.parseboolean (GetProperty (es_nodes_data_only),! Getnodeswanonly () &&!getnodesclientonly () &&!getnodesingestonly ());} public Boolean getnodesingestonly () {return Booleans.parseboolean (GetProperty (es_nodes_ingest_only, Es_nodes_ingest _only_default));} public Boolean getnodesclientonly () {return Booleans.parseboolean (GetProperty (es_nodes_client_only, es_nodes_client _only_default));} public Boolean getnodeswanonly () {return Booleans.parseboolean (GetProperty (es_nodes_wan_only, Es_nodes_wan_only_ DEFAULT));}
ElasticSearch problem Analysis: No data nodes with http-enabled available