Astyanax/Cassandra - Getting "Re-preparing already prepared query" warning with caching enabled

537 views Asked by At

I'm trying to insert some data to Cassandra with Astyanax, by I'm getting a lot of "Re-preparing already prepared query" warnings even if have caching enabled:

22:08:03,703  WARN Cluster:1702 - Re-preparing already prepared query INSERT INTO test.test (key,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9) VALUES (?,?,?,?,?,?,?,?,?,?,?) . Please note that preparing the same query more than once is generally an anti-pattern and will likely affect performance. Consider preparing the statement only once.
22:08:03,707  WARN Cluster:1702 - Re-preparing already prepared query INSERT INTO test.test (key,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9) VALUES (?,?,?,?,?,?,?,?,?,?,?) . Please note that preparing the same query more than once is generally an anti-pattern and will likely affect performance. Consider preparing the statement only once.
22:08:03,708  WARN Cluster:1702 - Re-preparing already prepared query INSERT INTO test.test (key,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9) VALUES (?,?,?,?,?,?,?,?,?,?,?) . Please note that preparing the same query more than once is generally an anti-pattern and will likely affect performance. Consider preparing the statement only once.

Source code:

Connect: (executed once)

@Override
public void connect() throws ClientException {
    AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
            .forCluster(clusterName)
            .forKeyspace(keyspaceName)
            .withHostSupplier(new Supplier<List<Host>>() {
                @Override
                public List<Host> get() {
                    return Collections.singletonList(new Host(host, 9160));
                }
            })
            .withAstyanaxConfiguration(
                    new AstyanaxConfigurationImpl().setDiscoveryType(NodeDiscoveryType.DISCOVERY_SERVICE)
                            .setDiscoveryDelayInSeconds(60000))
            .withConnectionPoolConfiguration(new JavaDriverConfigBuilder().build())
            .buildKeyspace(CqlFamilyFactory.getInstance());

    context.start();
    keyspace = context.getClient();

    columnFamilyTemplate = new ColumnFamily<String, String>(columnFamily,
            StringSerializer.get(), StringSerializer.get());
    try {
        columnFamilyTemplate.describe(keyspace);
    } catch (ConnectionException e) {
        throw new ClientException(e);
    }

    insert = keyspace.prepareMutationBatch().withCaching(true);
}

Insert: (executed multiple times)

insert.discardMutations();
final ColumnListMutation<String> row = insert.withRow(columnFamilyTemplate, key);
for (Map.Entry<String, String> pair : columnValues.entrySet()) {
    final String column = pair.getKey();
    final String value = pair.getValue();
    row.putColumn(column, value, null);
}

try {
    insert.withCaching(true).execute();
} catch (ConnectionException e) {
    throw new ClientException(e);
}

The warning message suggests that the caching is not actually working. Any idea how to fix it?

0

There are 0 answers