All of the classes reponsible for handling the connection to the Elasticsearch cluster. The default subclasses used can be overriden by passing parameters to the Elasticsearch class. All of the arguments to the client will be passed on to Transport, ConnectionPool and Connection.
For example if you wanted to use your own implementation of the ConnectionSelector class you can just pass in the selector_class parameter.
Encapsulation of transport-related to logic. Handles instantiation of the individual connections as well as creating a connection pool to hold them.
Main interface is the perform_request method.
Any extra keyword arguments will be passed to the connection_class when creating and instance unless overriden by that connection’s options provided as part of the hosts parameter.
Create a new Connection instance and add it to the pool.
|Parameters:||host – kwargs that will be used to create the instance|
Mark a connection as dead (failed) in the connection pool. If sniffing on failure is enabled this will initiate the sniffing process.
|Parameters:||connection – instance of Connection that failed|
Perform the actual request. Retrieve a connection from the connection pool, pass all the information to it’s perform_request method and return the data.
If an exception was raised, mark the connection as failed and retry (up to max_retries times).
If the operation was succesful and the connection used was previously marked as dead, mark it as live, resetting it’s failure count.
Instantiate all the connections and crate new connection pool to hold them. Tries to identify unchanged hosts and re-use existing Connection instances.
|Parameters:||hosts – same as __init__|
Obtain a list of nodes from the cluster and create a new connection pool using the information retrieved.
To extract the node connection parameters use the nodes_to_host_callback.
It’s only interactions are with the Transport class that drives all the actions within ConnectionPool.
Initially connections are stored on the class as a list and, along with the connection options, get passed to the ConnectionSelector instance for future reference.
Upon each request the Transport will ask for a Connection via the get_connection method. If the connection fails (it’s perform_request raises a ConnectionError) it will be marked as dead (via mark_dead) and put on a timeout (if it fails N times in a row the timeout is exponentially longer - the formula is default_timeout * 2 ** (fail_count - 1)). When the timeout is over the connection will be resurrected and returned to the live pool. A connection that has been peviously marked as dead and succeedes will be marked as live (it’s fail count will be deleted).
Return a connection from the pool using the ConnectionSelector instance.
It tries to resurrect eligible connections, forces a resurrection when no connections are availible and passes the list of live connections to the selector instance to choose from.
Returns a connection instance and it’s current fail count.
Mark the connection as dead (failed). Remove it from the live pool and put it on a timeout.
|Parameters:||connection – the failed instance|
Mark connection as healthy after a resurrection. Resets the fail counter for the connection.
|Parameters:||connection – the connection to redeem|
Attempt to resurrect a connection from the dead pool. It will try to locate one (not all) eligible (it’s timeout is over) connection to return to th live pool.
|Parameters:||force – resurrect a connection even if there is none eligible (used when we have no live connections)|
Simple class used to select a connection from a list of currently live connection instances. In init time it is passed a dictionary containing all the connections’ options which it can then use during the selection process. When the select method is called it is given a list of currently live connections to choose from.
The options dictionary is the one that has been passed to Transport as hosts param and the same that is used to construct the Connection object itself. When the Connection was created from information retrieved from the cluster via the sniffing process it will be the dictionary returned by the host_info_callback.
Example of where this would be useful is a zone-aware selector that would only select connections from it’s own zones and only fall back to other connections where there would be none in it’s zones.
|Parameters:||opts – dictionary of connection instances and their options|
Select a connection from the given list.
|Parameters:||connections – list of live connections to choose from|
Class responsible for maintaining a connection to an Elasticsearch node. It holds persistent connection pool to it and it’s main interface (perform_request) is thread-safe.
Also responsible for logging.
Log an unsuccessful API call.
Log a successful API call.