首页 > 解决方案 > Apache Ignite .Net 2.8.1:与 QueryEntity 的亲和搭配

问题描述

我在 Windows 10 机器上使用 Apache Ignite v.2.8.1 .Net。

我正在尝试在启用查询的缓存上使用亲和力搭配。我存储在缓存中的实体有一个名为“Id”的主键和一个名为“PartnerId”的关联键。两个键都是 Int32 类型。我将缓存定义如下:

new CacheConfiguration("BespokeCharge")
        {
            KeyConfiguration = new[]
            {
                    new CacheKeyConfiguration()
                    {
                        AffinityKeyFieldName = "PartnerId",
                        TypeName = typeof(BespokeCharge).Name
                    }
            }
        };

接下来我使用以下代码添加数据:

var cache = Ignite.GetCache<AffinityKey, BespokeCharge>("BespokeCharge")
cache.Put(new AffinityKey(entity.Id, entity.PartnerId), entity)

到目前为止,一切都很好。因为我希望能够使用 SQL 来搜索定制费用,所以我还添加了一个 QueryEntity 配置:

new CacheConfiguration("BespokeCharge",
            new QueryEntity(typeof(AffinityKey), typeof(BespokeCharge))
            {
                KeyFieldName = "Id",
                TableName = "BespokeCharge"
            })
        {
            KeyConfiguration = new[]
            {
                    new CacheKeyConfiguration()
                    {
                        AffinityKeyFieldName = "PartnerId",
                        TypeName = typeof(BespokeCharge).Name
                    }
            }
        };

当我运行代码时,Ignite 和我的应用程序都崩溃了,并且记录了以下错误:

由于失败,JVM 将立即停止:[failureCtx=FailureContext [type=CRITICAL_ERROR, err=class oaiiprocessors.cache.persistence.tree.CorruptedTreeException: B+Tree is corrupted [pages(groupId, pageId)=[IgniteBiTuple [val1= 1565129718, val2=844420635164729]], cacheId=-1278247946, cacheName=BESPOKECHARGES, indexName=BESPOKECHARGES_ID_ASC_IDX, msg=行上运行时失败: Row@29db2fbe[键: AffinityKey [idHash=8137191, hash=7839key=94447 2], val: UtilityClick.BillValidation.Shared.InMemory.Model.BespokeCharge [idHash=889383506, hash=-399638125, BespokeChargeTypeId=4, ChargeValue=100.0000, ChargeValueIncCommission=100.0000, Id=3, PartnerId=2, QuoteRecordId=5] ][ 4, 100.0000, 100.0000, , 2, 5 ]]]]

当我尝试使用 int 而不是 AffinityKey 的键类型定义 QueryEntity 时,我得到了一个具有相同结果的不同错误——崩溃。

由于失败,JVM 将立即停止:[failureCtx=FailureContext [type=CRITICAL_ERROR, err=java.lang.ClassCastException: class oaicache.affinity.AffinityKey cannot be cast to class java.lang.Integer (oaicache.affinity.AffinityKey is在加载程序“app”的未命名模块中;java.lang.Integer 在加载程序“bootstrap”的模块 java.base 中)]]

我究竟做错了什么?谢谢您的帮助!

标签: ignite

解决方案


KeyFieldName = "Id"设置是问题。它将Id字段设置为用作缓存键,即int,但随后我们将AffinityKey其用作缓存键,这会导致类型不匹配。

在这种情况下,我认为我们根本不需要KeyFieldName,删除它可以解决问题,并且SELECT查询不应受到此更改的影响。


推荐阅读