private PreparedStatement getCachedPreparedStatement(final String cql) {
    final CachedPreparedStatementCreator cachedPreparedStatementCreator =
        new CachedPreparedStatementCreator(cql);
    final PreparedStatement preparedStatement =
        cachedPreparedStatementCreator.createPreparedStatement(cassandraTemplate.getSession());

    preparedStatement.setConsistencyLevel(ConsistencyLevel.ONE);

    return preparedStatement;
  }
  public static void waitForSchemaVersionsToCoalesce(
      String encapsulatingOperationDescription, CQLKeyValueService kvs) {
    PreparedStatement peerInfoQuery =
        kvs.getPreparedStatement(
            CassandraConstants.NO_TABLE,
            "select peer, schema_version from system.peers;",
            kvs.session);
    peerInfoQuery.setConsistencyLevel(ConsistencyLevel.ALL);

    Multimap<UUID, InetAddress> peerInfo = ArrayListMultimap.create();
    long start = System.currentTimeMillis();
    long sleepTime = 100;
    do {
      peerInfo.clear();
      for (Row row : kvs.session.execute(peerInfoQuery.bind()).all()) {
        peerInfo.put(row.getUUID("schema_version"), row.getInet("peer"));
      }

      if (peerInfo.keySet().size() <= 1) { // full schema agreement
        return;
      }
      sleepTime = Math.min(sleepTime * 2, 5000);
    } while (System.currentTimeMillis()
        < start + CassandraConstants.SECONDS_WAIT_FOR_VERSIONS * 1000);

    StringBuilder sb = new StringBuilder();
    sb.append(
        String.format(
            "Cassandra cluster cannot come to agreement on schema versions, during operation: %s.",
            encapsulatingOperationDescription));

    for (Entry<UUID, Collection<InetAddress>> versionToPeer : peerInfo.asMap().entrySet()) {
      sb.append(String.format("\nAt schema version %s:", versionToPeer.getKey()));
      for (InetAddress peer : versionToPeer.getValue()) {
        sb.append(String.format("\n\tNode: %s", peer));
      }
    }
    sb.append(
        "\nFind the nodes above that diverge from the majority schema "
            + "(or have schema 'UNKNOWN', which likely means they are down/unresponsive) "
            + "and examine their logs to determine the issue. Fixing the underlying issue and restarting Cassandra "
            + "should resolve the problem. You can quick-check this with 'nodetool describecluster'.");
    throw new IllegalStateException(sb.toString());
  }