Astyanax / Cassandra - 获取"重新准备已经准备好的查询"启用缓存警告

时间:2015-06-17 19:22:36

标签: caching cassandra prepared-statement astyanax

我试图用Astyanax向Cassandra插入一些数据,我得到了很多"重新准备已准备好的查询"即使启用了缓存也会发出警告:

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.

源代码:

连接 :(执行一次)

@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.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);
}

警告消息表明缓存实际上并不起作用。知道怎么解决吗?

0 个答案:

没有答案