在ignite中加入2缓存时找不到数据库

在ignite中加入2缓存时找不到数据库,ignite,Ignite,我正致力于利用多个ignite缓存之间的分布式连接。我在两个缓存中都加载了所需的数据,在执行连接时,它在解析SQL时失败,提示“未找到数据库”(请查看堆栈跟踪) 下面是我的ignite配置文件: <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http:

我正致力于利用多个ignite缓存之间的分布式连接。我在两个缓存中都加载了所需的数据,在执行连接时,它在解析SQL时失败,提示“未找到数据库”(请查看堆栈跟踪)

下面是我的ignite配置文件:

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="offerCacheStoreFactory" class="javax.cache.configuration.FactoryBuilder" factory-method="factoryOf">
<constructor-arg><value>com.xyz.exploreignite.cache.CustomOfferCacheStore</value></constructor-arg>
</bean>

<bean id="organizationCacheStoreFactory" class="javax.cache.configuration.FactoryBuilder" factory-method="factoryOf">
<constructor-arg><value>com.xyz.exploreignite.cache.CustomOrganizationCacheStore</value></constructor-arg>
</bean>

<bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
    <property name="peerClassLoadingEnabled" value="false"/>
<property name="clientMode" value="false"/>
<property name="gridName" value="clusterGrid"/>
    <property name="cacheConfiguration">
        <list>               
    <bean class="org.apache.ignite.configuration.CacheConfiguration">
                <property name="atomicityMode" value="ATOMIC"/>
                <property name="backups" value="1"/>
                <property name="name" value="customOrganizationCache"/>
                <property name="readThrough" value="true"/>
                <property name="writeThrough" value="true"/>
                <property name="cacheMode" value="PARTITIONED"/>
                <property name="writeBehindEnabled" value="true"/>
                <property name="copyOnRead" value="false"/>
                <property name="memoryMode" value="OFFHEAP_TIERED"/>
                <property name="atomicWriteOrderMode" value="PRIMARY"/>
                <property name="indexedTypes" >
        <list>
            <value>java.lang.String</value>
            <value>com.xyz.exploreignite.pojo.Organization</value>
        </list>
        </property>
        <!-- Cache store. -->
        <property name="cacheStoreFactory" ref="organizationCacheStoreFactory"/>
        <property name="swapEnabled" value="false"/>
        <property name="offHeapMaxMemory" value="0"/>
        <property name="evictionPolicy">
        <!-- LRU eviction policy. -->
        <bean class="org.apache.ignite.cache.eviction.lru.LruEvictionPolicy">
            <!-- Set the maximum cache size to 1 million (default is 100,000). -->
            <property name="maxSize" value="1000000"/>
        </bean>
        </property>
            </bean>
    <bean class="org.apache.ignite.configuration.CacheConfiguration">
                <property name="atomicityMode" value="ATOMIC"/>
                <property name="backups" value="1"/>
                <property name="name" value="customOfferCache"/>
                <property name="readThrough" value="true"/>
                <property name="writeThrough" value="true"/>
                <property name="cacheMode" value="PARTITIONED"/>
                <property name="writeBehindEnabled" value="true"/>
                <property name="copyOnRead" value="false"/>
                <property name="memoryMode" value="OFFHEAP_TIERED"/>
                <property name="atomicWriteOrderMode" value="PRIMARY"/>
                <property name="indexedTypes" >
        <list>
            <value>java.lang.String</value>
            <value>com.xyz.exploreignite.pojo.Offer</value>
        </list>
        </property>
        <!-- Cache store. -->
        <property name="cacheStoreFactory" ref="offerCacheStoreFactory"/>
        <property name="swapEnabled" value="false"/>
        <property name="offHeapMaxMemory" value="0"/>
        <property name="evictionPolicy">
        <!-- LRU eviction policy. -->
        <bean class="org.apache.ignite.cache.eviction.lru.LruEvictionPolicy">
            <!-- Set the maximum cache size to 1 million (default is 100,000). -->
            <property name="maxSize" value="1000000"/>
        </bean>
        </property>
            </bean>
        </list>
    </property>


    <!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->
    <property name="discoverySpi">
        <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
            <property name="ipFinder">
                <!--
                    Ignite provides several options for automatic discovery that can be used
                    instead os static IP based discovery. For information on all options refer
                    to our documentation: http://apacheignite.readme.io/docs/cluster-config
                -->
                <!-- Uncomment static IP finder to enable static-based discovery of initial nodes. -->
                <!--<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">-->
                <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder">
                    <property name="addresses">
                        <list>
                            <value>127.0.0.1:47500..47509</value>
                        </list>
                    </property>
                </bean>
            </property>
        </bean>
    </property>
</bean>

com.xyz.exploreignite.cache.CustomOfferCacheStore
com.xyz.exploreignite.cache.CustomOrganizationCacheStore
java.lang.String
com.xyz.exploreignite.pojo.Organization
java.lang.String
com.xyz.exploreignite.pojo.Offer
127.0.0.1:47500..47509

下面是我在执行联接时使用的代码:

