[英]org.apache.ignite.IgniteException: Failed to find deployed service
[英]Apache Ignite Failed to find SQL table
我正在開發一個 spring 應用程序以連接到 apache Ignite 緩存以獲取記錄。 首先,我運行 DataNode 緩存代碼(如下所述)以從數據庫中獲取所有數據。 接下來,當我嘗試運行客戶端代碼以查詢不同應用程序中的緩存時。 我收到錯誤消息“找不到類型的 SQL 表:Person”
DataNode 緩存代碼:
CacheConfiguration<String, Person> personCache = new CacheConfiguration<String, Person>();
personCache.setName("person:cache");
personCache.setRebalanceMode(CacheRebalanceMode.SYNC);
personCache.setReadThrough(true);
personCache.setWriteThrough(false);
personCache.setWriteBehindEnabled(false);
personCache.setCacheMode(CacheMode.PARTITIONED);
personCache.setIndexedTypes(String.class, Person.class);
personCache.setEvictionPolicy(new LruEvictionPolicy<>(100000));
personCache.setOnheapCacheEnabled(true);
personCache.setCacheStoreFactory(FactoryBuilder.factoryOf(PersonCacheStore.class));
configuration.setCacheConfiguration(personCache);
TcpDiscoverySpi tcpDiscoverySpi = new TcpDiscoverySpi();
TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
ipFinder.setAddresses(Arrays.asList("127.0.0.1:47500"));
tcpDiscoverySpi.setIpFinder(ipFinder);
configuration.setDiscoverySpi(tcpDiscoverySpi);
IgniteCache<String, Person> personCache = ignite.getOrCreateCache("person:cache");
personCache.loadCache(null);
人:
public class Person implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@QuerySqlField
private String name;
private Date dob;
public Person() {
super();
}
public Person(String name, Date dob) {
super();
this.name = name;
this.dob = dob;
}
}
個人緩存存儲:
public class PersonCacheStore implements CacheStore<String, Person> {
public Person load(String name) throws CacheLoaderException {
// code to load data from DB.
}
public void loadCache(IgniteBiInClosure<String, Person> clo, Object... arg1) throws CacheLoaderException {
// code to load data from DB.
}
}
查詢緩存的客戶端代碼:
IgniteConfiguration configuration = new IgniteConfiguration();
configuration.setClientMode(true);
TcpDiscoverySpi tcpDiscoverySpi = new TcpDiscoverySpi();
TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
ipFinder.setAddresses(Arrays.asList("127.0.0.1:47500"));
tcpDiscoverySpi.setIpFinder(ipFinder);
configuration.setDiscoverySpi(tcpDiscoverySpi);
Ignite ignite = Ignition.start(configuration);
IgniteCache<String, Person> cache = ignite.getOrCreateCache("person:cache");
SqlQuery<String, Person> qry2 = new SqlQuery<String, Person>(Person.class,
"select * from Person where name = ?");
qry2.setArgs("Ram");
List<Entry<String, Person>> res = cache.query(qry2).getAll();
for (Entry<String, Person> entry : res) {
}
幫我解決這個問題。
目前尚不清楚您如何在DataNode
上創建緩存。 您創建了一個CacheConfiguration
對象,然后將其添加到 Ignite 配置中,但實際上在您啟動節點后會發生這種情況。 如果是這種情況,則緩存是使用默認設置創建的,因此不知道 SQL 配置。
有兩個選項可以修復:
Ignition.start()
之前完全創建IgniteConfiguration
(包括CacheConfiguration
)。 然后使用ignite.cache("person:cache")
獲取緩存; 如果你這樣做而不是使用getOrCreateCache
,你將得到null
而不是錯誤配置的緩存,以防萬一你搞砸了,所以更容易定位問題。CacheConfiguration
作為IgniteConfiguration
一部分,並使用getOrCreateCache
提供配置對象而不只是名稱來創建緩存。這是文檔中的示例: 注冊索引類型。
正好解決你的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.