【发布时间】:2016-05-01 00:19:39
【问题描述】:
我们正在使用 Spring Cassandra 和 datastax 驱动程序使用 CachedPreparedStatementCreator/PreparedStatement 向 Cassandra 发出请求。在启动时,这些 WARN 消息会显示在日志文件中(还有其他的,这只是一个示例)
:WARN lg:com.datastax.driver.core.Cluster - 重新准备已准备好的查询插入到活动(id)值(?)使用 TTL?。请注意,多次准备同一个查询通常是一种反模式,并且可能会影响性能。考虑只准备一次声明。
准备好的语句是使用 CachedPreparedStatementCreator 类创建的。查看源代码,似乎存在“竞争条件”并且实现不是线程安全的。
Map<String, PreparedStatement> sessionMap = psMap.get(session);
if (sessionMap == null) {
sessionMap = new ConcurrentHashMap<String, PreparedStatement>();
psMap.put(session, sessionMap);
}
PreparedStatement pstmt = sessionMap.get(keyspaceCQLKey.toString());
if (pstmt == null) {
log.debug("No Cached PreparedStatement found...Creating and Caching");
pstmt = session.prepare(this.cql);
sessionMap.put(keyspaceCQLKey.toString(), pstmt);
} else {
log.debug("Found cached PreparedStatement");
}
这门课的目的是什么?它是线程安全的吗?有人会知道有关此缓存性能的任何信息吗?
【问题讨论】:
-
Hopper SR2 版本修复了这个问题。
标签: java spring cassandra datastax