try (Ignite ignite = Ignition.start(
            // "/home/impadmin/ignite/apache-ignite-fabric-1.7.0-bin/examples/config/example-cache-ss-cluster.xml"))
            // {
            "/home/xyz/msheth/install/apache-ignite-fabric-1.7.0-bin/examples/config/example-cache-ss-cluster.xml")) {

        try (IgniteCache<String, Offer> customOfferCache = ignite.getOrCreateCache("customOfferCache");

                IgniteCache<String, Organization> customOrganizationCache = ignite
                        .getOrCreateCache("customOrganizationCache")) {


            SqlFieldsQuery joinQuery = new SqlFieldsQuery("select organization.displayName "
                    + "from Organization as organization, \"customOfferCache\".Offer as offer"
                    + " where organization._id = offer.relationships.customer.targets.key "
                    + "and organization._id = ?");

            joinQuery.setDistributedJoins(true);

            long startTime = System.currentTimeMillis();
            try (QueryCursor<List<?>> joinCursor = customOrganizationCache
                    .query(joinQuery.setArgs("542de0b83b2d445f0a0e0f53"))) {
                for (List<?> organizationEntry : joinCursor)
                    System.out.println("Organizations display name: " + organizationEntry);
            }

            System.out.println("Time to fetch join based record:" + (System.currentTimeMillis() - startTime));

        }

    }
try(点火=点火启动(
//“/home/impadmin/ignite/apache-ignite-fabric-1.7.0-bin/examples/config/example cache ss cluster.xml”))
// {
“/home/xyz/msheth/install/apache-ignite-fabric-1.7.0-bin/examples/config/example cache ss cluster.xml”)){
try(IgniteCache customOfferCache=ignite.getOrCreateCache(“customOfferCache”);
IgniteCache customOrganizationCache=ignite
.getOrCreateCache(“customOrganizationCache”)){
SqlFieldsQuery joinQuery=新建SqlFieldsQuery(“选择organization.displayName”
+“来自作为组织的组织,\“customOfferCache\”。作为要约提供”
+“其中组织._id=offer.relationships.customer.targets.key”
+“和组织._id=?”;
setDistributedJoins(true);
long startTime=System.currentTimeMillis();
try(QueryCursor organizationEntry:joinCursor)
System.out.println(“组织显示名称:“+organizationEntry”);
}
System.out.println(“获取基于联接的记录的时间:”+(System.currentTimeMillis()-startTime));
}
}

请帮助我找到根本原因。

问题出现在以下表达式中:

offer.relationships.customer.targets.key
围绕这一点的几点考虑:

  • 允许嵌套对象,但Ignite将创建平面模式。例如,
    customer
    字段可以作为
    Offer
    表的成员访问,您不应该为此提供完整路径。通常,在使用SQL时应该尽量避免嵌套对象,而是创建简单的POJO类
  • 但是,不允许在集合内查询。在您的情况下,
    目标的整个集合
    保存为单个对象,您不能根据其内容进行选择。您应该为
    Target
    对象提供单独的缓存,并将其与其他表连接起来

问题在于这句话:

offer.relationships.customer.targets.key
围绕这一点的几点考虑:

  • 允许嵌套对象,但Ignite将创建平面模式。例如,
    customer
    字段可以作为
    Offer
    表的成员访问,您不应该为此提供完整路径。通常,在使用SQL时应该尽量避免嵌套对象,而是创建简单的POJO类
  • 但是,不允许在集合内查询。在您的情况下,
    目标的整个集合
    保存为单个对象,您不能根据其内容进行选择。您应该为
    Target
    对象提供单独的缓存,并将其与其他表连接起来

这看起来很奇怪。您能否将整个测试作为一个小型GitHub项目提供。如果我运行它,就会更容易理解发生了什么。@Valentin,谢谢你调查此事。我已将代码推送到公共github@。请注意,有多个测试类,主要是用于加载和设置缓存的TestCustomOfferCacheLoad.java和TestCustomOrgCacheLoad.java,以及用于缓存连接的TestCustomOfferGCacheJoin.java。这看起来非常奇怪。您能否将整个测试作为一个小型GitHub项目提供。如果我运行它,就会更容易理解发生了什么。@Valentin,谢谢你调查此事。我已将代码推送到公共github@。请注意,有多个测试类,主要是TestCustomOfferCacheLoad.java和TestCustomOrgCacheLoad.java,用于加载和设置缓存&TestCustomOfferGCacheJoin.java用于缓存连接。感谢您的注释,我们将对其进行处理以保留不同缓存中的对象,但在第一个项目符号上还有一个查询。如果我们将所有嵌套字段都作为直接缓存pojo成员(在我的例子中是映射到pojo的JSON对象),Ignite如何区分不同的节字段。为了简化,我们在放置缓存时有一个字段“offer/customer”和另一个字段“offer/relationships/customer”,两者都将被offer对象中的同名customer字段占用。ignite如何区分这些。在这种情况下ignite将抛出异常。但是,
@QuerySqlField
注释具有o