我正在尝试将Cassandra配置为Apache Ignite 2.0缓存的持久存储。作为测试,我试图将键值对映射到这个简单的Cassandra表:
CREATE TABLE ignite.cache_test(
key text PRIMARY KEY,
value int)
我正在使用的关联持久性配置xml:
<persistence keyspace="ignite" table="cache_test" ttl="86400">
<keyspaceOptions>
REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 1}
AND DURABLE_WRITES = true
</keyspaceOptions>
<tableOptions>
comment = 'Cache test'
AND read_repair_chance = 0.2
</tableOptions>
<keyPersistence class="java.lang.String" strategy="PRIMITIVE" column="key" />
<valuePersistence class="java.lang.Integer" strategy="PRIMITIVE" column="value" />
</persistence>
当我尝试使用Ignite REST接口将元素放入缓存时,我得到:
com.datastax.driver.core.exceptions.CodecNotFoundException: Codec not found for requested operation: [int <-> java.lang.String]
好像我正在尝试将int映射到String类型。我确信这是一个愚蠢的配置错误,但我尝试了几种组合但没有成功。
为了完整性,这是我发送的http电话:
http://localhost:8080/ignite?cmd=put&key=testkey&val=1&cacheName=cache1
谢谢大家的帮助
答案 0 :(得分:1)
将值类型更改为文本
表模式:
CREATE TABLE ignite.cache_test(
key text PRIMARY KEY,
value text
);
配置:
<persistence keyspace="ignite" table="cache_test" ttl="86400">
<keyspaceOptions>
REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 1}
AND DURABLE_WRITES = true
</keyspaceOptions>
<tableOptions>
comment = 'Cache test'
AND read_repair_chance = 0.2
</tableOptions>
<keyPersistence class="java.lang.String" strategy="PRIMITIVE" column="key" />
<valuePersistence class="java.lang.String" strategy="PRIMITIVE" column="value" />
</persistence>