AffinityKeyMapped无法与Ignite 2.4 / 2.5 / 2.6和Scala一起使用

时间:2018-07-20 22:43:03

标签: scala ignite

使用Scala 2.11.7 / Java 1.8.0_161 / RHEL7。

我们有两个缓存,它们的元素共享相同的相似性密钥。亲和密钥的定义如下:

case class IgniteTradePayloadKey(
    @(AffinityKeyMapped@field)
    tradeKey: TradeKey,
    ... other fields
) extends Serializable

case class IgniteDealPayloadKey(
   @(AffinityKeyMapped@field)
   tradeKey: TradeKey,
   child: Int,
   ... other fields
) extends Serializable

这些用作两个点火缓存(交易和交易)的键。我们希望同时使用交易和交易实例,因为我们同时使用两者进行计算。可以将它们视为具有父/子关系,并且我们希望将父项及其子项保留在同一节点中,因为我们的计算需要同时进行。父项由TradeKey唯一标识,因此我们在两个缓存中都使用它来控制亲和力。请注意,它们还用作Ignite键本身的一部分。它们不是价值的一部分。

这与Ignite 1.7完美结合;然后,我们尝试升级到较新版本的Ignite(我们尝试使用2.4、2.5和2.6),并且在没有任何代码更改的情况下,有些孩子不再与父母同住。确保恢复到1.7,并且可以进行搭配。我们试图用一些简单的方法(只是在TradeKey上的一个哈希值)覆盖了相似性函数,并且它再次适用于1.7,但不适用于上面列出的任何2.X版本。

我们缺少什么?

根据要求进行配置(对大量文件表示歉意)。我们尝试使用和不定义自己的相似性函数,结果相同。

    <beans xmlns="http://www.springframework.org/schema/beans"
        <bean id="propertyConfigurer"
              class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_FALLBACK"/>
            <property name="searchSystemEnvironment" value="true"/>
        </bean>

        <bean id="CLIENT_MODE" class="java.lang.String">
            <constructor-arg value="${IGNITE_CLIENT_MODE:false}" />
        </bean>

        <!-- Ignite common configuration -->
        <bean abstract="true" id="common.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
            <property name="gridName" value="MTS Trades Cache Grid" />
            <property name="failureDetectionTimeout" value="60000"/>
            <property name="clientFailureDetectionTimeout" value="60000"/>
            <property name="peerClassLoadingEnabled" value="true"/>
            <property name="clientMode" ref="CLIENT_MODE"/>
            <property name="rebalanceThreadPoolSize" value="4"/>
            <property name="deploymentMode" value="CONTINUOUS"/>

            <property name="discoverySpi">
                <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
                    <property name="localPort" value="47700"/>
                    <property name="localPortRange" value="20"/>

                    <!-- Setting up IP finder for this cluster -->
                    <property name="ipFinder">
                        <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
                            <property name="addresses">
                                <list>
                                    <value>127.0.0.1:47700..47720</value>
                                </list>
                            </property>
                        </bean>
                    </property>
                </bean>
            </property>

            <property name="communicationSpi">
                <bean class="org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi">
                    <property name="localPort" value="49100"/>
                    <property name="sharedMemoryPort" value="-1" />
                    <property name="messageQueueLimit" value="1024"/>

                </bean>
            </property>

            <!-- Cache configuration -->
            <property name="cacheConfiguration">
                <list>
                    <!-- deals -->
                    <bean class="org.apache.ignite.configuration.CacheConfiguration">
                        <property name="name" value="dealPayloads" />
                        <property name="cacheMode" value="PARTITIONED" />
                        <property name="backups" value="0" />
                        <property name="OnheapCacheEnabled" value="true"/>

                        <property name="queryEntities">
                            <list>
                                <bean class="org.apache.ignite.cache.QueryEntity">
                                    <!-- setting indexed type's key class -->
                                    <property name="keyType" value="com.company.ignite.IgniteDealPayloadKey" />
                                    <!-- setting indexed type's value class -->
                                    <property name="valueType" value="com.company.ignite.IgniteDealPayload" />
                                </bean>
                            </list>
                        </property>

                        <property name="affinity">
                            <bean class="com.company.ignite.affinity.IgniteAffinityFunction">
                                <property name="partitions" value="1024"/>
                            </bean>
                        </property>

                        <property name="atomicityMode" value="ATOMIC" />
                        <property name="rebalanceMode" value="ASYNC" />
                        <property name="copyOnRead" value="false" />

                        <!-- Set rebalance batch size to 8 MB. -->
                        <property name="rebalanceBatchSize" value="#{8 * 1024 * 1024}"/>

                        <!-- Explicitly disable rebalance throttling. -->
                        <property name="rebalanceThrottle" value="0"/>

                        <!-- Set 4 threads for rebalancing. -->
                        <property name="rebalanceThreadPoolSize" value="4"/>

                    </bean>
                    <!-- trade versions -->
                    <bean class="org.apache.ignite.configuration.CacheConfiguration">
                        <property name="name" value="tradePayloads" />
                        <property name="cacheMode" value="PARTITIONED" />
                        <property name="backups" value="0" />
                        <property name="OnheapCacheEnabled" value="true"/>

                        <property name="queryEntities">
                            <list>
                                <bean class="org.apache.ignite.cache.QueryEntity">
                                    <!-- setting indexed type's key class -->
                                    <property name="keyType" value="com.company.ignite.IgniteTradePayloadKey" />
                                    <!-- setting indexed type's value class -->
                                    <property name="valueType" value="com.company.ignite.IgniteTradePayload" />
                                </bean>
                            </list>
                        </property>

                        <property name="affinity">
                            <bean class="com.company.ignite.affinity.IgniteAffinityFunction">
                                <property name="partitions" value="1024"/>
                            </bean>
                        </property>

                        <property name="atomicityMode" value="ATOMIC" />
                        <property name="rebalanceMode" value="ASYNC" />
                        <property name="copyOnRead" value="false" />

                        <!-- Set rebalance batch size to 8 MB. -->
                        <property name="rebalanceBatchSize" value="#{8 * 1024 * 1024}"/>

                        <!-- Explicitly disable rebalance throttling. -->
                        <property name="rebalanceThrottle" value="0"/>

                        <!-- Set 4 threads for rebalancing. -->
                        <property name="rebalanceThreadPoolSize" value="4"/>

                    </bean>
                </list>
            </property>
        </bean>
    </beans>

