在点燃时加入2个缓存时无法找到数据库

时间:2016-11-08 07:54:18

标签: ignite

我正在利用多个点火缓存之间的分布式连接。我在两个缓存中加载了所需的数据,并且在执行连接时,它在解析建议“未找到数据库”的SQL时失败(请参阅堆栈跟踪)。

Caused by: org.h2.jdbc.JdbcSQLException: Database "OFFER" not found; SQL statement:
SELECT "customOrganizationCache".Organization._key, "customOrganizationCache".Organization._val from Organization as organization, "customOfferCache".Offer as offer where organization._id = offer.relationships.customer.targets.key and organization._id = ? [90013-191]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:179)

以下是我的点燃配置文件:

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

以下是我在执行加入时使用的代码:

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

        }

    }

请帮我找到根本原因。

1 个答案:

答案 0 :(得分:0)

问题在于这个表达式:

offer.relationships.customer.targets.key

关于这一点的几点考虑:

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