# LegacyDefaultLoadBalancingPolicy

<div class="jsdoc-content"><header>
    
        <h2><span class="attribs"><span class="type-signature"></span></span>
            <span class="ancestors"><a href="index.html">policies/loadBalancing</a>~</span>LegacyDefaultLoadBalancingPolicy<span class="signature">(options<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h2>
        
            <div class="class-description"><p>A load-balancing policy implementation that attempts to fairly distribute the load based on the amount of in-flight
request per hosts. The local replicas are initially shuffled and
<a href="https://www.eecs.harvard.edu/~michaelm/postscripts/mythesis.pdf">between the first two nodes in the
shuffled list, the one with fewer in-flight requests is selected as coordinator</a>.</p>
<p>Additionally, it detects unresponsive replicas and reorders them at the back of the query plan.</p>
<p>For graph analytics queries, it uses the preferred analytics graph server previously obtained by driver as first
host in the query plan.</p></div>
        
    
</header>


    
        

    
    </div>

## Constructor

<div class="jsdoc-content">
    

    
    <h4 class="name" id="LegacyDefaultLoadBalancingPolicy"><span class="type-signature"></span>new LegacyDefaultLoadBalancingPolicy<span class="signature">(options<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    <p>Creates a new instance of <code>LegacyDefaultLoadBalancingPolicy</code>.</p>
</div>









    <h5>Parameters:</h5>
    

<table class="params docutils align-default">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        
        <th>Attributes</th>
        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>options</code></td>
            

            <td class="type">
            
                
<span class="param-type">String</span>
|

<span class="param-type">Object</span>


            
            </td>

            
                <td class="attributes">
                
                    &lt;optional><br>
                

                

                
                </td>
            

            

            <td class="description last"><p>The local data center name or the optional policy options object.</p>
<p>Note that when providing the local data center name, it overrides <code>localDataCenter</code> option at
<code>Client</code> level.</p>
                <h6>Properties</h6>
                

<table class="params docutils align-default">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        
        <th>Attributes</th>
        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>localDc</code></td>
            

            <td class="type">
            
                
<span class="param-type">String</span>


            
            </td>

            
                <td class="attributes">
                
                    &lt;optional><br>
                

                

                
                </td>
            

            

            <td class="description last"><p>local data center name.  This value overrides the 'localDataCenter' Client option
and is useful for cases where you have multiple execution profiles that you intend on using for routing
requests to different data centers.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>filter</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            
                <td class="attributes">
                
                    &lt;optional><br>
                

                

                
                </td>
            

            

            <td class="description last"><p>A function to apply to determine if hosts are included in the query plan.
The function takes a Host parameter and returns a Boolean.</p></td>
        </tr>

    
    </tbody>
</table>

            </td>
        </tr>

    
    </tbody>
</table>






<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/policies/load-balancing.js#L289" target="_blank" rel="noopener">policies/load-balancing.js, line 289</a></p></div>




















    
    

    

    

    

    

    

    

    

    
        </div>

## Methods

<div class="jsdoc-content">

        
            

    

    
    <h4 class="name" id="getDistance"><span class="type-signature"></span>getDistance<span class="signature">(host)</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    <p>Returns the distance assigned by this policy to the provided host, relatively to the client instance.</p>
</div>









    <h5>Parameters:</h5>
    

<table class="params docutils align-default">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>host</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="Host.html">Host</a></span>


            
            </td>

            

            

            <td class="description last"></td>
        </tr>

    
    </tbody>
</table>






<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/policies/load-balancing.js#L368" target="_blank" rel="noopener">policies/load-balancing.js, line 368</a></p></div>




















        
            

    

    
    <h4 class="name" id="getOptions"><span class="type-signature"></span>getOptions<span class="signature">()</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    <p>Gets an associative array containing the policy options.</p>
</div>













<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/policies/load-balancing.js#L642" target="_blank" rel="noopener">policies/load-balancing.js, line 642</a></p></div>




















        
            

    

    
    <h4 class="name" id="init"><span class="type-signature"></span>init<span class="signature">(client, hosts, callback)</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    <p>Initializes the load balancing policy, called after the driver obtained the information of the cluster.</p>
</div>









    <h5>Parameters:</h5>
    

<table class="params docutils align-default">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>client</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="../../Client.html">Client</a></span>


            
            </td>

            

            

            <td class="description last"></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>hosts</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="HostMap.html">HostMap</a></span>


            
            </td>

            

            

            <td class="description last"></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last"></td>
        </tr>

    
    </tbody>
</table>






<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/policies/load-balancing.js#L347" target="_blank" rel="noopener">policies/load-balancing.js, line 347</a></p></div>




















        
            

    

    
    <h4 class="name" id="newQueryPlan"><span class="type-signature"></span>newQueryPlan<span class="signature">(keyspace, executionOptions, callback)</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    <p>Returns a host iterator to be used for a query execution.</p>
</div>









    <h5>Parameters:</h5>
    

<table class="params docutils align-default">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>keyspace</code></td>
            

            <td class="type">
            
                
<span class="param-type">String</span>


            
            </td>

            

            

            <td class="description last"></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>executionOptions</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="../../ExecutionOptions.html">ExecutionOptions</a></span>


            
            </td>

            

            

            <td class="description last"></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last"></td>
        </tr>

    
    </tbody>
</table>






<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/policies/load-balancing.js#L391" target="_blank" rel="noopener">policies/load-balancing.js, line 391</a></p></div>




















        
            

    

    
    <h4 class="name" id="yieldReplicasFirst"><span class="type-signature">(generator) </span>yieldReplicasFirst<span class="signature">(replicas)</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    <p>Yields the local replicas followed by the rest of local nodes.</p>
</div>









    <h5>Parameters:</h5>
    

<table class="params docutils align-default">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>replicas</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array&lt;<a href="Host.html">Host</a>></span>


            
            </td>

            

            

            <td class="description last"><p>The local replicas</p></td>
        </tr>

    
    </tbody>
</table>






<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.6.1/lib/policies/load-balancing.js#L547" target="_blank" rel="noopener">policies/load-balancing.js, line 547</a></p></div></div>