此外,这是相关的例外情况:

    [22:28:24,418][INFO][grid-timeout-worker-#23%MTS Trades Cache Grid%][IgniteKernal%MTS Trades Cache Grid] FreeList [name=MTS Trades Cache Grid, buckets=256, dataPages=9658, reusePages=0]
    [22:28:57,335][INFO][pub-#314%MTS Trades Cache Grid%][GridDeploymentLocalStore] Class locally deployed: class com.company.pt.tradesrouter.routing.ComputeJob
    [22:28:57,705][SEVERE][pub-#314%MTS Trades Cache Grid%][GridJobWorker] Failed to execute job [jobId=48df049c461-b3ba568d-6a39-4296-b03f-0c046e7cf3f7, ses=GridJobSessionImpl [ses=GridTaskSessionImpl [taskName=com.company.pt.tradesrouter.routing.ComputeJob, dep=GridDeployment [ts=1532382444003, depMode=CONTINUOUS, clsLdr=sun.misc.Launcher$AppClassLoader@764c12b6, clsLdrId=a717c19c461-e5241c47-40d4-4085-a7fa-4f1916275b2e, userVer=0, loc=true, sampleClsName=o.a.i.i.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap, pendingUndeploy=false, undeployed=false, usage=2], taskClsName=com.company.pt.tradesrouter.routing.ComputeJob, sesId=38df049c461-b3ba568d-6a39-4296-b03f-0c046e7cf3f7, startTime=1532384937062, endTime=1532388537300, taskNodeId=b3ba568d-6a39-4296-b03f-0c046e7cf3f7, clsLdr=sun.misc.Launcher$AppClassLoader@764c12b6, closed=false, cpSpi=null, failSpi=null, loadSpi=null, usage=1, fullSup=false, internal=false, topPred=null, subjId=b3ba568d-6a39-4296-b03f-0c046e7cf3f7, mapFut=IgniteFuture [orig=GridFutureAdapter [ignoreInterrupts=false, state=INIT, res=null, hash=1635946755]], execName=null], jobId=48df049c461-b3ba568d-6a39-4296-b03f-0c046e7cf3f7]]
    class org.apache.ignite.IgniteException: null
            at org.apache.ignite.internal.processors.closure.GridClosureProcessor$C2.execute(GridClosureProcessor.java:1858)
            at org.apache.ignite.internal.processors.job.GridJobWorker$2.call(GridJobWorker.java:566)
            at org.apache.ignite.internal.util.IgniteUtils.wrapThreadLoader(IgniteUtils.java:6623)
            at org.apache.ignite.internal.processors.job.GridJobWorker.execute0(GridJobWorker.java:560)
            at org.apache.ignite.internal.processors.job.GridJobWorker.body(GridJobWorker.java:489)
            at org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:110)
            at org.apache.ignite.internal.processors.job.GridJobProcessor.processJobExecuteRequest(GridJobProcessor.java:1189)
            at org.apache.ignite.internal.processors.job.GridJobProcessor$JobExecutionListener.onMessage(GridJobProcessor.java:1921)
            at org.apache.ignite.internal.managers.communication.GridIoManager.invokeListener(GridIoManager.java:1555)
            at org.apache.ignite.internal.managers.communication.GridIoManager.processRegularMessage0(GridIoManager.java:1183)
            at org.apache.ignite.internal.managers.communication.GridIoManager.access$4200(GridIoManager.java:126)
            at org.apache.ignite.internal.managers.communication.GridIoManager$9.run(GridIoManager.java:1090)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
            at java.lang.Thread.run(Thread.java:748)
    Caused by: java.lang.NullPointerException
            at com.company.pt.tradesrouter.routing.ComputeJob$$anonfun$1$$anonfun$2.apply(ComputeJob.scala:49)
            at com.company.pt.tradesrouter.routing.ComputeJob$$anonfun$1$$anonfun$2.apply(ComputeJob.scala:47)
            at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
            at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
            at scala.collection.immutable.Set$Set1.foreach(Set.scala:79)
            at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
            at scala.collection.AbstractSet.scala$collection$SetLike$$super$map(Set.scala:47)
            at scala.collection.SetLike$class.map(SetLike.scala:92)
            at scala.collection.AbstractSet.map(Set.scala:47)
            at com.company.pt.tradesrouter.routing.ComputeJob$$anonfun$1.apply(ComputeJob.scala:47)
            at com.company.pt.tradesrouter.routing.ComputeJob$$anonfun$1.apply(ComputeJob.scala:44)
            at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
            at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
            at scala.collection.immutable.HashMap$HashMap1.foreach(HashMap.scala:221)
            at scala.collection.immutable.HashMap$HashTrieMap.foreach(HashMap.scala:428)
            at scala.collection.immutable.HashMap$HashTrieMap.foreach(HashMap.scala:428)
            at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
            at scala.collection.AbstractTraversable.map(Traversable.scala:104)
            at com.company.pt.tradesrouter.routing.ComputeJob.call(ComputeJob.scala:44)
            at com.company.pt.tradesrouter.routing.ComputeJob.call(ComputeJob.scala:21)
            at org.apache.ignite.internal.processors.closure.GridClosureProcessor$C2.execute(GridClosureProcessor.java:1855)
            ... 14 more

1 个答案:

答案 0 :(得分:2)

很可能您遇到了Ignite 2.0中引入的错误:https://issues.apache.org/jira/browse/IGNITE-5795

由于此错误@AffinityKeyMapped注释在查询实体配置中使用的类中被忽略。据我所知,这正是您的情况。

它将在Ignite 2.7中修复。

有一个解决此问题的方法:您可以在BinaryConfiguration#classNames配置属性中列出有问题的类。二进制配置应指定为IgniteConfiguration#binaryConfiguration。在所有节点上,此配置应相同。您可能还需要为缓存配置CacheConfiguration#keyConfiguration