title: NoHostAvailable Exception on Async operations with Datastax Cassandra driver
body: <p>I'm using nested Asynchronous query execution with Cassandra. Data is continuously streamed in and for each incoming data, the below block of <code>cassandra</code> operations are executed. It works fine for a while but then starts throwing a lot of <code>NoHostAvailableException</code>.<br>
  Please me help me out here.
  Cassandra Session Connection code : </p>
  
  <p>I use separate sessions for read and write. Each of these sessions connect to a different seed as I was told this would improve performance.</p>
  
  <pre><code>final com.datastax.driver.core.Session readSession = CassandraManager.connect("10.22.1.144", "fr_repo",
                      "READ");
              final com.datastax.driver.core.Session writeSession = CassandraManager.connect("10.1.12.236", "fr_repo",
                      "WRITE");
  </code></pre>
  
  <p>The <code>CassandraManager.connect</code> method is  below : </p>
  
  <pre><code>public static  Session connect(String ip, String keySpace,String type) {
             PoolingOptions poolingOpts = new PoolingOptions();
             poolingOpts.setCoreConnectionsPerHost(HostDistance.REMOTE, 2);
             poolingOpts.setMaxConnectionsPerHost(HostDistance.REMOTE, 400);
             poolingOpts.setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance.REMOTE, 128);
             poolingOpts.setMinSimultaneousRequestsPerConnectionThreshold(HostDistance.REMOTE, 2);
             cluster = Cluster
               .builder()
               .withPoolingOptions( poolingOpts )
               .addContactPoint(ip)
               .withRetryPolicy( DowngradingConsistencyRetryPolicy.INSTANCE )
               .withReconnectionPolicy( new ConstantReconnectionPolicy( 100L ) ).build();
             Session s =  cluster.connect(keySpace);
             return s;
      }
  </code></pre>
  
  <p>Database operation code : </p>
  
  <pre><code>ResultSetFuture resultSetFuture = readSession.executeAsync(selectBound.bind(fr.getHashcode()));
                      Futures.addCallback(resultSetFuture, new FutureCallback&lt;ResultSet&gt;() {
                          public void onSuccess(com.datastax.driver.core.ResultSet resultSet) {
                              try {
                                  Iterator&lt;Row&gt; rows = resultSet.iterator();
                                  if (!rows.hasNext()) {
                                      ResultSetFuture resultSetFuture = readSession.executeAsync(selectPrimaryBound
                                              .bind(fr.getPrimaryKeyHashcode()));
                                      Futures.addCallback(resultSetFuture, new FutureCallback&lt;ResultSet&gt;() {
                                          public void onFailure(Throwable arg0) {
  
                                          }
  
                                          public void onSuccess(ResultSet arg0) {
                                              Iterator&lt;Row&gt; rows = arg0.iterator();
                                              if (!rows.hasNext()) {
                                                  writeSession.executeAsync(insertBound.bind(fr.getHashcode(), fr,
                                                          System.currentTimeMillis()));
                                                      writeSession.executeAsync(insertPrimaryBound.bind(
                                                              fr.getHashcode(),
                                                              fr.getCombinedPrimaryKeys(), System.currentTimeMillis()));
                                                  produceintoQueue(new Gson().toJson(frCompleteMap));
  
                                              } else {
                                                  writeSession.executeAsync(updateBound.bind(fr,
                                                          System.currentTimeMillis(), fr.getHashcode()));
                                                  produceintoQueue(new Gson().toJson(frCompleteMap));
                                              }
                                          }
  
                                      });
  
                                  } else {
                                      writeSession.executeAsync(updateLastSeenBound.bind(System.currentTimeMillis(),
                                          fr.getHashcode()));
  
                                  }
                              } catch (Exception e) {
                                  e.printStackTrace();
                              }
  
                          }
  </code></pre>