java - Apache Ignite 找不到 SQL 表

标签 java spring-boot ignite

我正在开发一个 Spring 应用程序来连接到 apache Ignite 缓存以获取记录。首先,我运行 DataNode 缓存代码(如下所述)以从数据库中获取所有数据。接下来,当我尝试运行客户端代码来查询不同应用程序中的缓存时。我收到错误消息“无法找到类型为 Person 的 SQL 表”

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;
}

}

PersonCacheStore:

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 配置。

有两个选项可以修复:

  1. 确保您完全创建 IgniteConfiguration (包括 CacheConfiguration )在调用 Ignition.start() 之前有了这个配置。然后使用ignite.cache("person:cache")获取缓存;如果你这样做而不是使用 getOrCreateCache ,你会得到null而不是错误配置缓存以防万一搞砸了某些东西,这样会更容易定位问题。
  2. 不提供CacheConfiguration作为 IgniteConfiguration 的一部分,并使用 getOrCreateCache 创建缓存提供配置对象而不仅仅是名称。

关于java - Apache Ignite 找不到 SQL 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47186981/

相关文章:

java - 在 spring 数据中使用什么代替 fetch.EAGER ?

java - Spring 配置属性递归类型

caching - Ignite Write 内部结构

基于 Java 枚举的状态机 (FSM) : Passing in events

spring - 如何使用 Vaadin + Spring 创建 MVP 架构?

java - 如何清理 Rx Subscription 和 Observable 以防止内存泄漏?

java - 使用 SSLContext.getDefault() 在 Spring 使用 SSL 设置 Ignite 集群

ignite - 基于apache ignite SQL查询中的列表字段的排序记录

Javafx 自定义 slider 值

java - ant 目标将 war 部署到 tomcat7/webapps