2017-06-12 129 views
0

我想卡桑德拉配置作爲一個Apache點燃2.0緩存持久性存儲。作爲測試,我想鍵值對映射到這個簡單的卡桑德拉表:點燃卡桑德拉緩存配置 - CodecNotFoundException

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 

謝謝大家的幫助

回答

1

變化的值類型爲文本

所以表模式:

CREATE TABLE ignite.cache_test(
    key text PRIMARY KEY, 
    value text 
); 

而conf配置:

<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> 
+0

是否可以將其他類型映射爲字符串類型以外的值與PRIMITIVE策略? – riccamini

+0

@riccamini我還沒有與Apache點火工作。你的錯誤意味着您正試圖插入字符串轉換成int類型的字段和我檢查自己的REST API調用https://apacheignite.readme.io/v2.0/docs/rest-api#put他們說清楚,關鍵是字符串鍵入 –

+0

我沒有將鍵字段指定爲字符串類型嗎?或者你建議使用web api的所有類型都將被視爲字符串? – riccamini