2016-11-08 96 views
1

我正在利用多個點火緩存之間的分佈式連接。我在兩個緩存中加載了所需的數據,並在執行連接時失敗,同時解析SQL提示「數據庫未找到」(請參閱​​堆棧跟蹤)。無法找到數據庫,同時加入2緩存點燃

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

     } 

    } 

請幫我找到根本原因。

+0

這看起來很奇怪。你能否提供整個測試作爲一個小型的GitHub項目?如果我運行它,將會更容易理解正在發生的事情。 –

+0

@Valentin,感謝您關注此事。我已將代碼推送到公共github @ https://github.com/mananstar2001/testignite。請注意,有多個測試類,主要是TestCustomOfferCacheLoad.java和TestCustomOrgCacheLoad.java,用於加載和設置緩存連接的緩存和TestCustomOfferOrgCacheJoin.java。 –

回答

0

的問題是在這個表達式:

offer.relationships.customer.targets.key 

解決此夫婦事項:

  • 你被允許有嵌套的對象,然而點燃將創建扁平架構。例如,customer字段可以作爲Offer表的成員訪問,因此您不應爲此提供此完整路徑。通常,您應該嘗試在使用SQL時避免嵌套對象,並改爲創建簡單的POJO類。
  • 但是,您不允許在集合中進行查詢。在您的情況下,targets的整個集合將保存爲單個對象,並且您無法根據其內容進行選擇。您應該爲Target對象分開緩存並將其與其他表加入。
+0

感謝您的評論,並將其用於保存不同緩存中的對象,但另外在第一個項目符號上有1個查詢。如果我們將所有嵌套字段都作爲直接緩存pojo成員(在我的例子中是將其映射到POJO的JSON對象),Ignite將如何區分不同的部分字段。爲了簡化,我們有一個字段「offer/customer」和另一個字段字段「offer/relationships/customer」,同時放下緩存,這兩個字段都會被提供對象中的同名客戶字段佔用。點燃如何區分這些。 –

+0

在這種情況下,Ignite將引發異常。然而,'@ QuerySqlField'註解具有可選的'name'參數,可以覆蓋名稱並避免這種衝突。 –