title: How to speeden up schema agreement in Cassandra?
body: <p>I have a 3 node 2.x Cassandra cluster with an out of the box configuration. My java program uses the datastax driver (2.19) to create the schema by executing CQL/DDL statements one at a time. What I am finding is that many times schema changes take tens of seconds for schema agreement for several statements. The statement which takes a long time is pretty much random.</p>
  
  <p>I am looking for tips on how to improve the speed of schema agreement. </p>
  
  <p>Note :- when I create the schema using cqlsh it's pretty fast. </p>
  
  <p>UPDATE 08/12/2016</p>
  
  <p>I added the following code to execute a statement and then wait for schema agreement so that I could get a little more insight into how long the wait is. </p>
  
  <pre class="lang-java prettyprint-override"><code>private void executeStatement(String statement, PrintStream out) throws DBInstallerException {
      int retries = 0;
      final ResultSet resultSet = session.execute(statement);
  
      if (!resultSet.getExecutionInfo().isSchemaInAgreement()) {
          for (; retries &lt; TOTAL_WAIT_FOR_SCHEMA_AGREEMENT_IN_SECONDS; retries++) {
              Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
              if (cluster.getMetadata().checkSchemaAgreement()) {
                  break;
              }
          }
      }
  
      if (retries &gt;= TOTAL_WAIT_FOR_SCHEMA_AGREEMENT_IN_SECONDS) {
          throw new DBInstallerException("Failed to get schema agreement after " + TOTAL_WAIT_FOR_SCHEMA_AGREEMENT_IN_SECONDS + " seconds");
      } else {
          if (retries &gt; 0 ) {
              out.println("INFO : Got schema agreement after " + retries + " retries");
          }
      }
  }
  </code></pre>
  
  <p>Many times I get the "Got schema agreement after " output printed to console and the retries can be as many as 300. This is what does not make sense to me. How could any schema change take that long to execute on a system which is essentially idle.</p>